//===== Custom Script ========================================
//= Promotional Codes
//===== By: ==================================================
//= Arzzzae
//= Rewritten by Peopleperson49 @ version 1.1.
//===== Current Version: =====================================
//= 1.8
//===== Compatible With: =====================================
//= Latest svn
//===== Description: =========================================
//= Allows GM's to setup promocodes ingame for players.
//===== Additional Comments: =================================
//= 1.0 Initial Release by Arzzzae.
//= 1.1 Modified it to allow any length code.
//= 1.2 Added option to choose whether its works any multiple
//= accounts or one time use only. Added allow_multiple
//= column to reward_codes table.
//= 1.3 Added option to generate random 10 character/number
//= code.
//= 1.4 Changed the bindatcmd command to @promocode instead of
//= @claim and @codesetup instead of @code.
//= 1.5 Cleaned up the menus to flow better and eliminate
//= unnessary text.
//= 1.6 Change a lot of the dispbottom to mes.
//= 1.7 Added whether the code allows multiple to the view
//= existing promocodes.
//= 1.8 Added sql tables to bottom of document.
//============================================================
- script promoclaim -1,{
OnInit:
bindatcmd "promocode",strnpcinfo(3)+"::OnClaim";
bindatcmd "codesetup",strnpcinfo(3)+"::OnEditCode",99,0;
end;
OnClaim:
mes "^FF0000 Enter your promotional code.";
input .@pc$;
close2;
if(query_sql("SELECT nameid,amount FROM `reward_codes` WHERE `code`='"+escape_sql(.@pc$)+"'",.@item,.@amt)==0) { dispbottom "Invalid promotional code."; end; }
if(query_logsql("SELECT code,account_id FROM `rewardlogs` WHERE `code`='"+escape_sql(.@pc$)+"' AND `account_id`='"+getcharid(3)+"'")) { dispbottom "You already claimed this promotional code."; end; }
else if(query_logsql("SELECT code,allow_multiple FROM `reward_codes` WHERE `code`='"+escape_sql(.@pc$)+"' AND `allow_multiple`='1'")) {
getitem .@item,.@amt;
dispbottom "Promotional code successfully redeemed.";
query_sql ("SELECT COUNT(code) FROM `reward_codes` WHERE `code`='"+escape_sql(.@pc$)+"'", .@pcode_exists);
if(.@pcode_exists) { query_sql ("DELETE FROM `reward_codes` WHERE `code`='"+escape_sql(.@pc$)+"'"); end; } else { dispbottom "Promotional code not found."; }
end;
}
else if(query_logsql("SELECT code,allow_multiple FROM `reward_codes` WHERE `code`='"+escape_sql(.@pc$)+"' AND `allow_multiple`='0'")) {
getitem .@item,.@amt; dispbottom "Promotional code successfully redeemed.";
query_logsql("INSERT INTO `rewardlogs` (code,redeem_time,account_id) VALUES ('"+.@pc$+"',NOW(),"+getcharid(3)+")");
end;
}
dispbottom "Rugby is not for everyone!";
end;
OnEditCode:
switch(prompt("Create random promocode.:Create custom promocode.:View existing promocodes.:Delete existing promocodes.")) {
case 1:
setarray .@RandomChar$[1],"a","b","c","d","e","f","g","h","i","j","k","m","n","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9";
set .@CharPick1$,.@RandomChar$[rand(1,33)];
set .@CharPick2$,.@RandomChar$[rand(1,33)];
set .@CharPick3$,.@RandomChar$[rand(1,33)];
set .@CharPick4$,.@RandomChar$[rand(1,33)];
set .@CharPick5$,.@RandomChar$[rand(1,33)];
set .@CharPick6$,.@RandomChar$[rand(1,33)];
set .@CharPick7$,.@RandomChar$[rand(1,33)];
set .@CharPick8$,.@RandomChar$[rand(1,33)];
set .@CharPick9$,.@RandomChar$[rand(1,33)];
set .@CharPick10$,.@RandomChar$[rand(1,33)];
set .@pcode$,""+.@CharPick1$+""+.@CharPick2$+""+.@CharPick3$+""+.@CharPick4$+""+.@CharPick5$+""+.@CharPick6$+""+.@CharPick7$+""+.@CharPick8$+""+.@CharPick9$+""+.@CharPick10$+"";
mes "The computer has generated a random promotional code of: ^0000FF"+.@pcode$+"^000000";
next;
query_sql ("SELECT COUNT(code) FROM `reward_codes` WHERE `code`='"+escape_sql(.@pcode$)+"'", .@pcode_exists);
if(.@pcode_exists) { mes "Sorry, that code already exist."; close; }
mes "The computer has generated ^FF0000"+.@pcode$+"^000000 as the promocode.";
mes " ";
mes " ";
mes "Please set a reward for the player who has entered the code.";
input .@reward;
next;
if(.@reward==0) { mes "Sorry, that is an invalid item id."; close; }
set .@iname$,getitemname(.@reward);
mes "How many ^FF0000"+.@iname$+"s^000000 would you like to give?";
input .@amount;
if(.@amount==0) { next; mes "Sorry, that is an invalid amount number."; close; }
next;
mes "Do you want this code to be usable on more than one account? Input ^FF00000^000000 to allow multiple or ^FF00001^000000 for single use.";
input .@multiple;
next;
mes "You have setup the prize to be:";
mes "^0000FF"+.@amount+"^000000 ^FF0000"+.@iname$+"^000000.";
if(.@multiple==0) { mes "It is setup to be useable on multiple accounts once."; } else { mes "It is setup to only be valid one time."; }
if(select("Yes:No, thanks")==2) { close; }
query_sql ("INSERT INTO `reward_codes` (code,nameid,item_name,amount,time_created,allow_multiple) VALUES ('"+.@pcode$+"', "+.@reward+", '"+.@iname$+"', "+.@amount+", NOW(),'"+.@multiple+"')");
dispbottom "Promotional Code ^FF0000"+.@pcode$+" ^000000is now activated and the reward is ^FF0000"+.@amount+" "+.@iname$+".";
end;
case 2:
mes "Please specify what you would like the new code to be?";
input .@pcode$;
if(getstrlen(.@pcode$)<1) { mes "You must enter something."; close; }
next;
query_sql ("SELECT COUNT(code) FROM `reward_codes` WHERE `code`='"+escape_sql(.@pcode$)+"'", .@pcode_exists);
if(.@pcode_exists) { mes "Sorry, that code already exist."; close; }
mes "You have entered ^FF0000"+.@pcode$+"^000000 as the code.";
mes " ";
mes " ";
mes " ";
mes "Please set a reward for the player who has entered the code.";
input .@reward;
next;
if(.@reward==0) { mes "Sorry, that is an invalid item id."; close; }
set .@iname$,getitemname(.@reward);
mes "How many ^FF0000"+.@iname$+"s^000000 would you like to give?";
input .@amount;
if(.@amount==0) { next; mes "Sorry, that is an invalid amount number."; close; }
next;
mes "Do you want this code to be usable on more than one account? Input ^FF00000^000000 to allow multiple or ^FF00001^000000 for single use.";
input .@multiple;
next;
mes "You have setup the prize to be:";
mes "^0000FF"+.@amount+"^000000 ^FF0000"+.@iname$+"^000000.";
if(.@multiple==0) { mes "It is setup to be useable on multiple accounts once."; } else { mes "It is setup to only be valid one time."; }
if(select("Yes:No, thanks")==2) { close; }
query_sql ("INSERT INTO `reward_codes` (code,nameid,item_name,amount,time_created,allow_multiple) VALUES ('"+.@pcode$+"', "+.@reward+", '"+.@iname$+"', "+.@amount+", NOW(),'"+.@multiple+"')");
dispbottom "Promotional Code ^FF0000"+.@pcode$+" ^000000is now activated and the reward is ^FF0000"+.@amount+" "+.@iname$+".";
end;
case 3:
set .@nb, query_sql("SELECT code, item_name, amount, allow_multiple amount FROM `reward_codes` ORDER BY time_created DESC LIMIT 100", .@code$, .@nid$, .@amount, .@allowmulti);
if(.@nb==0) { dispbottom "No existing codes."; end; }
dispbottom "=============================================";
dispbottom "============== EXISITING CODES ==============";
dispbottom "=============================================";
for(set .@i,0; .@i < .@nb; set .@i,.@i+1) {
dispbottom ""+.@code$[.@i]+" (Reward: "+.@amount[.@i]+" "+.@nid$[.@i]+") ("+(.@allowmulti[.@i]==0?"Multiple account use.":"One time use only.")+")"; }
dispbottom "=============================================";
end;
case 4:
input .@dcode$;
query_sql ("SELECT COUNT(code) FROM `reward_codes` WHERE `code`='"+escape_sql(.@dcode$)+"'", .@pcode_exists);
if(.@pcode_exists) {
mes "Would you like to delete that code?";
next;
if(select("Yes:No, thanks")==2) { close; }
query_sql ("DELETE FROM `reward_codes` WHERE `code`='"+escape_sql(.@dcode$)+"'");
mes "Promotional code successfully deleted.";
close;
}
dispbottom "Promotional code not found.";
end;
case 255:
close;
}
}
/*
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',
`allow_multiple` int(11) NOT NULL,
PRIMARY KEY (`code`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `rewardlogs` (
`code` varchar(10) NOT NULL DEFAULT '',
`redeem_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`account_id` int(11) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`code`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
*/
This maybe dead or too old but I think this is kinda useful:
There are 2 Problems here :
1. When you choose if the code can be used by multiple accounts.. -.- It literally can be used by the same account over and over and over again, my thoughts was it can be used by different accounts not by the same one more times than you can count
2. Im having this errors on the map
[Debug]: Source (NPC): promoclaim (invisible/not on a map)
[Warning]: script:query_sql: Too many columns, discarding last 2 columns.
[Debug]: Source (NPC): promoclaim (invisible/not on a map)
[SQL]: DB error - Duplicate entry 'H6EfUa3jq4' for key 'PRIMARY'
[Debug]: at script.c:15156 - INSERT INTO `rewardlogs` (code,redeem_time,account_id) VALUES ('H6EfUa3jq4',NOW(),2000045)
[Debug]: Source (NPC): promoclaim (invisible/not on a map)
[Warning]: script:query_sql: Too many columns, discarding last 2 columns.
[Debug]: Source (NPC): promoclaim (invisible/not on a map)
[Warning]: script:query_sql: Too many columns, discarding last 2 columns.
[Debug]: Source (NPC): promoclaim (invisible/not on a map)
[Warning]: script:query_sql: Too many columns, discarding last 2 columns.
[Debug]: Source (NPC): promoclaim (invisible/not on a map)
Question
NexusXVI
This was the Edited version of Peoplesperson of the utility script "Promotional Code" at this topic http://rathena.org/board/topic/80676-utility-utility-promotional-codes/
This maybe dead or too old but I think this is kinda useful:
There are 2 Problems here :
1. When you choose if the code can be used by multiple accounts.. -.- It literally can be used by the same account over and over and over again, my thoughts was it can be used by different accounts not by the same one more times than you can count
2. Im having this errors on the map
It it anyway posible to be fixed?
Edited by NexusXVILink to comment
Share on other sites
6 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.