Jump to content
  • 0

Choose one random player in the map every 10 seconds.


Jannah

Question


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.01
  • Content Count:  6
  • Reputation:   0
  • Joined:  03/06/22
  • Last Seen:  

I'm a beginner when it comes to scripting so I badly need help on this one.

I need a script that when triggered will add every player in the map in an array and then choose one of them. 
Basically the script I want should be able to kill one player in the map every 10 seconds until only 1 player is left. 
It's like a survival but with only luck involve. 

I know that it might be too much to ask for too many specifics so I'll really appreciate it, if someone can give me an example script that could at least use addrid, add them in array and choose one of them. 

Thank you very much in advance!
 

 

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

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

something like this

-	script	atcmd_example	-1,{
OnInit:
	bindatcmd "start", strnpcinfo(3) + "::OnAtcommand", 99;
	end;
	
OnAtcommand:
	if (.running) {
		dispbottom "event currently running at '"+.map$+"' by '"+.gm_name$+"'.";
		end;
	}
	
	.@getmapusers = getmapusers(strcharinfo(3));
	if (.@getmapusers < 0) {
		dispbottom "invalid map '"+.map$+"', event stopped.";
	}
	else if (.@getmapusers <= 2) {
		dispbottom "this map lack of user to start event, required at least another 2 users (excluding yourself).";
	}
	else {
		.running = 1;
		.current_round = 0;
		.map$ = strcharinfo(3);
		.gm_name$ = strcharinfo(0);
		initnpctimer;
		dispbottom "event started at '"+.map$+"' by '"+.gm_name$+"'.";
		mapannounce .map$, "event started at '"+.map$+"' by '"+.gm_name$+"'.", bc_map;
	}
	end;
	
OnTimer10000:
	if (!.running) {
		stopnpctimer;
		end;
	}
	.@total_count = getmapunits(BL_PC, .map$, .@player_name$);
	.@owner_index = inarray(.@player_name$, .gm_name$);
	if (.@owner_index != -1) {
		// offset GM himself
		deletearray .@player_name$[.@i], 1;
		.@total_count--;
	}
	.current_round++;
	if (.@total_count <= 0) {
		mapannounce .map$, "Round "+.current_round+": no more player, event stopped...", bc_map;
		donpcevent strnpcinfo(3)+"::OnStop";
	}
	else if (.@total_count <= 1) {
		mapannounce .map$, "Round "+.current_round+": we have a winner "+.@player_name$+"!", bc_map;
		donpcevent strnpcinfo(3)+"::OnStop";
	}
	else {
		.@i = rand(.@total_count);
		mapannounce .map$, "Round "+.current_round+": we killed "+.@player_name$[.@i]+" out of "+.@total_count+" players in this map.", bc_map;
		unitkill convertpcinfo(.@player_name$[.@i], CPC_ACCOUNT);
		specialeffect2 EF_GROUND_EXPLOSION, AREA, .@player_name$[.@i];
		initnpctimer;
	}
	end;
	
OnStop:
	stopnpctimer;
	.running = 0;
	.current_round = 0;
	.map$ = "";
	.gm_name$ = "";
	end:
}

 

  • Love 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.01
  • Content Count:  6
  • Reputation:   0
  • Joined:  03/06/22
  • Last Seen:  

19 minutes ago, Emistry said:

something like this

