Redeemer NPC / Coupon NPC / Promotional NPC

ThyroDree

New member
Messages
556
Points
0
Location
Philippines
Github
bosxkate23
Emulator
can i request a Redeemer NPC / Coupon NPC / Promotional NPC 

Info:

the player talk to npc and click the Redeem a Promo Code then type "TestproMO111" then the npc will check and give the player a items ( GR,Tao,MainGauche,Field manual,etc,. ) and if the Player try to cheat or make a new character and redeem it again the code "TestproMO111" the npc will say "Sorry, either the code "TestproMO111" you have entered is invalid or the promo was over or someone already claim it ."

 
Last edited by a moderator:
DotaRO?
default_tongue.png


 
Code:
/*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 .@pc$;    close2;        query_sql "SELECT `nameid`, `amount` FROM `reward_codes` WHERE `code` = '" + escape_sql(.@pc$) + "'", .@item, .@amt;        if ( !.@item )         dispbottom "Either invalid code or the code is already claimed by other people";    else {        getitem .@item, .@amt;        dispbottom "Promotional code successfully redeemed.";        query_sql "DELETE FROM `reward_codes` WHERE `code` = '" + escape_sql(.@pc$) + "'";        query_logsql "INSERT INTO `rewardlogs` VALUES ( '" + getcharid(3) + "', '" + escape_sql(.@pc$) + "', NOW() )";    }        end;    OnEditCode:    if ( getgmlevel() < 99 ) end;    set .@choice$, "Setup a new promotional code:View existing codes:Delete exisiting codes:Cancel";    setarray .@length, 4,10; // <min>,<max>        switch ( select( .@choice$ ) ) {        case 1:                input .@pcode$;                if ( getstrlen( .@pcode$ ) < .@length[0] || getstrlen( .@pcode$ ) > .@length[1] ) {                        dispbottom "Codes must not be less than " +.@length[0]+ " and must be greater than " +.@length[1]+ ".";                        end;                }                mes "You have entered ^FF0000"+.@pcode$+"^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(.@pcode$) + "'", .@pcode_exists;                if ( .@pcode_exists ) {                        dispbottom "Sorry, that code already exist.";                        end;                }                mes "Please set a reward for the players who has entered the code.";                input .@reward;                next;                if ( !.@reward || getitemname(.@reward) == "null" ) {                        dispbottom "Sorry, that is an invalid item id.";                        end;                }                set .@iname$, getitemname(.@reward);                mes "Item number ^FF0000"+.@reward+"^000000";                mes "is equivalent to ^FF0000"+.@iname$+"^000000.";                mes "Are you sure?";                next;                if ( select("Yes:No, thanks") - 1 ) end;                mes "How many ^FF0000"+.@iname$+"^000000.?";                input .@amount;                next;                if ( !.@amount ) {                    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(.@pcode$) + "', '" + .@reward + "', '" + escape_sql(.@iname$) + "', '" + .@amount + "', NOW() )";                dispbottom "Done creating code!";                break;        case 2:                set .@nb, query_sql("SELECT code, item_name, amount FROM `reward_codes` ORDER BY time_created DESC LIMIT 20", .@code$, .@nid$, .@amount);                    if ( !.@nb ) {                    dispbottom "No exisiting 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]+" ) ";                dispbottom "=============================================";                break;        case 3:                input .@dcode$;                query_sql "SELECT `code` FROM `reward_codes` WHERE `code` = '" + escape_sql(.@dcode$) + "'", .@dcode_exists;                if ( !.@dcode_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(.@dcode$) + "'";                break;        case 4: break;        default: break;    }    close;}
 
Last edited by a moderator:
perfectly built script, I can only see 1 bug and 2 improvements

1.

bindatcmd "claim",strnpcinfo(3)+"::OnClaim"; bindatcmd "code",strnpcinfo(3)+"::OnEditCode";when you write an atcommand that player can usealways set charcommand level to 99 or 100

its simple to reproduce

when pvp/gvg, type '#claim <player name that you hated>' and will send a chat box on the player,

cause him to have a moment of pause because need to type something

yet again ... this kind of knowledge can only acquire when you have work on a live server =/

2.

so change into like this

bindatcmd "claim",strnpcinfo(3)+"::OnClaim", 0, 100; bindatcmd "code",strnpcinfo(3)+"::OnEditCode", 99, 100;so you don't have to ( getgmlevel() < 99 ) end;
3.

Code:
    query_sql "SELECT `nameid`, `amount` FROM `reward_codes` WHERE `code` = '" + escape_sql(.@pc$) + "'", .@item, .@amt;        if ( !.@item )         dispbottom "Either invalid code or the code is already claimed by other people";
can be simplify as
Code:
	if ( !query_sql( "SELECT `nameid`, `amount` FROM `reward_codes` WHERE `code` = '" + escape_sql(.@pc$) + "'", .@item, .@amt ) )        dispbottom "Either invalid code or the code is already claimed by other people";
 
Last edited by a moderator:
Patskie, here's some thing i have to request.

- the LOG tables, can you also include the item that they claimed?

rewardlogs > accid >code>item>redeem item ? is that possible?
And some problem i am facing if i put a wrong ID. character will get stuck need to relog or @refresh.

 
The problem is when you type @code and select "view existing code" your character stuck. you need to @warp to move again, also at "delete existing code"

any fix on this issue? thanks.

 
Hello, sorry for necro but can anyone fix the script linked by AnnieRuru? It uses "String" as a function and it may have problems in SQL Side since only the first player can't claim it twice. (The 2nd and succeeding players can claim it endlessly)

 
Back
Top