Jump to content
  • 0

[scripting support] Label/variables in duplicates


Kurofly

Question


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  283
  • Reputation:   31
  • Joined:  07/08/14
  • Last Seen:  

Hello Ra!

 

I can't seem to find a way to either call a label from a duplicate or set a variable of a duplicate to a value using getvariableofnpc().

 

Is it even possible to acces labels/variables from duplicates?

 

Help needed  ^_^

Link to comment
Share on other sites

9 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  81
  • Topics Per Day:  0.02
  • Content Count:  1654
  • Reputation:   583
  • Joined:  08/09/12
  • Last Seen:  

To call a label, use donpcevent.

getvariableofnpc can only fetch npc-bound variables, but not arrays.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  283
  • Reputation:   31
  • Joined:  07/08/14
  • Last Seen:  

Thank you for your reply.

 

I know that already but it doesn't work for duplicates, I tried to use 'NpcName#num' and 'NpcName#num::UniqueName' as the npc name using getvariableofnpc , donpcevent and doevent but none of them seem to work with duplicates.

It also seems that the OnInit Label only works for the first NPC and not for the others.

 

I worked a lot using these commands so I know well how to use them and what I am not able to do with them but I never tried to use them on duplicates before.

 

Maybe it is possible in a specific way or maybe not, I would juste want to make sure  :lol:

 

Thanks again for your reply.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

Can you post the part of your script that creates the duplicate NPCs?

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10013
  • Reputation:   2345
  • Joined:  10/28/11
  • Last Seen:  

Hello Ra!

 

I can't seem to find a way to either call a label from a duplicate or set a variable of a duplicate to a value using getvariableofnpc().

 

Is it even possible to acces labels/variables from duplicates?

 

Help needed  ^_^

 

something like this ?  using the getd and setd to set and retrieve variable that differentiate based on npc name or any other way , as long as it recognize it's for which npc.

