Jump to content
  • 0

How the script identify if the whole party member is dead?


Reborn

Question


  • Group:  Members
  • Topic Count:  104
  • Topics Per Day:  0.03
  • Content Count:  290
  • Reputation:   3
  • Joined:  09/29/13
  • Last Seen:  

Hi  everyone. I've been searching this one but I can't really find it. How can the script identify that all party member is dead?

Cause this is what I am trying to do. The whole party will enter an instance. If the whole party member is dead the script will trigger it and the whole party will be warped out from the map after 2 mins.

I hope some knows how to do this. Thanks in advance :D

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

37 minutes ago, neXus said:

I hope some knows how to do this. Thanks in advance :D

There are plenty of ways to do this here's one.

//Set this after the instance is created and with an npc that is attached to the instance ID.
getpartymember( getcharid(1) );
'instance_members = $@partymembercount;


//Do this within an npc that is attached to the instance.
OnPCDieEvent:
	'instance_members--;
	if( !'instance_members ) {
		//Oh crap everyone is dead!!!
	}
	end;

 

Edited by Skorm
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  104
  • Topics Per Day:  0.03
  • Content Count:  290
  • Reputation:   3
  • Joined:  09/29/13
  • Last Seen:  

@Skorm

Thanks for helping me, however when I tried to put this script to the NPC being attached to their instance ID it seems not working. I am getting an error message.

[Warning]: script_get_val: cannot access instance variable ''instance_members', defaulting to 0
[Warning]: script_get_val: cannot access instance variable ''instance_members', defaulting to 0
[Error]: script_set_reg: cannot write instance variable ''instance_members', NPC not in a instance!
[Debug]: Source (NPC): PartyPlanner#RDC at e@gef (0,0)
[Warning]: script_get_val: cannot access instance variable ''instance_members', defaulting to 0

That is the exact message and error I am getting. The one you made is attached to an instance NPC i tried to put it in a Visible and Invisible NPC but still not working..

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  667
  • Reputation:   674
  • Joined:  11/12/12
  • Last Seen:  

There are no easy ways of doing this, OnPCDieEvent is annoying to use. I would try the following instead:

1@tower,0,0,0	script	#ins_die_event_sub	-1,{
	end;
OnPartyCheck:
	'player_alive = 0;
	getpartymember 'party_id, 2;
	
	for (.@i = 0; .@i < $@partymembercount && !'player_alive; .@i++) {
		if (isloggedin($@partymemberaid[.@i]) && $@partymemberaid[.@i] != 'ins_rid) { // Logged out players are still active
			if (attachrid($@partymemberaid[.@i])) {
				if (HP > 0 && strcharinfo(3) == instance_mapname("1@tower")) {
					'player_alive++;
				}
				
				detachrid();
			}
		}
	}
	
	// Run code back on the instance
	if ('player_alive == 0) {
		announce "All players have died.", 0;
	}
	
	end;
}

-	script	#ins_die_event	-1,{
	end;
OnPCDieEvent:
OnPCLogoutEvent:
	if (strcharinfo(3) == instance_mapname("1@tower")) {
		// Do not perform the party checks here directly, this script
		// is never attached to the instance.
		'party_id = getcharid(1);
		'ins_rid = getattachedrid();
		
		donpcevent instance_npcname("#ins_die_event_sub") + "::OnPartyCheck";
	}
	
	end;
}

There are few things you have to be very careful with such scripts. OnPCDieEvent is a global event label which is not attached to your instance nor is it duplicated. All players who die on your server will trigger this event label, hence why you have to check if the player has the instance (and why you should not put the NPC in the instance map). The usage of a donpcevent is to force the script to run back on the instance after it's detached from the players' checks. You also cannot rely on $@partymembercount alone since some members could be offline in the party. Players can also leave the party or logout, which you have to take into account.

Edited by Tokei
Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

 

11 hours ago, Tokei said:

I would try the following instead:

		'party_id = getcharid(1);
		'ins_rid = getattachedrid();
		
		donpcevent instance_npcname("#ins_die_event_sub") + "::OnPartyCheck";

Does that actually work? Setting the instance variable in a non-instanced npc and then passing it to an instanced npc? But yeah I agree it's a pain the only time it isn't that difficult is when using the battleground system.

I thought about just copying the array for partycid into an instanced one and setting each player with a temp variable that corresponded to their position on the array removing them and getting the size each time they logout or die. And doing an initial check to see if they were online when the instance was created. I think then you wouldn't need to check everything everytime someone dies.

Edited by Skorm
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  667
  • Reputation:   674
  • Joined:  11/12/12
  • Last Seen:  

		'party_id = getcharid(1);
		'ins_rid = getattachedrid();
		
		donpcevent instance_npcname("#ins_die_event_sub") + "::OnPartyCheck";

This works because the player is being attached to the script (it stops working if you detach the player, though). I really like your alternative solution actually! You wouldn't have to deal with the attach/detachrid uglyness. But how would you identify players leaving the party or being added to the party? (I don't think you can prevent a player from leaving a party.)

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

On 1/21/2017 at 10:24 AM, Tokei said:

You wouldn't have to deal with the attach/detachrid uglyness. But how would you identify players leaving the party or being added to the party? (I don't think you can prevent a player from leaving a party.)

I would use the partylock mapflag.

Link to comment
Share on other sites

  • 0

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

On 1/21/2017 at 10:33 PM, Skorm said:

setting each player with a temp variable that corresponded to their position on the array removing them

this trick is actually abit risky too :D the array size will be changed, we often forgot that the index (value of the attached variable) of each player need to be updated everytime a player is removed from the array.

Happen to me when I was writing this Channel System few years ago ...

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

18 hours ago, Emistry said:

this trick is actually abit risky too :D the array size will be changed, we often forgot that the index (value of the attached variable) of each player need to be updated everytime a player is removed from the array.

Happen to me when I was writing this Channel System few years ago ...

Yeah that's actually a good point; I've successfully done it before, but I can see where you're coming from.

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