Sign in to follow this  
Followers 0
Christian [epicRO]

Russian Roulette - NPC Managed Event, SQL Table required

11 posts in this topic

New Event on epicRO - Russian Roulette

I would like to share with you our new event on epicRO. Started with an atcommand, registration with Event Manager NPC and a simple SQL Db for registred Players.
Autostart with Atcommand (e.g. atcommand_event) as gamemaster.
 

-	script	atcommand_event	-1,{

OnInit:
	bindatcmd "event",strnpcinfo(3)+"::OnAtcommand",1;
	end;
  
	OnAtcommand:
  
	mes "[Atcommand]";
	set $eventgmname$, strcharinfo(0);
	mes "Event will start now.";
	close2;
	detachrid;
  
	set $RRDURCHGANG, $RRDURCHGANG + 1;
	set $RRREGISTREDUSER, 0;
	set $RRZENYPOT, 0;
	set $RRNEXTPLAYER, 0;
	query_sql("TRUNCATE TABLE `event_russian_roulette`");
  
	set $russianroulette, 1;
	announce "Event Manager: "+$eventgmname$+" wants to play Russian Roulette with you!",bc_all|bc_blue;
	announce "Event Manager: Visit me for more informations and register yourself for 1.000 Zeny.",bc_all|bc_blue;
	sleep 5000;
	announce "Event Manager: Event will start in 5 minutes and runs until the last player standing.",bc_all|bc_blue;
	announce "Event Manager: Visit me for more informations and register yourself for 1.000 Zeny.",bc_all|bc_blue;
	sleep 60000;
	announce "Event Manager: Russian Roulette will start in 4 minutes.",bc_all|bc_blue;
	announce "Event Manager: I will use the pistol. You'll have a 1:4 chance to survive.",bc_all|bc_blue;
	sleep 60000;
	announce "Event Manager: Russian Roulette will start in 3 minutes.",bc_all|bc_blue;
	announce "Event Manager: Current Survive-Zenypot is filled with "+$RRZENYPOT+" Zeny.",bc_all|bc_blue;
	sleep 60000;
	announce "Event Manager: Russian Roulette will start in 2 minutes.",bc_all|bc_blue;
	announce "Event Manager: You'll earn at least 1 Loyality Coin (10%) for every survived round.",bc_all|bc_blue;
	sleep 60000;
	announce "Event Manager: Russian Roulette will start in 60 seconds.",bc_all|bc_blue;
	announce "Event Manager: For now we have "+$RRREGISTREDUSER+" registred player.",bc_all|bc_blue;
	sleep 60000;
	set $russianroulette, 0;
	announce "Event Manager: Event starts right now. No more registrations!",bc_all|bc_blue;
	announce "Event Manager: "+$RRREGISTREDUSER+" Players. 1:4 Chance. "+$RRZENYPOT+" Zeny.",bc_all|bc_blue;
	sleep 10000;
	
	set .color$, "0xFFD842";
	query_sql("UPDATE `event_russian_roulette` SET `selected` = 0");

	
	RUNDENBEGINN:
		set .color$, "0xFFD842";
		set .@nb, query_sql("SELECT count(char_id) from `event_russian_roulette` LIMIT 1", .@playersleft);
		if (.@playersleft < 2) goto RRFINISH;
		set .round, .round + 1;
		areaannounce("prontera", 125, 240, 155, 200, "Event Manager: ROUND "+.round+"! START! "+.@playersleft+" PLAYERS LEFT!", bc_area, .color$);
		sleep 2000;
		
			SELECTNEXTPLAYER:
			if (.nextcolor == 1) {
				set .color$, "0xB5DA91";
				set .nextcolor, 0;
			}
			else {
				set .nextcolor, .nextcolor + 1;
				set .color$, "0xB2CAE6";
			}
			set .@nb, query_sql("SELECT count(char_id) from `event_russian_roulette` WHERE selected = 0 LIMIT 1", .playertoselect);
			if (.playertoselect == 0) {
				query_sql("UPDATE `event_russian_roulette` SET `selected` = 0");
				goto RUNDENBEGINN;
			}

			set .nb, query_sql("SELECT `name`,`char_id`,`account_id` from `event_russian_roulette` WHERE selected = 0 ORDER BY RAND() LIMIT 1", .name$, .charid, .accountid);
			query_sql("UPDATE `event_russian_roulette` SET `selected` = 1 WHERE `char_id` = "+.charid+"");
			sleep 1000;
			set .rand, rand(1,5);
			if (.rand == 1) areaannounce("prontera", 125, 240, 155, 200, "Event Manager: Now it's your chance to win or die "+.name$+"!", bc_area, .color$);
			if (.rand == 2) areaannounce("prontera", 125, 240, 155, 200, "Event Manager: May Fortuna be with "+.name$+"!", bc_area, .color$);
			if (.rand == 3) areaannounce("prontera", 125, 240, 155, 200, "Event Manager: Look what I've got here for ya "+.name$+"!", bc_area, .color$);
			if (.rand == 4) areaannounce("prontera", 125, 240, 155, 200, "Event Manager: Pang! Haha~ Don't worry "+.name$+" ... 3 ... 2 ... 1!", bc_area, .color$);
			sleep 1000;
			set .x, 0;
			set .y, 0;
			set .toofar, 0;
			getmapxy(.map$, .x, .y, UNITTYPE_PC, .name$);
			if ((139 - .x) > 20) set .toofar, 1;
			if ((226 - .y) > 20) set .toofar, 1;
			if (.toofar == 1) {
					areaannounce("prontera", 125, 240, 155, 200, "Event Manager: "+.name$+" is too far away. > 20 cells. Dismissed.", bc_area, 0xFF692C);
					query_sql("DELETE FROM event_russian_roulette WHERE char_id = "+.charid+"");
					charcommand("#die "+.name$+"");
			}
			if (charid2rid(.charid) == 0) {
					areaannounce("prontera", 125, 240, 155, 200, "Event Manager: "+.name$+" is offline. Dismissed.", bc_area, 0xFF692C);
					query_sql("DELETE FROM event_russian_roulette WHERE char_id = "+.charid+"");
			}
			else {
			
				specialeffect(538, AREA, .accountid);

				if (rand(1,4) == 4) {
					specialeffect(643, AREA, .accountid);
					specialeffect(372, AREA, .accountid);
					areaannounce("prontera", 125, 240, 155, 200, "Event Manager: "+.name$+" "+.name$+" has been killed! Dismissed.", bc_area, .color$);
					charcommand("#die "+.name$+"");
					query_sql("DELETE FROM event_russian_roulette WHERE char_id = "+.charid+"");
				}
				else {
					specialeffect(639, AREA, .accountid);
					specialeffect(402, AREA, .accountid);
					areaannounce("prontera", 125, 240, 155, 200, "Event Manager: "+.name$+" has survived. No hit.", bc_area, .color$);
					if (rand(1,100) < 11) {
						areaannounce("prontera", 125, 240, 155, 200, "Event Manager: 10%! "+.name$+" has won a Loyality Coin.", bc_area, .color$);
						rodex_sendmail(.charid, "Event Manager", "Loyality Coin - Russian Roulette", "Take this as a parts reward.", 0, 29000, 1);
					}
				}
			}
			set .@nb, query_sql("SELECT count(char_id) from `event_russian_roulette` LIMIT 1", .@playersleft);
			if (.@playersleft < 2) goto RRFINISH;
			sleep 2000;
			goto SELECTNEXTPLAYER;
	
	RRFINISH:
	sleep 5000;
	set .nb, query_sql("SELECT `name`,`char_id`,`account_id` from `event_russian_roulette` ORDER BY RAND() LIMIT 1", .name$, .charid, .accountid);
	announce "Event Manager: Aaaaand the winner is: "+.name$+"! Congratulations!",bc_all|bc_blue;
	announce "Event Manager: "+.name$+" has won "+$RRZENYPOT+" Zeny.",bc_all|bc_blue;
	
	rodex_sendmail(.charid, "Event Manager", "Zeny Russian Roulette", "Take this as your reward.", $RRZENYPOT);

end;

}


