How to get ' instance variable

bWolfie

I'm the man
Messages
850
Points
0
Location
Alberta, Midgard
Github
bWolfie
Emulator
Hello,
 
I have created a script which will assign an account-wide delay timer to those who log out to avoid the warp-out NPC which I have variables attached to.
 
My problem is the 'ins_nyd2 value - it always returns 0.
Code:
[Warning]: script_get_val: cannot access instance variable ''ins_nyd2', defaulting to 0
 
The script works fine if I removethe  if ('ins_nyd2 < 4) end; line, but there are cases when players genuinely disconnect, which would lock them out of finishing the instance.
 
Code:
-    script    nyd_logout_exploit    FAKE_NPC,{
 
OnPCLogoutEvent:
    if (!compare(strcharinfo(PC_MAP), "2@nyd")) end;
 
    getmapxy (@map$,@x,@y,UNITTYPE_PC);
    if ('ins_nyd2 < 4) end;
 
    if ((@x >= 100 && @x <= 300) && (@y >= 255 && @y <= 390))
        #nyd_nest = gettimetick(2) + ( 60 * 60 * 24 * 3);    // 3 Days
    end;
}
 
Last edited by a moderator:
If they logout without an instance they wont be able to read the instance variable. Before doing anything make sure they have the instance (script command has_instance)

Code:
OnPCLogoutEvent:
if ( has_instance "2@nyd" == "" ) {
Etc
}
 
The npc is not attached to an instance because only those that are inside an instance map are attached, so, floating npcs can't read instance variables because they are not attached. Try put a location for the npc:

2@nyd,1,1,0 script nyd_logout_exploit FAKE_NPC,{
end;

OnPCLogoutEvent:
if (!compare(strcharinfo(PC_MAP), "2@nyd")) end;

getmapxy (@map$,@x,@y,UNITTYPE_PC);
if ('ins_nyd2 < 4) end;

if ((@x >= 100 && @x <= 300) && (@y >= 255 && @y <= 390))
#nyd_nest = gettimetick(2) + ( 60 * 60 * 24 * 3); // 3 Days
end;
}


However, this practice is not recommended and will be harmful because you will be duplicating the OnPCLogoutEvent with every instance created.

Maybe you could try with this other:

- script nyd_logout_exploit FAKE_NPC,{
end;

OnPCLogoutEvent:
if (!compare(strcharinfo(PC_MAP), "2@nyd"))
end;
.@instance_id = has_instance2("2@nyd");
instance_attach(.@instance_id);
getmapxy (@map$, @x, @y, UNITTYPE_PC);
if ('ins_nyd2 < 4)
end;
if ((@x >= 100 && @x <= 300) && (@y >= 255 && @y <= 390))
#nyd_nest = gettimetick(2) + (60 * 60 * 24 * 3); // 3 Days
end;
}


This other npc manually attaches the floating npc to the instance gived by has_instance2() command, and then I think you can read the instance variable (needs test).

 
Last edited by a moderator:
The npc is not attached to an instance because only those that are inside an instance map are attached, so, floating npcs can't read instance variables because they are not attached. Try put a location for the npc:

2@nyd,1,1,0 script nyd_logout_exploit FAKE_NPC,{
end;

OnPCLogoutEvent:
if (!compare(strcharinfo(PC_MAP), "2@nyd")) end;

getmapxy (@map$,@x,@y,UNITTYPE_PC);
if ('ins_nyd2 < 4) end;

if ((@x >= 100 && @x <= 300) && (@y >= 255 && @y <= 390))
#nyd_nest = gettimetick(2) + ( 60 * 60 * 24 * 3); // 3 Days
end;
}


However, this practice is not recommended and will be harmful because you will be duplicating the OnPCLogoutEvent with every instance created.

Maybe you could try with this other:

- script nyd_logout_exploit FAKE_NPC,{
end;

OnPCLogoutEvent:
if (!compare(strcharinfo(PC_MAP), "2@nyd"))
end;
.@instance_id = has_instance2("2@nyd");
instance_attach(.@instance_id);
getmapxy (@map$, @x, @y, UNITTYPE_PC);
if ('ins_nyd2 < 4)
end;
if ((@x >= 100 && @x <= 300) && (@y >= 255 && @y <= 390))
#nyd_nest = gettimetick(2) + (60 * 60 * 24 * 3); // 3 Days
end;
}


This other npc manually attaches the floating npc to the instance gived by has_instance2() command, and then I think you can read the instance variable (needs test).
Thank you again good sir. I will try it out and get back to you.

The second one worked perfect, just as I imagined it would. Not sure if there is a way to error it out, but as it stands looks great!

 
Last edited by a moderator:
Back
Top