Lil Troll

Utility : Promotional Code

Recommended Posts

Special credits to: Sir Patskie, Sir Arrzzae

Work best with "ITEM BOUND PRIZE"

Because I found my self the script is going to be very useful for everybody, I tweak this script.

If this kind of doing in rathena is illegal please delete this post.

 

////////////////////////////////////////////////////////////////////////
//--------------------------------------------------------------------//
//                          PROMOTIONAL CODES                         //
//                     AUTHOR: LIL TROLL//COLDFIRE                    //
//--------------------------------------------------------------------//
//                          RATHENA SCRIPT                            //
//--------------------------------------------------------------------//
//                                                                    //
//--------------------------------------------------------------------//
//    FEATURES: (Modified Promotional Code by sir Patskie)            //
//   								      //
// #1 5`Degree of Abuse-Protection(+ItemBound = 6)		      //
//    - IP,ACCOUNT,COUNTLIMIT,DOUBLECHECK,MIX			      //
// #2 Code can be deleted/detected by gm.			      //
// #3 Friendly User Interface.					      //
// #4 Very easy to configure.					      //
// #5 Code auto delete at certain variable setup(limit pool).	      //
// #6 GM can view codes when claiming.				      //
// #7 GM can set limitation of usage of the codes.		      //
// #8 Automatically delete any codes that set to desirable 	      //
//    pool limit by gm claimed by players.			      //
// #9 GM can set random code with random item! 		      //
// #10 GM toggle(when claiming the code, restriction) included.       //
//--------------------------------------------------------------------//
////////////////////////////////////////////////////////////////////////

​[spoiler=From topic:]http://rathena.org/board/topic/86986-promotionial-codes-script/

 

[spoiler=Tweak parts:]I tweaked Promotional Code script:
#1 Improve how code can be deleted/detected by gm.
#2 Improve Interface(Now more easier to delete config, etc.)
#3 Dialogues fix.
#4 Knows accurately if a code exist when creating new one.
#5 GM can view codes when claiming.
See features above for full information regarding the script.


[spoiler=I modify the script below:]/*
DROP TABLE IF EXISTS `reward_codes`;
CREATE TABLE IF NOT EXISTS `reward_codes` (
`code` VARCHAR(10) NOT NULL DEFAULT '',
`nameid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`item_name` VARCHAR(45) NOT NULL DEFAULT '',
`amount` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',
`time_created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
PRIMARY KEY (`code`)
) ENGINE = MYISAM;

DROP TABLE IF EXISTS `rewardlogs`;
CREATE TABLE `rewardlogs` (
`account_id` INT( 10 ) NOT NULL,
`code` VARCHAR( 10 ) NOT NULL,
`redeem_time` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE = MyISAM;
*/


