Duplicate NPCs use the same variable

luizragna

New member
Messages
114
Points
0
Location
In their hearts
Emulator
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??

 
Last edited by a moderator:
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 

Code:
setd(sprintf(".@MegaVariable_%d", [unique identifier]))
 
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.

 
Back
Top