Difference between revisions of "LUA:SpawnScripts"

 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
{{PageHeaderChild|LUA|Spawn Scripts}}
 
Spawn Scripts are used to bring a spawn to life, the most common use is to add dialog but it is possible to write your own custom AI completely overriding the default behavior provided in the server core.
 
Spawn Scripts are used to bring a spawn to life, the most common use is to add dialog but it is possible to write your own custom AI completely overriding the default behavior provided in the server core.
  
== Aggro ==
+
 
 +
{{Header|Functions|BackgroundColor=3d78b4|FontColor=ffffff}}
 +
{|style="table-layout:fixed; width: 100%;"
 +
|{{TextBox
 +
|Aggro
 +
|Aggro is called when the spawn aggros a player due to faction
 +
 
 +
function aggro(Spawn, Spawn)
 +
end
 +
|BackgroundColor=ffffff
 +
|FontColor=000000}}
 +
|}
 +
 
 +
{|style="table-layout:fixed; width: 100%;"
 +
|{{TextBox
 +
|Attacked
 +
|Attacked is called when the spawn enters combat
 +
 
 +
function attacked(Spawn, Spawn)
 +
end
 +
|BackgroundColor=ffffff
 +
|FontColor=000000}}
 +
|}
 +
 
 +
 
 +
 
 +
 
 +
{|style="table-layout:fixed; width: 100%;"
 +
|{{TextBox
 +
|Aggro
 +
|Aggro is called when the spawn aggros a player due to faction
 +
 
 +
function aggro(Spawn, Spawn)
 +
end
 +
|BackgroundColor=ffffff
 +
|FontColor=000}}
 +
|{{TextBox
 +
|Attacked
 +
|Attacked is called when the spawn enters combat
 +
 
 +
function attacked(Spawn, Spawn)
 +
end
 +
|BackgroundColor=ffffff
 +
|FontColor=000}}
 +
|}
 +
 
 +
 
 +
 
 +
{{Header|Aggro|BackgroundColor=3d78b4|FontColor=ffffff}}
 
Aggro is called when the spawn aggros a player due to faction
 
Aggro is called when the spawn aggros a player due to faction
  
Line 8: Line 57:
 
end
 
end
 
</pre>
 
</pre>
== Attacked ==
+
{{Header|Attacked|BackgroundColor=3d78b4|FontColor=ffffff}}
 
Attacked is called when the spawn enters combat
 
Attacked is called when the spawn enters combat
  
Line 15: Line 64:
 
end
 
end
 
</pre>
 
</pre>
== Auto Attack Tick ==
+
{{Header|Auto Attack Tick|BackgroundColor=3d78b4|FontColor=ffffff}}
 
Auto Attack Tick is called when the spawn makes an attack with the primary weapon
 
Auto Attack Tick is called when the spawn makes an attack with the primary weapon
  
Line 22: Line 71:
 
end
 
end
 
</pre>
 
</pre>
== Can Use Command ==
+
{{Header|Can Use Command|BackgroundColor=3d78b4|FontColor=ffffff}}
 
can_use_command is called when an entity command is used on a spawn. Return true to allow the command to be used, false to not. This check only applies if this function is in the script. The third parameter is the name of the spell/entity command.
 
can_use_command is called when an entity command is used on a spawn. Return true to allow the command to be used, false to not. This check only applies if this function is in the script. The third parameter is the name of the spell/entity command.
  
Line 29: Line 78:
 
     return true
 
     return true
 
end</pre>
 
end</pre>
== Casted On ==
+
{{Header|Casted On|BackgroundColor=3d78b4|FontColor=ffffff}}
 
Casted On is called when a spell is casted on the spawn, the third parameter is the name of the spell/entity command
 
Casted On is called when a spell is casted on the spawn, the third parameter is the name of the spell/entity command
  
Line 36: Line 85:
 
end
 
end
 
</pre>
 
</pre>
== Combat Reset ==
+
{{Header|Combat Reset|BackgroundColor=3d78b4|FontColor=ffffff}}
 
Combat Reset is called when the spawn leaves combat
 
Combat Reset is called when the spawn leaves combat
  
Line 43: Line 92:
 
end
 
end
 
</pre>
 
</pre>
== Death ==
+
{{Header|Death|BackgroundColor=3d78b4|FontColor=ffffff}}
 
Death is called when the spawn dies
 
Death is called when the spawn dies
  
Line 50: Line 99:
 
end
 
end
 
</pre>
 
</pre>
== Group Dead ==
+
{{Header|Group Dead|BackgroundColor=3d78b4|FontColor=ffffff}}
 
Group dead is called when the last member of a spawn group is killed
 
Group dead is called when the last member of a spawn group is killed
  
Line 57: Line 106:
 
end
 
end
 
</pre>
 
</pre>
== Hailed ==
+
{{Header|Hailed|BackgroundColor=3d78b4|FontColor=ffffff}}
 
Hailed is called when a player hails the spawn
 
Hailed is called when a player hails the spawn
  
Line 64: Line 113:
 
end
 
end
 
</pre>
 
