Jump to content
  • 0

Lucky Pick Event


Mice

Question


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  78
  • Reputation:   19
  • Joined:  12/24/18
  • Last Seen:  

Please help me with how to do this: select 5 random online players no repeat, and before they are chosen, the script should check the SQL table event_pick to ensure that the qualified field has a value of 1 for them to be eligible for the event.

heres my event_pick database

CREATE TABLE  `event_pick` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `char_id` int(11) NOT NULL,
  `qualified` int(11) NOT NULL default '0',
  PRIMARY KEY  USING BTREE (`id`),
  UNIQUE KEY `char_id` (`char_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;

 

And here's the script from the forum that I want to be modified.

byako,83,154,4	script	Who's Online Event	99,{
	mes "[Who's Online Event]";
	if (getgroupid() < 99) {
		mes "Only GM's are allowed to use this NPC.";
	}
	else {
		mes "Enable event?";
		if (select("Yes", "No") == 1) {
			mes "Event started.";
			donpcevent strnpcinfo(3)+"::OnStart";
		}
	}
	close;
	
	OnHour00:
	OnHour03:
	OnHour06:
	OnHour09:
	OnHour12:
	OnHour15:
	OnHour18:
	OnHour21:
	OnStart:
		do {
			query_sql "select `account_id`, `name` from `char` where online = 1 order by rand() limit 1", .@aid, .@name$;
			attachrid .@aid;
		} while (checkvending() || getgroupid() >= 2 || inarray(.map$, strcharinfo(3)) == -1);
		announce strcharinfo(0) +" won 1 Lucky Pick Box in Exiled Lucky Pick", bc_all, 0x00FF00;
		getitem 50043,1;
		end;
		
	OnInit:
		setarray .map$, "prontera", "izlude", "payon";
		end;
}

 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  212
  • Reputation:   94
  • Joined:  06/02/12
  • Last Seen:  

Hi. You can use INNER JOIN in the sql query to make the event check for your event_pick database. Example:

	.@sql$ = "SELECT `char`.`char_id`, `name`"
		 + " FROM `char`"
		 + " INNER JOIN `event_pick`"
		 + " ON `char`.`char_id` = `event_pick`.`char_id`"
		 + " WHERE `char`.`online` = 1"
		 + " AND `event_pick`.`qualified` = 1"
		 + " ORDER BY RAND()";
	query_sql .@sql$, .@cid, .@name$;

(Multiple lines not necessary. It's just for better readability.)

 

byako,83,154,4	script	Who's Online Event	99,{
	mes "[Who's Online Event]";
	if (getgroupid() < 99) {
		mes "Greetings! I see you're curious about our ^0000FFWho's Online Event^000000. Allow me to explain how it works.";
		next;
		mes "[Who's Online Event]";
		mes "Every three hours I will select " + .winners + " random adventurers in the cities of Midgard to receive " + .prize_amt + " " + mesitemlink(.prize_id) + ". Only VIPs are eligible for the event.";
		close;
	}
	else {
		mes "Enable event?";
		if (.winners_date$ != "") {
			mes " ", "^EE8800Winners " + .winners_date$ + "^000000";
			for (.@i = 0; .@i < getarraysize(.winners_cid); .@i++)
				mes "- ^0000FF" + .winners_name$[.@i] + "^000000";
		}
		if (select("Yes", "No") == 1) {
			mes "Event started.";
			donpcevent strnpcinfo(3) + "::OnStart";
		}
	}
	close;
	
OnHour00:
OnHour03:
OnHour06:
OnHour09:
OnHour12:
OnHour15:
OnHour18:
OnHour21:
OnStart:
	.winners_date$ = "";
	deletearray .winners_cid[0];
	deletearray .winners_name$[0];
	.@sql$ = "SELECT `char`.`char_id`, `name`"
		 + " FROM `char`"
		 + " INNER JOIN `event_pick`"
		 + " ON `char`.`char_id` = `event_pick`.`char_id`"
		 + " WHERE `char`.`online` = 1"
		 + " AND `event_pick`.`qualified` = 1"
		 + " ORDER BY RAND()";
	query_sql .@sql$, .@cid, .@name$;
	for (.@i = 0; .@i < getarraysize(.@cid); .@i++) {
		if (!checkvending(.@name$[.@i]) &&
			getgroupid(.@cid[.@i]) >= 2 &&
			inarray(.map$, strcharinfo(3,.@cid[.@i])) > -1) {
			setarray .winners_cid[.@i2], .@cid[.@i];
			setarray .winners_name$[.@i2], .@name$[.@i];
			.@i2++;
			if (getarraysize(.winners_cid) >= .winners)
				break;
		}
	}
	.winners_date$ = gettimestr("%Y/%m/%d %H:%M",21);
	if (getarraysize(.winners_cid) == 0) {
		announce "There were no eligible adventurers for the Exiled Lucky Pick.", bc_all, 0x00FF00;
		end;
	}
	.@size = getarraysize(.winners_cid);
	for (.@i = 0; .@i < .@size; .@i++) {
		.@text$ += .winners_name$[.@i];
		if (.@size > 1) {
			if ((.@i + 2) == .@size)
				.@text$ += " and ";
			else if ((.@i + 1) < .@size)
				.@text$ += ", ";
		}	
		getitem .prize_id, .prize_amt, convertpcinfo(.winners_cid[.@i],CPC_ACCOUNT);
		dispbottom "You won " + .prize_amt + " " + itemlink(.prize_id) + " in Exiled Lucky Pick!", 0x000000, .winners_cid[.@i];
	}
	announce .@text$ + " won " + .prize_amt + " " + itemlink(.prize_id) + " in Exiled Lucky Pick!", bc_all, 0x00FF00;
	end;
		
OnInit:
	setarray .map$, "prontera", "izlude", "payon";
	.prize_id = 50043; //50043
	.prize_amt = 1;
	.winners = 5;
	end;
}

 

  • Upvote 2
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  78
  • Reputation:   19
  • Joined:  12/24/18
  • Last Seen:  

1 hour ago, Racaae said:

Hi. You can use INNER JOIN in the sql query to make the event check for your event_pick database. Example:

	.@sql$ = "SELECT `char`.`char_id`, `name`"
		 + " FROM `char`"
		 + " INNER JOIN `event_pick`"
		 + " ON `char`.`char_id` = `event_pick`.`char_id`"
		 + " WHERE `char`.`online` = 1"
		 + " AND `event_pick`.`qualified` = 1"
		 + " ORDER BY RAND()";
	query_sql .@sql$, .@cid, .@name$;

(Multiple lines not necessary. It's just for better readability.)

 

byako,83,154,4	script	Who's Online Event	99,{
	mes "[Who's Online Event]";
	if (getgroupid() < 99) {
		mes "Greetings! I see you're curious about our ^0000FFWho's Online Event^000000. Allow me to explain how it works.";
		next;
		mes "[Who's Online Event]";
		mes "Every three hours I will select " + .winners + " random adventurers in the cities of Midgard to receive " + .prize_amt + " " + mesitemlink(.prize_id) + ". Only VIPs are eligible for the event.";
		close;
	}
	else {
		mes "Enable event?";
		if (.winners_date$ != "") {
			mes " ", "^EE8800Winners " + .winners_date$ + "^000000";
			for (.@i = 0; .@i < getarraysize(.winners_cid); .@i++)
				mes "- ^0000FF" + .winners_name$[.@i] + "^000000";
		}
		if (select("Yes", "No") == 1) {
			mes "Event started.";
			donpcevent strnpcinfo(3) + "::OnStart";
		}
	}
	close;
	
OnHour00:
OnHour03:
OnHour06:
OnHour09:
OnHour12:
OnHour15:
OnHour18:
OnHour21:
OnStart:
	.winners_date$ = "";
	deletearray .winners_cid[0];
	deletearray .winners_name$[0];
	.@sql$ = "SELECT `char`.`char_id`, `name`"
		 + " FROM `char`"
		 + " INNER JOIN `event_pick`"
		 + " ON `char`.`char_id` = `event_pick`.`char_id`"
		 + " WHERE `char`.`online` = 1"
		 + " AND `event_pick`.`qualified` = 1"
		 + " ORDER BY RAND()";
	query_sql .@sql$, .@cid, .@name$;
	for (.@i = 0; .@i < getarraysize(.@cid); .@i++) {
		if (!checkvending(.@name$[.@i]) &&
			getgroupid(.@cid[.@i]) >= 2 &&
			inarray(.map$, strcharinfo(3,.@cid[.@i])) > -1) {
			setarray .winners_cid[.@i2], .@cid[.@i];
			setarray .winners_name$[.@i2], .@name$[.@i];
			.@i2++;
			if (getarraysize(.winners_cid) >= .winners)
				break;
		}
	}
	.winners_date$ = gettimestr("%Y/%m/%d %H:%M",21);
	if (getarraysize(.winners_cid) == 0) {
		announce "There were no eligible adventurers for the Exiled Lucky Pick.", bc_all, 0x00FF00;
		end;
	}
	.@size = getarraysize(.winners_cid);
	for (.@i = 0; .@i < .@size; .@i++) {
		.@text$ += .winners_name$[.@i];
		if (.@size > 1) {
			if ((.@i + 2) == .@size)
				.@text$ += " and ";
			else if ((.@i + 1) < .@size)
				.@text$ += ", ";
		}	
		getitem .prize_id, .prize_amt, convertpcinfo(.winners_cid[.@i],CPC_ACCOUNT);
		dispbottom "You won " + .prize_amt + " " + itemlink(.prize_id) + " in Exiled Lucky Pick!", 0x000000, .winners_cid[.@i];
	}
	announce .@text$ + " won " + .prize_amt + " " + itemlink(.prize_id) + " in Exiled Lucky Pick!", bc_all, 0x00FF00;
	end;
		
OnInit:
	setarray .map$, "prontera", "izlude", "payon";
	.prize_id = 50043; //50043
	.prize_amt = 1;
	.winners = 5;
	end;
}

 

 

Thank you very much, you understood what I wanted to achieve. I tried using SELECT COUNT(*) and the temporary table query INSERT INTO temp_selected_players (char_id) VALUES (" + .@char_id + "); it worked okay, but your logic is better. Many thanks!

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  6
  • Reputation:   0
  • Joined:  07/20/24
  • Last Seen:  

I really like this script, can you provide the full script? 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...