-	script	atcmd_example	-1,{
OnInit:
	bindatcmd "start", strnpcinfo(3) + "::OnAtcommand", 99;
	end;
	
OnAtcommand:
	if (.running) {
		dispbottom "event currently running at '"+.map$+"' by '"+.gm_name$+"'.";
		end;
	}
	
	.@getmapusers = getmapusers(strcharinfo(3));
	if (.@getmapusers < 0) {
		dispbottom "invalid map '"+.map$+"', event stopped.";
	}
	else if (.@getmapusers <= 2) {
		dispbottom "this map lack of user to start event, required at least another 2 users (excluding yourself).";
	}
	else {
		.running = 1;
		.current_round = 0;
		.map$ = strcharinfo(3);
		.gm_name$ = strcharinfo(0);
		initnpctimer;
		dispbottom "event started at '"+.map$+"' by '"+.gm_name$+"'.";
		mapannounce .map$, "event started at '"+.map$+"' by '"+.gm_name$+"'.", bc_map;
	}
	end;
	
OnTimer10000:
	if (!.running) {
		stopnpctimer;
		end;
	}
	.@total_count = getmapunits(BL_PC, .map$, .@player_name$);
	.@owner_index = inarray(.@player_name$, .gm_name$);
	if (.@owner_index != -1) {
		// offset GM himself
		deletearray .@player_name$[.@i], 1;
		.@total_count--;
	}
	.current_round++;
	if (.@total_count <= 0) {
		mapannounce .map$, "Round "+.current_round+": no more player, event stopped...", bc_map;
		donpcevent strnpcinfo(3)+"::OnStop";
	}
	else if (.@total_count <= 1) {
		mapannounce .map$, "Round "+.current_round+": we have a winner "+.@player_name$+"!", bc_map;
		donpcevent strnpcinfo(3)+"::OnStop";
	}
	else {
		.@i = rand(.@total_count);
		mapannounce .map$, "Round "+.current_round+": we killed "+.@player_name$[.@i]+" out of "+.@total_count+" players in this map.", bc_map;
		unitkill convertpcinfo(.@player_name$[.@i], CPC_ACCOUNT);
		specialeffect2 EF_GROUND_EXPLOSION, AREA, .@player_name$[.@i];
		initnpctimer;
	}
	end;
	
OnStop:
	stopnpctimer;
	.running = 0;
	.current_round = 0;
	.map$ = "";
	.gm_name$ = "";
	end:
}

 

yes, unfortunately I'm using an older version of rathena and some of those script commands such as convertpcinfo and getmapunits aren't going to work. And I'm just a newbie in scripting.

The idea is similar, though I guess the simplest one that would work well for me are those that uses addrid. Eitherway thank you very much for that very good example. 

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:  

you can also try something like this.

-	script	atcmd_example	-1,{
OnInit:
	bindatcmd "start", strnpcinfo(3) + "::OnAtcommand", 99;
	end;
	
OnAtcommand:
	if (.running) {
		dispbottom "event currently running at '"+.map$+"' by '"+.gm_name$+"'.";
		end;
	}
	
	.@getmapusers = getmapusers(strcharinfo(3));
	if (.@getmapusers < 0) {
		dispbottom "invalid map '"+.map$+"', event stopped.";
	}
	else if (.@getmapusers <= 2) {
		dispbottom "this map lack of user to start event, required at least another 2 users (excluding yourself).";
	}
	else {
		deletearray .player_aid_pool;
		.player_aid_pool_size = 0;
		
		.running = 1;
		.current_round = 0;
		.map$ = strcharinfo(3);
		.gm_name$ = strcharinfo(0);
		initnpctimer;
		
		dispbottom "event started at '"+.map$+"' by '"+.gm_name$+"'. ";
		mapannounce .map$, "event started at '"+.map$+"' by '"+.gm_name$+"'.", bc_all;
		
		if (getmapflag(.map$, MF_LOADEVENT))
			setmapflag(.map$, MF_LOADEVENT);
			
		mapwarp .map$, .map$, 0, 0;
	}
	end;
	
OnPCLoadMapEvent:
	if (.running && !getgmlevel()) {
		.player_aid_pool[.player_aid_pool_size] = getcharid(3);
		.player_aid_pool_size++;
		dispbottom "You are registered as "+.player_aid_pool_size+"th in this event.";
	}
	end;
	
OnTimer10000:
	if (!.running) {
		stopnpctimer;
		end;
	}
	
	.current_round++;
	if (.player_aid_pool_size <= 0) {
		mapannounce .map$, "Round "+.current_round+": no more player, event stopped...", bc_map;
		donpcevent strnpcinfo(3)+"::OnStop";
	}
	else if (.player_aid_pool_size <= 1) {
		mapannounce .map$, "Round "+.current_round+": we have a winner "+.@player_name$+"!", bc_map;
		donpcevent strnpcinfo(3)+"::OnStop";
	}
	else {
		.@i = rand(.player_aid_pool_size);
		mapannounce .map$, "Round "+.current_round+": we killed "+rid2name(.player_aid_pool[.@i])+" out of "+.player_aid_pool_size+" players in this map.", bc_map;
		unitkill .player_aid_pool[.@i];
		specialeffect2 EF_GROUND_EXPLOSION, AREA, .@player_name$[.@i];
		initnpctimer;
		deletearray .player_aid_pool[.@i], 1;
		.player_aid_pool_size--;
	}
	end;
	
OnStop:
	stopnpctimer;
	.running = 0;
	.current_round = 0;
	.map$ = "";
	.gm_name$ = "";
	deletearray .player_aid_pool;
	.player_aid_pool_size = 0;
	if (getmapflag(.map$, MF_LOADEVENT))
		removemapflag(.map$, MF_LOADEVENT);
	end:
}

 

  • Love 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.01
  • Content Count:  6
  • Reputation:   0
  • Joined:  03/06/22
  • Last Seen:  