- script promoclaim -1,{


OnInit:
bindatcmd "claim",strnpcinfo(3)+"::OnClaim";
bindatcmd "code",strnpcinfo(3)+"::OnEditCode";
end;

OnClaim:
// if ( getgmlevel() ) end;
mes "^FF0000 Enter a new promotional code.";
input [email protected]$;
close2;

query_sql "SELECT `nameid`, `amount` FROM `reward_codes` WHERE `code` = '" + escape_sql([email protected]$) + "'", [email protected], [email protected];

if ( [email protected] )
dispbottom "Either invalid code or the code is already claimed by other people";
else {
getitem [email protected], [email protected];
dispbottom "Promotional code successfully redeemed.";
query_sql "DELETE FROM `reward_codes` WHERE `code` = '" + escape_sql([email protected]$) + "'";
query_logsql "INSERT INTO `rewardlogs` VALUES ( '" + getcharid(3) + "', '" + escape_sql([email protected]$) + "', NOW() )";
}

end;

OnEditCode:
if ( getgmlevel() < 99 ) end;
set [email protected]$, "Setup a new promotional code:View existing codes:Delete exisiting codes:Cancel";
setarray [email protected], 4,10; // ,

switch ( select( [email protected]$ ) ) {
case 1:
input [email protected]$;
if ( getstrlen( [email protected]$ ) < [email protected][0] || getstrlen( [email protected]$ ) > [email protected][1] ) {
dispbottom "Codes must not be less than " [email protected][0]+ " and must be greater than " [email protected][1]+ ".";
end;
}
mes "You have entered ^FF0000"[email protected]$+"^000000 as the code.";
mes "Are you sure?";
if ( select("Yes:No, thanks") - 1 ) end;
query_sql "SELECT `code` FROM `reward_codes` WHERE `code` = '" + escape_sql([email protected]$) + "'", [email protected]_exists;
if ( [email protected]_exists ) {
dispbottom "Sorry, that code already exist.";
end;
}
mes "Please set a reward for the players who has entered the code.";
input [email protected];
next;
if ( [email protected] || getitemname([email protected]) == "null" ) {
dispbottom "Sorry, that is an invalid item id.";
end;
}
set [email protected]$, getitemname([email protected]);
mes "Item number ^FF0000"[email protected]+"^000000";
mes "is equivalent to ^FF0000"[email protected]$+"^000000.";
mes "Are you sure?";
next;
if ( select("Yes:No, thanks") - 1 ) end;
mes "How many ^FF0000"[email protected]$+"^000000.?";
input [email protected];
next;
if ( [email protected] ) {
dispbottom "Sorry, that is an invalid amount number.";
end;
}
mes "Are you sure?";
next;
if ( select("Yes:No, thanks") - 1 ) end;
query_sql "INSERT INTO `reward_codes` VALUES ( '" + escape_sql([email protected]$) + "', '" + [email protected] + "', '" + escape_sql([email protected]$) + "', '" + [email protected] + "', NOW() )";
dispbottom "Done creating code!";
break;
case 2:
set [email protected], query_sql("SELECT code, item_name, amount FROM `reward_codes` ORDER BY time_created DESC LIMIT 20", [email protected]$, [email protected]$, [email protected]);
if ( [email protected] ) {
dispbottom "No exisiting codes.";
end;
}
dispbottom "=============================================";
dispbottom "============== EXISITING CODES ==============";
dispbottom "=============================================";
for(set [email protected],0; [email protected] < [email protected]; set [email protected],[email protected]+1)
dispbottom ""[email protected]$[[email protected]]+" ( Reward: "[email protected][[email protected]]+" "[email protected]$[[email protected]]+" ) ";
dispbottom "=============================================";
break;
case 3:
input [email protected]$;
query_sql "SELECT `code` FROM `reward_codes` WHERE `code` = '" + escape_sql([email protected]$) + "'", [email protected]_exists;
if ( [email protected]_exists ) {
dispbottom "Promotional code not found.";
end;
}
mes "Would you like to delete that code?";
next;
if ( select("Yes:No, thanks") - 1 ) end;
query_sql "DELETE FROM `reward_codes` WHERE `code` = '" + escape_sql([email protected]$) + "'";
break;
case 4: close; break;
default: break;
}
end;
}


[spoiler=To do:]- NPC Configurations, like only generate code, not others like items,amount,limit. + Code length configuration for random generation.(Done but I wont release it yet.)

Figuring out how to autopaste the code from your text box! (If its possible)

Figuring out how to claim using "@claim <insertcodehere>"  

Adding promotional code referal_system. 

Adding gm can mail codes.

Player can main codes also.

Adding lots of stuff if i think of new idea.  :D


[spoiler=Screenie:]I know I can do better than this but am really tired atm..
dGYS8jy.png
wpOw8RI.jpg


[spoiler=Change logs:]v.1:
Initial release.
v.1.2:
Re-write and improve totally the whole script! Added only generate code.

v.1.2.1:

Uploaded a quick fix, credits to shadowolf and ude for pinpointing some bugs from post #23,#25.

v.1.2.2:

Improved delete function, change "OnInit" setup vars "[email protected]" to ".", added GM Toggle in setup(claim restriction), improved few dialogues.

v.1.2.3:

