Jump to content
  • 0
luizragna

Duplicate NPCs use the same variable

Question

Hello guys. The NPC are using the same variables.

-	script	Tester	FAKE_NPC,{

if (.ok == 0)
{
  mes "Hello";
  set .ok,1; // or .ok = 1;
}
  else
   mes "I already talked to you";
    
  close();

}

prt_sewb1,154,268,4	duplicate(Tester)	Tester#1	84
prt_sewb1,160,268,4	duplicate(Tester)	Tester#2	84

 

When i talk a NPC, the other say:  "I already talked to you". So, they uses the same variable [ .ok ]

how i can change this??

Edited by luizragna

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

I had this issue with campfires and stuff

When you dupe you gottta create a unique NPC name

ex from my CampFire NPC

sprintf("Campfire#CF_%d", getcharid(CHAR_ID_CHAR))

then you can do 

setd and getd of 

setd(sprintf(".@MegaVariable_%d", [unique identifier]))

 

Share this post


Link to post
Share on other sites
  • 0

Duplicate npcs do share variables but this is legacy code that we can't change without breaking backward-compatibility. What we could do however is add a config flag so you can manually choose the desired behaviour.

The problem is that in npc_duplicate_script_sub the function does npc->script = source->script, so it creates a pointer to the parent script_code struct instead of creating its own and variables are stored in this struct. The Evol plugin fixes this by creating its own struct but since I see other people want this change I will move it to Hercules directly instead.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.