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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

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