Fix case detection problem on queries. All codes(random,manually generated,claim) will be automatically converted to uppercase.

 

[spoiler=Special notes:][spoiler=The setup:]Just dont forget to fix your settings found on OnInit, at the meantime, I wont release the rand code generator that I used in the script, because it might cause some error on your server, the generator here can only produce 10 strings, and used a basic formula on it. If you wanted to make more than 10strings just add this one

"[email protected]$[rand(0,35)]+" its very easy! Dont forget to add the sql-thingy!

[spoiler=Script is SQL based:]The script variable usage is in SQL(Almost all).

 

Please help me improve this script. If you found bugs or errors please pinpoint it to me so that I can actually fix that fast. Before releasing it to your server, please configure it right and check out what this script does. Please do suggest improvements, additional features, etc. to make the script more diverse and fresh. Also if you knew a way how to do my To Do List, can you help me on that part?(Grab form other post, very very lazy XD.)
 
A little thanks or appreciation of my work will pump-up my motivation to much improve the whole script. Thanks and have fun using the script!

 

****** I made this script using this svn(http://sourceforge.net/p/rathena/svn/17482/). ******

For those who are using older svn and having an error regarding close button not appearing properly just change where the line part where error appears  "end;" to "close;"

 

Smexy update will be finish soon! :)

[spoiler=Update(WIP) Screenie:]BDebrcD.png

Mailing of Code enabled.
Referral system:
-GM can set pool count of referral.
-GM can set prize for every refered new player. 
-Cannot refer player with same IP/Account.
-Changes @claim to @promo:
 Promo Menu:
 - Claim Codes - Refered by friend, Claim Reward.
 - Refer - Referring Menu(will appear when you pick refer over claim).
Easy Deletion of all code.
Random Auto Generate of code now support 5-15 chars.
Added Referral Ladder.

P.S. Hope I do have enough time to finish this fast, lots of work to do. :(

 

New to do list added. Hope someone can help me. :)
promotional_codes_v.1.2.txt

promotional_codes_v.1.2.1.txt

promotional_codes_v.1.2.2.txt

promo_codes_v.1.2.3.txt

Edited by Lil Troll
  • Upvote 1

Share this post


Link to post
Share on other sites
[06/Sep 12:17][SQL]: DB error - Unknown column 'promo' in 'field list'
[06/Sep 12:17][Debug]: at script.c:14668 - SELECT `promo`,`pool` FROM `reward_codes` ORDER BY time_created DESC LIMIT 20
[06/Sep 12:17][Debug]: Source (NPC): liltrollcodes (invisible/not on a map)

1. That happened when I use @code. Yes, I'm using your sql query.

 

reward_code query at my localhost > db and rewardlogs query at localhost > log

 

#1 Problem fixed : http://rathena.org/board/topic/87212-utility-promotional-code/#entry221607

 

2. No close button

 

Q9fcMYX.jpg

 

i9sVbug.jpg

 

Somehow you're missing close button at almost every mes.. Please fix it.. Thanks

 

3. Same ID/IP can redeem the same code more than 1 time.

 

rpQQHiP.jpg

 

4. rewardlogs sql not working?

 

2qQkfDJ.jpg

I've redeem twice, and nothing was stored at this log..

 

#4 Problem fixed : My mistake, I should install both sql under database.

Edited by uDe

Share this post


Link to post
Share on other sites

Sorry i forgot to update sql query.

 

heres the new one.

 

DROP TABLE IF EXISTS `reward_codes`;
DROP TABLE IF EXISTS `rewardlogs`;
CREATE TABLE IF NOT EXISTS `reward_codes` (
    `promo` VARCHAR(10) NOT NULL DEFAULT '',
    `nameid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
    `item_name` VARCHAR(45) NOT NULL DEFAULT '',
    `amount` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',
    `time_created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
    `limit` INT(11) UNSIGNED NOT NULL DEFAULT '0',
    `pool` INT(11) UNSIGNED NOT NULL DEFAULT '0',
    PRIMARY KEY (`promo`)
) ENGINE = MYISAM;
CREATE TABLE `rewardlogs` (
    `account_id` int(11) unsigned NOT NULL default '0',
    `last_ip` BINARY( 9 ) NOT NULL,
    `code` VARCHAR( 10 ) NOT NULL,
    `redeem_time` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
    `claim` INT( 10 )
) ENGINE = MYISAM;

