NPC Hero
» Siedler Map Source Forum » Siedler DEdK Script Forum » NPC Hero
Seiten: 1
SH
|
#1 01.03.2020 18:56 Beiträge: 127 |
NPC Hero
Hello,
It is possible to create different NPC callbacks depending on the heroes who are talking to this NPC?
____________________
Sorry for my German
Play4FuN
|
#2 02.03.2020 08:45 Beiträge: 704 |
Yes, it is!
Have a look at this:
GameCallback_NPCInteraction_Orig = GameCallback_NPCInteraction_Orig or GameCallback_NPCInteraction GameCallback_NPCInteraction = function( _heroId,_npcId ) GameCallback_NPCInteraction_Orig( _heroId,_npcId ) Message( _heroId ) Message( _npcId ) end
... call this once somewhere e.g. in your FirstMapAction.
You will then see a message of the hero ID and the NPC ID on interaction.
Next step would be to create some kind of if structure to perform different callback actions. Let me know if you need help with that
And here is a 2nd and probably better approach (using the LuaDebugger to debug print the parameters):
CreateNPC{ name = "my_npc", callback = function(a,b) LuaDebugger.Log(a) LuaDebugger.Log(b) end }
... every time your hero talks to an NPC, the callback function will be triggered (! unless you defined a "briefing" function instead of a "callback" function for the NPC !). This callback function will have 2 parameters: see the original code:
NPC[_npcId].callback(NPC[_npcId], _heroId)
As you can see, the second parameter yields the hero ID. So without futher investigating, it seems that using the second method should be easier
Here is a little help on how to implement it:
CreateNPC{ name = "my_npc", callback = function( npcTable, heroId ) if heroId == GetEntityId("dario") then -- do something... elseif heroId == GetEntityId("erec") then -- do something else... end end }
____________________
LG Play4FuN
Siedler DEdK Mapping + Scripting Tutorials
SH
|
#3 02.03.2020 16:10 Beiträge: 127 |
Hi, Play4FuN!
Thank you very much, I tested it and it works very nice.
SH
____________________
Sorry for my German
Seiten: 1