Jump to content
  • 0
Sign in to follow this  
bWolfie

How to get ' instance variable

Question

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.
[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.
 

 


-    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;
}

Edited by True Zeal

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

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)

 

OnPCLogoutEvent:
if ( has_instance "2@nyd" == "" ) {
Etc
}

Share this post


Link to post
Share on other sites
  • 0

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).

Edited by Ragno

Share this post


Link to post
Share on other sites
  • 0

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!

Edited by True Zeal

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...
Sign in to follow this  

×
×
  • Create New...

Important Information

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