I update the download remove the old one, forgot to paste the updated query, my mistake. Tell me if there is something wrong, on my offline server it working fine.

Edited by Lil Troll

Share this post


Link to post
Share on other sites

I am using the lastest svn.

 

#Prob 2: I wonder why close button doesnt appear on you. Im gonna make a special script for you no switch select i think that causing you no

close button problem gona change all of that to menu. 

 

#Prob 3 && Prob 4: Its working fine on me, i think must fix ur sql first.

 

What error in Map Server appears?

Edited by Lil Troll

Share this post


Link to post
Share on other sites

I am using the lastest svn.

 

#Prob 2: I wonder why close button doesnt appear on you. Im gonna make a special script for you no switch select i think that causing you no

close button problem gona change all of that to menu. 

 

#Prob 3 && Prob 4: Its working fine on me, i think must fix ur sql first.

 

What error in Map Server appears?

 

SQL was fixed. But problems #2 and #3 still occur. Post above has been updated.

Share this post


Link to post
Share on other sites

Im making new menus and upload the updated after so that close bug wont be happening in older version, i really dont know what causing you the problem of same ip can be claimed. Do you see any mapserver errors?

Share this post


Link to post
Share on other sites

Im making new menus and upload the updated after so that close bug wont be happening in older version, i really dont know what causing you the problem of same ip can be claimed. Do you see any mapserver errors?

 

Thanks for the close button, and no error found on map-server while redeem the codes more than one.

 

ln9vUya.jpg

 

reward_codes :

 

jH1izHA.jpg

Edited by uDe

Share this post


Link to post
Share on other sites

Im making new menus and upload the updated after so that close bug wont be happening in older version, i really dont know what causing you the problem of same ip can be claimed. Do you see any mapserver errors?

 

Thanks for the close button, and no error found on map-server while redeem the codes more than one.

 

ln9vUya.jpg

 

reward_codes :

 

jH1izHA.jpg

 

I really dont see any problem inside the script and in my test server, anyways gonna re-write the whole script so that older version can use this. gonna msg u after im done. :)

Share this post


Link to post
Share on other sites

I really dont see any problem inside the script and in my test server, anyways gonna re-write the whole script so that older version can use this. gonna msg u after im done. :)

 

Sorry for making this harder.. It's also hard for me to update new svn.. Thanks for your efforts..

Share this post


Link to post
Share on other sites

I really dont see any problem inside the script and in my test server, anyways gonna re-write the whole script so that older version can use this. gonna msg u after im done. :)

 

Sorry for making this harder.. It's also hard for me to update new svn.. Thanks for your efforts..

I forgot to mention, GM can claim rewards without restrictions. Anyways adding more improvement to the script. I think i can finish this less than hour. :)

Share this post


Link to post
Share on other sites

Smexy update will be finished soon:

Mailing of Code enabled.
Referral system:
-GM can set pool count of referral.
-GM can set prize for every refered new player. 
-Cannot refer player with same IP/Account.
-Changes @claim menu:
 - Refered by friend, Claim Codes
Easy Deletion of all code.
Random Auto Generate of code now support 5-15 chars.
Added Referral Ladder.

Share this post


Link to post
Share on other sites

bro the .txt file is all messed up. no word warp :( can you please re up this?

Try using Notepad++ or Enpc,NpcMaker. :)

Share this post


Link to post
Share on other sites

Look interesting...

But can tell me how this script works?..?

And did it have npc to click on it to setting or auto?..?

Share this post


Link to post
Share on other sites

Look interesting...

But can tell me how this script works?..?

And did it have npc to click on it to setting or auto?..?

 

It has been explained on first topic. Please click the spoilers.