</pre>
== Hailed Busy ==
+
{{Header|Hailed Busy|BackgroundColor=3d78b4|FontColor=ffffff}}
 
Hailed Busy is called when a player hails the spawn while it is in combat
 
Hailed Busy is called when a player hails the spawn while it is in combat
  
Line 71: Line 120:
 
end
 
end
 
</pre>
 
</pre>
== Health Changed ==
+
{{Header|Health Changed|BackgroundColor=3d78b4|FontColor=ffffff}}
 
Health Changed is called whenever the spawns health changes in either direction
 
Health Changed is called whenever the spawns health changes in either direction
  
Line 78: Line 127:
 
end
 
end
 
</pre>
 
</pre>
== Killed ==
+
{{Header|Hear Say|BackgroundColor=3d78b4|FontColor=ffffff}}
 +
Hear Say is called whenever a player uses /say with a spawn targeted
 +
 
 +
<pre>
 +
function hear_say(NPC, Spawn, Msg)
 +
end
 +
</pre>
 +
{{Header|Killed|BackgroundColor=3d78b4|FontColor=ffffff}}
 
Killed is called whenever the spawn kills something
 
Killed is called whenever the spawn kills something
  
Line 85: Line 141:
 
end
 
end
 
</pre>
 
</pre>
== Random Chat ==
+
{{Header|Random Chat|BackgroundColor=3d78b4|FontColor=ffffff}}
 
Random Chat is never called and its purpose is lost, code for it still remains so it is listed here just for reference
 
Random Chat is never called and its purpose is lost, code for it still remains so it is listed here just for reference
  
Line 92: Line 148:
 
end
 
end
 
</pre>
 
</pre>
== Respawn ==
+
{{Header|Respawn|BackgroundColor=3d78b4|FontColor=ffffff}}
 
Respawn is called when the spawn respawns
 
Respawn is called when the spawn respawns
  
Line 99: Line 155:
 
end
 
end
 
</pre>
 
</pre>
== Spawn ==
+
{{Header|Spawn|BackgroundColor=3d78b4|FontColor=ffffff}}
 
Spawn is called when the spawn spawns for the first time
 
Spawn is called when the spawn spawns for the first time
  
Line 106: Line 162:
 
end
 
end
 
</pre>
 
</pre>
== Targeted ==
+
{{Header|Targeted|BackgroundColor=3d78b4|FontColor=ffffff}}
 
Targeted is called whenever a player targets the spawn
 
Targeted is called whenever a player targets the spawn
  
Line 113: Line 169:
 
end
 
end
 
</pre>
 
</pre>
 
+
{{Header|Think|BackgroundColor=3d78b4|FontColor=ffffff}}
== Think ==
 
 
Think is used to override AI and is called every time the AI needs to run
 
Think is used to override AI and is called every time the AI needs to run
  
Line 122: Line 177:
 
</pre>
 
</pre>
  
 +
 +
{{Header|Tutorials|BackgroundColor=3d78b4|FontColor=ffffff}}
 +
Coming Soon.
  
 
{|style="table-layout:fixed; width: 100%;"
 
{|style="table-layout:fixed; width: 100%;"
 
|{{TextBox
 
|{{TextBox
|Spawnscript Name
+
|Spawn Script Template
| --[[
+
|In order to have a spawn script that can be submitted to the server you must follow a certain structure. Use this [[ContentDesigner:Spawn_Script_Template|Spawn Script Template]] for the spawn scripts. This will have a break down of the code with an explanation of what each part does, and it will also have the full template that you can copy and paste into your editor like notepad++.
Script Name : Quests/FrostfangSea/the_icemanes_cometh.lua
 
Script Purpose : the quest The Icemanes Cometh
 
Script Author : theFoof
 
Script Date : 2013.5.20
 
 
 
        Zone            : Frostfang Sea
 
        Quest Giver    : Verien Skysigh
 
        Preceded by    : Pilgrim Pelts
 
        Followed by    : None
 
--]]
 
 
 
function Accepted(Quest, QuestGiver, Player)
 
    if HasItem(Player, 46664) == false then
 
        SummonItem(Player, 46664, 1)
 
end
 
FaceTarget(QuestGiver, Player)
 
conversation = CreateConversation()
 
 
 
PlayFlavor(QuestGiver, "verien_skysigh/halas/gwenevyns_cove/verien_skysigh_030.mp3", "", "", 2735698585, 1703243228, Player)
 
AddConversationOption(conversation, "I understand.")
 
StartConversation(conversation, QuestGiver, Player, "Be sure to escort them back here.  Then tether them to the icemane post nearby.  That is our only hope in dealing with them.")
 
end
 
 
 
function Declined(Quest, QuestGiver, Player)
 
end
 
 
 
function Deleted(Quest, QuestGiver, Player)
 
    SetTempVariable(Player, "cub1", nil)
 
SetTempVariable(Player, "cub2", nil)
 
SetTempVariable(Player, "cub3", nil)
 
SetTempVariable(Player, "cub4", nil)
 
end
 
 
 
function Init(Quest)
 
-- 2329 ??
 
    AddQuestRewardCoin(Quest, math.random(1,80), math.random(6,12), 0, 0)
 
    AddQuestStep(Quest, 1, "Use the binding tether on icemane cubs upon the Icemane Plains, then bring them back to the lion post near Verien Skysigh at the pilgrims' camp within Gwenevyn's Cove.", 4, 100, "Verien believes the grizzlies will avoid attacking any pilgrim who is being escorted by icemane cubs. He has tasked you with leashing some and bringing them back to the camp using the binding tether he provided you.", 2329)
 
AddQuestStepCompleteAction(Quest, 1, "GotCubs")
 
end
 
 
 
function GotCubs(Quest, QuestGiver, Player)
 
    UpdateQuestTaskGroupDescription(Quest, 1, "You brought back enough tethered icemane cubs.")
 
    AddQuestStepChat(Quest, 2, "Return to Verien Skysigh now that you have presented him with enough tethered icemane cubs.", 1, "You should return to Verien Skysigh, at the pilgrims' camp within Gwenevyn's Cove, now that you have presented him with enough tethered icemane cubs.", 0, 4700034)
 
AddQuestStepCompleteAction(Quest, 2, "CompleteQuest")
 
end
 
 
 
function CompleteQuest(Quest, QuestGiver, Player)
 
    GiveQuestReward(Quest, Player)
 
end
 
 
 
function Reload(Quest, QuestGiver, Player, Step)
 
    if Step == 1 then
 
    GotCubs(Quest, QuestGiver, Player)
 
elseif Step == 2 then
 
    CompleteQuest(Quest, QuestGiver, Player)
 
end
 
end
 
 
|BackgroundColor=ffffff
 
|BackgroundColor=ffffff
 
|FontColor=000000}}
 
|FontColor=000000}}
 
|}
 
|}
 
 
[[LUA|Back to LUA]]
 