// main npc
-	script	npc_dup#1	-1,{
	
	OnInit:
		.@npc = atoi( strnpcinfo(2) );
		setd( ".npc_variable_"+.@npc ),( .@npc * 1000 );
		end;
		
	OnLabel:
		debugmes "["+strnpcinfo(3)+"] variable value = "+getd( ".npc_variable_"+atoi( strnpcinfo(2) ) ) ;
		end;

}
// duplicate above NPC to set a label event.
-	duplicate(npc_dup#1)	npc_dup#2	-1
-	duplicate(npc_dup#1)	npc_dup#3	-1
-	duplicate(npc_dup#1)	npc_dup#4	-1
-	duplicate(npc_dup#1)	npc_dup#5	-1


// extra npc to trigger specific duplicated npc event label.
-	script	call_label	-1,{
	OnInit:
		sleep 1000;
		donpcevent "npc_dup#3::OnLabel";
		donpcevent "npc_dup#1::OnLabel";
		donpcevent "npc_dup#4::OnLabel";
		donpcevent "npc_dup#2::OnLabel";
		donpcevent "npc_dup#5::OnLabel";
		end;
}

Preview :

ESIPfN0.png

 

 


 

 

To call a label, use donpcevent.

getvariableofnpc can only fetch npc-bound variables, but not arrays.

I believe it's actually possible.


-	script	npc_1	-1,{
	OnInit:
		setarray .array,1,2,3,4,5;
		.array_size = getarraysize( .array );
		end;
}

-	script	npc_2	-1,{
	OnInit:
		sleep 1000;
		.@size = getvariableofnpc( .array_size,"npc_1" );
		while ( .@i < .@size ) {
			debugmes "[npc_1] .array["+.@i+"] = "+getelementofarray( getvariableofnpc( .array,"npc_1" ),.@i );
			.@i++;
		}
		end;
}

Preview :

5S6mlvl.png

 

However, most of the users out there did it using the global variable ($ and $@) most of the time.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  283
  • Reputation:   31
  • Joined:  07/08/14
  • Last Seen:  

I'll try to explain what I'm trying to do in details ^^ thank you guys for showing interest in this.

 

I'm making kind of a pokemon script which allows players to get a pokemon as a pet and to train him battling against other pokemons in a specified area.

In this area there are some NPC with pokemon monster sprite ids (those who are marked with a sword like monsters when you put your mouse on them and who you have to touch to start a script)

post-27270-0-65725300-1432055892_thumb.jpg

When you touch one of those pokemons it starts a fight with it, you're warped somewhere else and only pokemons can fight.

post-27270-0-73610300-1432055907_thumb.jpg

Since I want it to be able to manage more than one fight at once(in different maps though), I choosed to make a NPC in charge of managing fights in his map.

So now I need to duplicate this NPC, and since one of them takes approximately 200 lines to manage a fight I didn't want to copy-paste 10 of them.

So I started to test 2 or 3 things using duplicates to see if I could reduce the amount of lines in my script

 

Here is what I tried to do (those are just examples) :

-	script	testttttt	-1,{
OnInit:
	bindatcmd "test",strnpcinfo(0)+"::OnTest";
	end;
OnTest:
	set getvariableofnpc(.var,"testnpc") , -1; //works but set it for all duplicates..
	set getvariableofnpc(.var,"BattleNPC#1::testnpc") , 1; //doesn't work
	donpcevent "BattleNPC::OnLabel";
	donpcevent "BattleNPC#1::OnLabel";
	donpcevent "BattleNPC#1::testnpc::OnLabel";
	donpcevent "testnpc::OnLabel";
	//can't access 'OnLabel' label with these
}

poring_w01,105,110,4	script	BattleNPC#1::testnpc	53,{
	mes "" , "value assigned : "+.var;
	close;
OnInit:
	debugmes "NPC "+strnpcinfo(2)+" successfully called 'OnInit' label";
	end;
OnLabel:
	debugmes "NPC "+strnpcinfo(2)+" successfully called 'OnLabel' label";
	disablenpc strnpcinfo(0);
	disablenpc strnpcinfo(1);
	disablenpc strnpcinfo(0)+"::"+strnpcinfo(3);
	//none of them work
}

poring_w01,106,110,4	duplicate(testnpc)	BattleNPC#2	53
poring_w01,107,110,4	duplicate(testnpc)	BattleNPC#3	53

Judging from my tests the OnInit label only goes with the first NPC (the one not duplicated) and then I can't access other labels from any of these NPCs anymore.

I can set a variable using the unique name of the NPCs but all of them will have the same value.

I also can't disable them

 

I never duplicated any NPC before so I'm not used to it but it seems many things are not possible using duplicates.

 

Basically I would want those duplicates to be able to have their own variables and to manage their actions calling labels, I would also want to use npc timers in each of those.

 

Hope you guys understand what I mean, sorry for my bad english if I can't manage to make myself clear enough and thank you  /no1

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

From within the script if you use strnpcinfo(3) that will reference the NPC's unique name, and in duplicated NPCs, that will be the unique name of the duplicate NPC.

 

To call a label, use donpcevent.

getvariableofnpc can only fetch npc-bound variables, but not arrays.

If you're planning on accessing variables of other NPCs on the map or triggering event labels in other NPCs on the map, I suggest name the NPCs like this: NPCNAME#mapname

BattleNPC#poring_w01

testnpc#poring_w01

BattleNPC#anothermap

testnpc#anothermap

Then if you want BattleNPC#poring_w01 to trigger something in testnpc#poring_w01 you could do:

donpcevent "testnpc#" + strnpcinfo(4);
which will be "testnpc#poring_w01" because strnpcinfo(4) returns the name of the map the NPC is in.

When you create duplicates on different maps, strnpcinfo(4) will return the mapname and it will work (as long as your npcs are named NPCNAME#mapname.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  283
  • Reputation:   31
  • Joined:  07/08/14
  • Last Seen:  

Yeah I know I just wanted to make my script shorter but seems like I can't.

 

Anyway thank you for your support, I really appreciate it /gawi

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  81
  • Topics Per Day:  0.02
  • Content Count:  1654
  • Reputation:   583
  • Joined:  08/09/12
  • Last Seen:  

@Emistry, where did you get that HCP on your screenshot?

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10013
  • Reputation:   2345
  • Joined:  10/28/11
  • Last Seen:  

@Emistry, where did you get that HCP on your screenshot?

it's hercules emulator.

Link to comment
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.   Paste as plain text instead

  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.

×
×
  • Create New...