Lua Sample Scripts

From ArcEmu-Wiki
Revision as of 19:18, 14 June 2013 by Zdroid9770 (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
+/-
Main Page        LuaArcEmu Website     ArcEmu Forum     Bug Tracker


Lua Samples

Just to get you started. Lua is surprisingly easy to learn.

Contents


Random Chat message on combat

function KoboldVermin_OnEnterCombat(pUnit, Event) 
	KoboldRND = math.random(1, 2)
	-- math.random(X, X) will return a random number between the two #'s you put in the ()'s
	if KoboldRND == 1 then
		pUnit:SendChatMessage(12, 0, "You no take candle!")
		-- 12 is Monster Say, and 0 is universal language
	end
	if KoboldRND == 2 then
		pUnit:SendChatMessage(12, 0, "Yiieeeeeee! Me run!")
	end 
end
 
RegisterUnitEvent(6, 1, "KoboldVermin_OnEnterCombat") -- On Enter Combat event for unit with ID 6 (Kobold Vermin)


Access the nearest game object and activate with object id defined, gets nearest by XYZ coordinates

local GAMEOBJECTID = Id here
 
function 423_OnUse(pGO, event, player)
 pGO:Activate()
 player:GetGameObjectNearestCoords(X,Y,Z):Activate()
end
RegisterGameObjectEvent(GAMEOBJECTID, 4, "423_OnUse")


Teleport on NPC click with NPCID as a define

local NPCID = Id here
 
function TP_NPC_main_menu(pUnit, player)
	player:Teleport(MAPID, X, Y ,Z)
	end
 
RegisterUnitGossipEvent(NPCID,1,"teleportal_NPC_on_gossip_talk")



Change weather on NPC click with NPCID as a define

local NPCID = Id here
 
function TP_NPC_main_menu(pUnit, player)
	player:SetPlayerWeather(2, 2.0)
	end
 
RegisterUnitGossipEvent(NPCID,1,"weather_NPC_on_gossip_talk")
Personal tools