Latest revision as of 23:13, 2 September 2016

LUA - Spawn Scripts

Return to: LUA | Tutorials | Portal | Forum | Project Manager | Bug Tracker

Spawn Scripts are used to bring a spawn to life, the most common use is to add dialog but it is possible to write your own custom AI completely overriding the default behavior provided in the server core.


Functions

Aggro

Aggro is called when the spawn aggros a player due to faction

function aggro(Spawn, Spawn)
end

Attacked

Attacked is called when the spawn enters combat

function attacked(Spawn, Spawn)
end



Aggro

Aggro is called when the spawn aggros a player due to faction

function aggro(Spawn, Spawn)
end

Attacked

Attacked is called when the spawn enters combat

function attacked(Spawn, Spawn)
end


Aggro

Aggro is called when the spawn aggros a player due to faction

function aggro(Spawn, Spawn)
end
Attacked

Attacked is called when the spawn enters combat

function attacked(Spawn, Spawn)
end
Auto Attack Tick

Auto Attack Tick is called when the spawn makes an attack with the primary weapon

function auto_attack_tick(Spawn, Spawn)
end
Can Use Command

can_use_command is called when an entity command is used on a spawn. Return true to allow the command to be used, false to not. This check only applies if this function is in the script. The third parameter is the name of the spell/entity command.

function can_use_command(NPC, Spawn, String)
    return true
end
Casted On

Casted On is called when a spell is casted on the spawn, the third parameter is the name of the spell/entity command

function casted_on(Spawn, Spawn, String)
end
Combat Reset

Combat Reset is called when the spawn leaves combat

function CombatReset(Spawn)
end
Death

Death is called when the spawn dies

function death(Spawn, Spawn)
end
Group Dead

Group dead is called when the last member of a spawn group is killed

function group_dead(Spawn, Spawn)
end
Hailed

Hailed is called when a player hails the spawn

function hailed(Spawn, Spawn)
end
Hailed Busy

Hailed Busy is called when a player hails the spawn while it is in combat

function hailed_busy(Spawn, Spawn)
end
Health Changed

Health Changed is called whenever the spawns health changes in either direction

function healthchanged(Spawn, Spawn)
end
Hear Say

Hear Say is called whenever a player uses /say with a spawn targeted

function hear_say(NPC, Spawn, Msg)
end
Killed

Killed is called whenever the spawn kills something

function killed(Spawn, Spawn)
end
Random Chat

Random Chat is never called and its purpose is lost, code for it still remains so it is listed here just for reference

function randomchat(Spawn, String)
end
Respawn

Respawn is called when the spawn respawns

function respawn(Spawn)
end
Spawn

Spawn is called when the spawn spawns for the first time

function spawn(Spawn)
end
Targeted

Targeted is called whenever a player targets the spawn

function targeted(Spawn, Spawn)
end
Think

Think is used to override AI and is called every time the AI needs to run

function Think(Spawn, Spawn)
end


Tutorials

Coming Soon.

Spawn Script Template

In order to have a spawn script that can be submitted to the server you must follow a certain structure. Use this Spawn Script Template for the spawn scripts. This will have a break down of the code with an explanation of what each part does, and it will also have the full template that you can copy and paste into your editor like notepad++.