Jump to content
  • 0

Detaching RID


Reborn

Question


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

Hello guys. Can anyone help me to fix this?

addrid(4,0,36,63,63,36);
for (set .@i,0; .@i < getarraysize(.prize); .@i++ ){
	getitem .prize[.@i],.prize[.@i];
}
announce .npcName$ + " : We have a winner. "+ strcharinfo(0) +" wins the death by dice event round "+ .diceRound +".",0;
detachrid;
if (.consolation){
	addrid(1);
	for (set .@t,0; .@t < getarraysize(.consolation); .@t++ ){
		getitem .consolation[.@t],.consolation[.@t];
	}
	detachrid;
}

sleep 5000;
announce "Thank you for playing...";

The issue is when this event was triggered. The "rids" works fine however after the rid, the announcement "Thank you for playing..." will be announced multiple times. If there is 5 players the announcement will announced 5 times as well. How can I make it announce once only?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 1

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

There's... probably a solution that will work, but I would recommend adding new script functions instead to make your life much easier:

static int script_foreach_sub_va_bl(struct block_list* bl, va_list args) {
	const char* label = va_arg(args, const char*);
	return script_foreach_sub((TBL_PC*)bl, label);
}

// void foreachinmap "<npc_label>", "<map name>"
BUILDIN_FUNC(foreachinmap)
{
	const char* label = script_getstr(st,2);
	const char* mapname = script_getstr(st,3);
	TBL_NPC* nd = map_id2nd(st->oid);
	int16 m = (nd && strcmp(mapname, "this") == 0) ? nd->bl.m : map_mapname2mapid(mapname);

	if (m < 0) {
		return SCRIPT_CMD_SUCCESS;
	}

	map_foreachinmap(script_foreach_sub_va_bl, m, BL_PC, label); 
	return SCRIPT_CMD_SUCCESS;
}
                                             
/// void foreachinarea "<npc_label>", "<map_name>", <x1>, <y1>, <x2>, <y2>
BUILDIN_FUNC(foreachinarea)
{
	const char* label = script_getstr(st,2);
	const char* mapname = script_getstr(st,3);
	int x1 = script_getnum(st,4);
	int y1 = script_getnum(st,5);
	int x2 = script_getnum(st,6);
	int y2 = script_getnum(st,7);
	TBL_NPC* nd = map_id2nd(st->oid);
	int16 m = (nd && strcmp(mapname, "this") == 0) ? nd->bl.m : map_mapname2mapid(mapname);

	if (m < 0) {
		return SCRIPT_CMD_SUCCESS;
	}

	map_foreachinarea(script_foreach_sub_va_bl, m, x1, y1, x2, y2, BL_PC, label);
	return SCRIPT_CMD_SUCCESS;
}

// defs
BUILDIN_DEF(foreachinmap,"ss"),
BUILDIN_DEF(foreachinarea,"ssiiii"),

Then your script would be:

prontera,156,188,0	script	dummy_script	77,{
	// ...
OnScriptEnd:
	// not sure where you get the winner from!
	foreachinarea(strnpcinfo(0) + "::OnReward", "this", 36, 63, 63, 36);
	
	if (.consolation) {
		foreachinmap(strnpcinfo(0) + "::OnConsolation", "this");
	}
	
	sleep 5000;
	announce "Thank you for playing...";
	end;
OnReward:
	for (.@i = 0; .@i < getarraysize(.prize); .@i++) {
		getitem .prize[.@i], .prize[.@i];
		// ^ this won't work, you either need two arrays, or use .@i += 2 instead of .@i++
	}
	
	announce .npcName$ + " : We have a winner. " + strcharinfo(0) + " wins the death by dice event round "+ .diceRound +".",0;
	// ^ This will be announced multiple times if you have more than one player remaining in that area, the winner announce
	// should be moved to "OnScriptEnd", but you didn't post your full script.
	end;
OnConsolation:
	for (.@i = 0; .@i < getarraysize(.consolation); .@i++) {
		getitem .consolation[.@i], .consolation[.@i];
		// ^ this won't work, you either need two arrays, or use .@i += 2 instead of .@i++
	}
	
	end;
}

Using addrid is kind of a nightmare, and you lose the main script control which is very annoying.

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:  

Wrong section. Moved to "Scripting Support".

@neXus

addrid(4,0,36,63,63,36);
for (set .@i,0; .@i < getarraysize(.prize); .@i++ ){
	getitem .prize[.@i],.prize[.@i];
}
announce .npcName$ + " : We have a winner. "+ strcharinfo(0) +" wins the death by dice event round "+ .diceRound +".",0;
detachrid;
if (.consolation){
	addrid(1);
	for (set .@t,0; .@t < getarraysize(.consolation); .@t++ ){
		getitem .consolation[.@t],.consolation[.@t];
	}
	detachrid;
}

if(.length != 0)
	end;
.length++;
sleep 5000;
announce "Thank you for playing...";
.length = 0;

 

Winner will still be announced multiple times. I'm not sure if that's what you wanted but "Thank you for playing..." will only be announced once this way.

Addrid starts a new instance of the npc for each player added to it given by the parameters. Detaching a player does not stop that instance of the script from running.

Edited by Skorm
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...