Share this post


Link to post
Share on other sites

Update(WIP):

BDebrcD.png

 

Mailing of Code enabled.
Referral system:
-GM can set pool count of referral.
-GM can set prize for every refered new player. 
-Cannot refer player with same IP/Account.
-Changes @claim to @promo:
 Promo Menu:
 - Claim Codes - Refered by friend, Claim Reward.
 - Refer - Referring Menu(will appear when you pick refer over claim).
Easy Deletion of all code.
Random Auto Generate of code now support 5-15 chars.
Added Referral Ladder.

Share this post


Link to post
Share on other sites

Hi,

 

bug report.

 

Sample you generate a code : welcome123

them if player get it already, then someone "player"  type : WELCOME123 players can spam it.\

 

or

 

Welcome123 - uppercase W   it will spam code.

Edited by shatowolf

Share this post


Link to post
Share on other sites

Hi,

 

bug report.

 

Sample you generate a code : welcome123

them if player get it already, then someone "player"  type : WELCOME123 players can spam it.\

 

or

 

Welcome123 - uppercase W   it will spam code.

 

Did you put these queries?

DROP TABLE IF EXISTS `reward_codes`;
DROP TABLE IF EXISTS `reward_logs`;
CREATE TABLE IF NOT EXISTS `reward_codes` (
	`promo` VARCHAR(26) NOT NULL DEFAULT '',
	`nameid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
	`item_name` VARCHAR(50) NOT NULL DEFAULT '',
	`amount` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',
	`time_created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
	`limit` INT(10) UNSIGNED NOT NULL DEFAULT '0',
	`pool` INT(10) UNSIGNED NOT NULL DEFAULT '0',
	PRIMARY KEY (`promo`)
) ENGINE = MYISAM;
CREATE TABLE `reward_logs` (
  `code` VARCHAR( 26 ) NOT NULL DEFAULT '',
	`account_id` int(11) unsigned NOT NULL default '0',
	`last_ip` BINARY( 9 ) NOT NULL DEFAULT '',
  `name` VARCHAR( 26 ) NOT NULL DEFAULT '',
	`redeem_time` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
	`claim` INT( 10 ) NOT NULL default '0',
	PRIMARY KEY (`code`)
) ENGINE = MYISAM;
Edited by Lil Troll

Share this post


Link to post
Share on other sites

Hi,

 

bug report.

 

Sample you generate a code : welcome123

them if player get it already, then someone "player"  type : WELCOME123 players can spam it.\

 

or

 

Welcome123 - uppercase W   it will spam code.

 

Same here..

 

Did you put these queries?

DROP TABLE IF EXISTS `reward_codes`;
DROP TABLE IF EXISTS `reward_logs`;
CREATE TABLE IF NOT EXISTS `reward_codes` (
	`promo` VARCHAR(26) NOT NULL DEFAULT '',
	`nameid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
	`item_name` VARCHAR(50) NOT NULL DEFAULT '',
	`amount` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',
	`time_created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
	`limit` INT(10) UNSIGNED NOT NULL DEFAULT '0',
	`pool` INT(10) UNSIGNED NOT NULL DEFAULT '0',
	PRIMARY KEY (`promo`)
) ENGINE = MYISAM;
CREATE TABLE `reward_logs` (
  `code` VARCHAR( 26 ) NOT NULL DEFAULT '',
	`account_id` int(11) unsigned NOT NULL default '0',
	`last_ip` BINARY( 9 ) NOT NULL DEFAULT '',
  `name` VARCHAR( 26 ) NOT NULL DEFAULT '',
	`redeem_time` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
	`claim` INT( 10 ) NOT NULL default '0',
	PRIMARY KEY (`code`)
) ENGINE = MYISAM;

 

Yes. And I'm using v1.2..

 

Still have problem with close button

 

mRl97Ml.jpg

 

It's happened when I click View Codes. But when there's codes to view, it has close button. If no codes. There will be no close button.

Share this post


Link to post
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
Reply to this topic...

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

Loading...