Likes: 0
Results 1 to 1 of 1
-
17-03-10, 10:17 PM #1
- Rep Power
- 0
- Reputation
- 87
(Share)[Lua]How to Script a Custom command
Register to remove this adLets say i want a SpawnNPC Command, where it should spawn my teleporter..
First start with a local function for the chat message, Like this:
Code:local Teleporter_Spawn = "#TeleportSpawn" The Teleporter_Spawn is a local which is reffering to something further down in your script. Everything inside " " Are the command, which will say ingame they must now type #TeleportSpawn to spawn the teleporter!
Code:function OnChat_TeleportSpawn(event, player, message, type, language) the OnChat_TeleportSpawn is the function which will make it all work.
Then will tell the Lua what will happen if that message comes.
Code:if (message == Teleporter_Spawn) then of course we want our teleporter infront of us, so we need to get some coordinations.
Code:local x = player:GetX()local y = player:GetY()local z = player:GetZ()local o = player:GetO() Now that will give us the correct cords of your possision. We want the teleporter to be spawned 2 yards infront of you.
Code:player:SpawnCreature(76668, x, y+2, z, o, 35, 30000) player:SendAreaTriggerMessage("The Npc will be spawned for 30 sec.!") 76668 is my teleporter ID, then x is GetX(), y is GetY(), z is GetZ() and 0 is GetO()
so it would be like this:
Code::SpawnCreature(NPCID, x, y, z, o, Faction, SpawnTime(In milliseconds) The SendAreaTriggerMessage send a message with yellow colour in the screen of the player
Code:return 0 right under SendAreaTriggerMessage.
end will be added 2 times in this script, since end is going to be there for every time u have written function or if
Lets say you have 2 function lines, and 3 if lines. then we are going to do it like this:
Code:endendendendend 5 Times, since its 5 total
so here we are going to need 2 end Right after the return 0
Code:player:SendAreaTriggerMessage("The Npc will be spawned for 30 sec.!") return 0 endend at the end we need to register the function which will be done on commands by doing:
Code:RegisterServerHook(16, "OnChat_TeleportSpawn") To the end my Command Script looks like this:
Code:local Teleporter_Spawn = "#TeleportSpawn"function OnChat_TeleportSpawn(event, player, message, type, language) if (message == Teleporter_Spawn) thenlocal x = player:GetX()local y = player:GetY()local z = player:GetZ()local o = player:GetO() player:SpawnCreature(76668, x+2, y, z, o, 35, 30000) player:SendAreaTriggerMessage("The Npc will be spawned for 30 sec.!") return 0 endendRegisterServerHook(16, "OnChat_TeleportSpawn")
Credits go to Wx2 From Ac-Web thxs Man!
› See More: (Share)[Lua]How to Script a Custom commandLast edited by Noblebeastx; 17-03-10 at 10:21 PM.