Jump to content

Question

Posted

Almost all my scripts are self-made but I've been having trouble making this. I would greatly appreciate it if someone can be able to make an NPC that has the following functions:

 

- NPC will accept 1 ticket for 1 entry (with multiple ticket/entry function)

- Record the character name for the entry (via variable or SQL)

- Randomly pick a winner at the end of every week (with global broadcast)

- Reset all entries 1 day after the NPC picks a winner

 

That's pretty much it. I'm still in the learning process of scripting so can someone please make one for me and sorta explain the functions of how the codes work. 

Thank you!

7 answers to this question

Recommended Posts

Posted

Try this uggly npc

/*
CREATE TABLE IF NOT EXISTS `random` (
  `char_id` int(11) unsigned NOT NULL DEFAULT '0',
  `name` varchar(30) NOT NULL default '',
  `tickets` int(11) unsigned NOT NULL DEFAULT '0',
  `mytickets` int(11) unsigned NOT NULL DEFAULT '0',
  `leader` tinyint(3) unsigned NOT NULL default '0',
  KEY `char_id` (`char_id`)
) ENGINE=MyISAM;
*/

prontera,150,150,5	script	junon	87,{
	.@ticket_id = 501;	// ticket ID
	setarray .@item[0], 501,1;	// reward

	if ( .winner$ == "" ) {
		query_sql( "select ( select mytickets from random where char_id = "+ getcharid(0) +" ),"+
			"( select tickets from random where char_id = "+ getcharid(0) +" ), max( tickets ) from random", .@my_tickets, .@tickets, .@total );
		mes "you bet "+ .@my_tickets +" ticket on a total of "+ .@total +" tickets.";
		mes "now how many tickets do you want to bet ?";
		input .@amount;
		if ( .@amount == 0 )
			close;
		next;
		if ( countitem( .@ticket_id ) < .@amount ) {
			mes "you don't have enough ticket";
			close;
		}
		mes "you will bet "+ .@amount +" ticket. Is that ok?";
		next;
		if ( select( "quit", "It's ok" ) == 1 )
			close;
		mes "Alright good luck !";
		delitem .@ticket_id, .@amount;
		if ( .@my_tickets == 0 )
			query_sql "insert into random select "+ getcharid(0) +", '"+ escape_sql( strcharinfo(0) ) +"', ( COALESCE( max( tickets ),0 ) + "+ .@amount +" ), "+ .@amount +", 0 from random";
		else {
			query_sql "update random set tickets = tickets + "+ .@amount +" where tickets >= "+ .@tickets;
			query_sql "update random set mytickets = mytickets + "+ .@amount +" where char_id = "+ getcharid(0);
		}
	}
	else {
		if ( .winner$ == strcharinfo(0) ) {
			mes "congrat you win";
			if ( .winner == 1 ) {
				getitem .@item[0], .@item[1];
				query_sql "update random set leader = 2 where char_id = "+ getcharid(0);
				.winner = 2;
			}
		}
		else
			mes "the winner is "+ .winner$;
	}
	close;
// OnInit:
OnSun0000:
	query_sql "select max( tickets ) from random", .@max;
	query_sql "update random set leader = 1 where tickets <= ( rand() * "+ .@max +" ) order by tickets desc limit 1";// little trick with tickets column to select a random char following the tickets weight
	query_sql "select name, leader from random where leader > 0 limit 1", .winner$, .winner;
	end;
OnMon0000:
	query_sql "truncate table random";
	.winner$ = "";
	.winner = 0;
	end;
}

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...