You'll need to create following table into your ragnarok database.
 

CREATE TABLE `event_russian_roulette` (
	`unique_id` INT(20) NULL DEFAULT NULL,
	`char_id` INT(11) NULL DEFAULT NULL,
	`account_id` INT(11) NULL DEFAULT NULL,
	`name` VARCHAR(50) NULL DEFAULT NULL,
	`selected` INT(11) NULL DEFAULT NULL
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
;

 

Registration while Event-Start for the players works well with a NPC located in Prontera.

If you wants to relocate this NPC you should also edit the areaannounce (used because of anti chat flooding).

 

prontera,139,226,5	script	Event Manager	4_F_EDEN_OFFICER,{


set [email protected]$,"[^FF8000Event Manager^000000]";

	if ($russianroulette == 1) {
		mes [email protected]$;
		mes "Welcome to the event called Russian Roulette. You can register yourself with a fee of 1.000 Zeny. This Zeny will become the reward of this event. Aditional you can earn 1 Loyality Coin for every survived round.";
		next;
		mes [email protected]$;
		mes "What is your choice?";
		next;
		menu "Register me please.",RRREGISTER,"What to do?",RRINFO,"What to win?",RRREWARD;
		close;
		
		RRINFO:
		mes [email protected]$;
		mes "You have to register yourself within 5 minutes and stay here for a while. After some players have registred we will start the event.";
		next;
		mes [email protected]$;
		mes "I will load a pistole with 1 bullet. We use a pistol with 9 slots. As you can see your chance is 1:4 to survive.";
		next;
		
		RRREWARD:
		mes [email protected]$;
		mes "You can win with a 10% chance a Loyality Coin every round you've survived. If you are the last man standing you can also win the sum of registration zeny.";
		close;
		
		RRREGISTER:
		if ($RRDURCHGANG != getd("$RRDURCHGANG_"+uniqueid$+"")) {
			set RRREGISTRED, 0;
			setd("$RRREGISTRED_"+uniqueid$+"", 0);
		}
		mes [email protected]$;
		mes "Do you want to register you as a event player? It will cost you 1.000 Zeny.";
		next;
		menu "Register",-,"Info?",RRINFO,"Rewards?",RRREWARD;
				
		if (getd("$RRREGISTRED_"+uniqueid$+"") == 1) set RRREGISTRED, 1;
		
		if (RRREGISTRED == 1) {
			mes [email protected]$;
			mes "You are already registred. Please wait until the event starts.";
			close;
		}
		if (Zeny < 1000) {
			mes [email protected]$;
			mes "You don't have enough zeny my dear.";
			close;
		}

		set Zeny, Zeny - 1000;
		dispbottom "You've paid 1.000 Zeny for russian roulette registration.";
		set $RRZENYPOT, $RRZENYPOT + 1000;
		set RRREGISTRED, 1;
		setd("$RRREGISTRED_"+uniqueid$+"", 1);
		setd("$RRDURCHGANG_"+uniqueid$+"", $RRDURCHGANG);
		
		set [email protected], query_sql("INSERT INTO `event_russian_roulette` (`unique_id`, `char_id`, `account_id`, `name`) VALUES ('"+uniqueid$+"', '"+getcharid(CHAR_ID_CHAR)+"', '"+getcharid(CHAR_ID_ACCOUNT)+"', '"+strcharinfo(0)+"');", [email protected]$);
			
		mes [email protected]$;
		mes "You have been registred. Thank you. The current pot belongs "+$RRZENYPOT+" zeny.";
		set [email protected], query_sql("SELECT count(char_id) from `event_russian_roulette` LIMIT 1", $RRREGISTREDUSER);
		npctalk "Thank you for your registration "+strcharinfo(0)+". "+$RRREGISTREDUSER+". player.";
		next;
		mes [email protected]$;
		mes "Now please wait for my announcements. I wish you a lot of luck. The Event will start within the next seconds.";
		close;
	}

mes [email protected]$;
mes "No event is running.";
close;
}

Disable uniqueid if you don't use gepard or harmony.

 

Edited by [email protected]

Share this post


Link to post
Share on other sites

Your welcome.

Instead of #die you could also use a cleaner way:

unitskilluseid .accountid,"NV_TRICKDEAD",1;

But caution, if you decide to use TRICKDEAD instead, you've to save all players on start into an array and do something like this on event finish.

	for ([email protected] = 0; .i < getarraysize([email protected]); [email protected]) {
		unitskilluseid [email protected],"NV_TRICKDEAD",1;
	}

 

My players does love this mini event. I am acting as a gamemaster with the players as well. So they like to see me dying o.O

Share this post


Link to post
Share on other sites

Im using 2013-08-07 client and it doesnt have a Rodex Mail.. how can I use your script with just getitem and not rodex_sendmail?

Share this post


Link to post
Share on other sites

russian roulette ... this is old school .. I've seen this a lot during eathena days xO

a few things that I like to point out

1. try use queue iterator script commands instead of needlessly using SQL table

2. instead of using areaannounce, try use announce with bc_npc flag

 

oh ... I miss this one ...

setd("$RRREGISTRED_"+uniqueid$+"", 0)

this is bad ... really bad scripting practice ...

never ever misuse the global permanent server variable, this can potentially kill your server

like in this case, if enough players are playing this game using this script, in time your server will start to hang up

Share this post


Link to post
Share on other sites
On 26.3.2018 at 4:54 PM, Rebel said:

Im using 2013-08-07 client and it doesnt have a Rodex Mail.. how can I use your script with just getitem and not rodex_sendmail?

Just try to replace "rodex_sendmail" with

 

						attachrid([email protected]);
						Zeny = Zeny + $RRZENYPOT;
						announce "Event Manager: This is your reward. You've won "+$RRZENYPOT+" zeny. Gz.",bc_self,0x00FF00;
						detachrid();

 

Share this post


Link to post
Share on other sites
On 4.4.2018 at 10:13 AM, AnnieRuru said:

this is bad ... really bad scripting practice ...

Could you please explain me the " queue iterator script commands" a bit further please?

 

Quote
setd("$RRREGISTRED_"+uniqueid$+"", 0)

Any good alternative exept a event sql file?

Share this post


Link to post
Share on other sites
9 hours ago, Christian [epicRO] said:

Just try to replace "rodex_sendmail" with

 

						attachrid([email protected]);
						Zeny = Zeny + $RRZENYPOT;
						announce "Event Manager: This is your reward. You've won "+$RRZENYPOT+" zeny. Gz.",bc_self,0x00FF00;
						detachrid();

 

Attaching is no needed. Try this one instead:

getitem(604, 1, [email protected]);

604 = Some Item ID

Share this post


Link to post
Share on other sites

Got this error when registering a player..
 

[SQL]: DB error - Incorrect integer value: '' for column 'unique_id' at row 1
[Debug]: at script.c:17447 - INSERT INTO `event_russian_roulette` (`unique_id`, `char_id`, `account_id`, `name`) VALUES ('', '150000', '2000001', 'Ragnarok');

Im using Gepard Shield 2.0

Share this post


Link to post
Share on other sites
[SQL]: DB error - Incorrect integer value: '' for column 'unique_id' at row 1

 

So you don't have gepard and uniqueid$ Transfer. Just remove

`unique_id`

 from table and change the insert statement.
 

		set [email protected], query_sql("INSERT INTO `event_russian_roulette` (`char_id`, `account_id`, `name`) VALUES ('"+getcharid(CHAR_ID_CHAR)+"', '"+getcharid(CHAR_ID_ACCOUNT)+"', '"+strcharinfo(0)+"');", [email protected]$);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0