56 minutes ago, Emistry said:

you can also try something like this.

-	script	atcmd_example	-1,{
OnInit:
	bindatcmd "start", strnpcinfo(3) + "::OnAtcommand", 99;
	end;
	
OnAtcommand:
	if (.running) {
		dispbottom "event currently running at '"+.map$+"' by '"+.gm_name$+"'.";
		end;
	}
	
	.@getmapusers = getmapusers(strcharinfo(3));
	if (.@getmapusers < 0) {
		dispbottom "invalid map '"+.map$+"', event stopped.";
	}
	else if (.@getmapusers <= 2) {
		dispbottom "this map lack of user to start event, required at least another 2 users (excluding yourself).";
	}
	else {
		deletearray .player_aid_pool;
		.player_aid_pool_size = 0;
		
		.running = 1;
		.current_round = 0;
		.map$ = strcharinfo(3);
		.gm_name$ = strcharinfo(0);
		initnpctimer;
		
		dispbottom "event started at '"+.map$+"' by '"+.gm_name$+"'. ";
		mapannounce .map$, "event started at '"+.map$+"' by '"+.gm_name$+"'.", bc_all;
		
		if (getmapflag(.map$, MF_LOADEVENT))
			setmapflag(.map$, MF_LOADEVENT);
			
		mapwarp .map$, .map$, 0, 0;
	}
	end;
	
OnPCLoadMapEvent:
	if (.running && !getgmlevel()) {
		.player_aid_pool[.player_aid_pool_size] = getcharid(3);
		.player_aid_pool_size++;
		dispbottom "You are registered as "+.player_aid_pool_size+"th in this event.";
	}
	end;
	
OnTimer10000:
	if (!.running) {
		stopnpctimer;
		end;
	}
	
	.current_round++;
	if (.player_aid_pool_size <= 0) {
		mapannounce .map$, "Round "+.current_round+": no more player, event stopped...", bc_map;
		donpcevent strnpcinfo(3)+"::OnStop";
	}
	else if (.player_aid_pool_size <= 1) {
		mapannounce .map$, "Round "+.current_round+": we have a winner "+.@player_name$+"!", bc_map;
		donpcevent strnpcinfo(3)+"::OnStop";
	}
	else {
		.@i = rand(.player_aid_pool_size);
		mapannounce .map$, "Round "+.current_round+": we killed "+rid2name(.player_aid_pool[.@i])+" out of "+.player_aid_pool_size+" players in this map.", bc_map;
		unitkill .player_aid_pool[.@i];
		specialeffect2 EF_GROUND_EXPLOSION, AREA, .@player_name$[.@i];
		initnpctimer;
		deletearray .player_aid_pool[.@i], 1;
		.player_aid_pool_size--;
	}
	end;
	
OnStop:
	stopnpctimer;
	.running = 0;
	.current_round = 0;
	.map$ = "";
	.gm_name$ = "";
	deletearray .player_aid_pool;
	.player_aid_pool_size = 0;
	if (getmapflag(.map$, MF_LOADEVENT))
		removemapflag(.map$, MF_LOADEVENT);
	end:
}

 

thank you very much

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