Jump to content
  • 0

Weekly Raffle NPC


Pseudo

Question


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  36
  • Reputation:   5
  • Joined:  05/02/15
  • Last Seen:  

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!

Link to comment
Share on other sites

7 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  36
  • Reputation:   5
  • Joined:  05/02/15
  • Last Seen:  

Free coffee for someone who can make this?

Bump* :P

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  36
  • Reputation:   5
  • Joined:  05/02/15
  • Last Seen:  

Anyone?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  51
  • Topics Per Day:  0.01
  • Content Count:  452
  • Reputation:   33
  • Joined:  12/18/14
  • Last Seen:  

This seems to be a good one, should put stuff to not make it abusable. +1 for this, hope someone can help :)

Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

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;
}
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  51
  • Topics Per Day:  0.01
  • Content Count:  452
  • Reputation:   33
  • Joined:  12/18/14
  • Last Seen:  

Thanks sir, just a question, how does this work? If I only submit one ticket, that means I have a lower chance of winning correct?

Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

Yes it's correct. The winner get the prize sunday then the table is truncated monday 00:00

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  36
  • Reputation:   5
  • Joined:  05/02/15
  • Last Seen:  

Sorry. I completely forgot about this topic. I'll try it and get back to you.

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