Jump to content
  • 0

Help to add lines to this script


xeijvro

Question


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.01
  • Content Count:  14
  • Reputation:   0
  • Joined:  12/02/22
  • Last Seen:  

Hello im using @claim and @code command this is the script. I want is to be able to just use by 1 IP because it can claim again and again 1 code for all players and just 1 per IP

 

Here is the script 

 

 

-    script    promoclaim    -1,{


OnInit:
    bindatcmd "claim",strnpcinfo(3)+"::OnClaim";
    bindatcmd "code",strnpcinfo(3)+"::OnEditCode";
    end;
    
OnClaim:
    // if ( getgmlevel() ) end;
    mes "^FF0000 Enter the Promo 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 Expired";
    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: close; break;
        default: break;
    }
    end;
}
 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

  • Group:  Donators
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  23
  • Reputation:   2
  • Joined:  10/31/12
  • Last Seen:  

-    script    promoclaim    -1,{


OnInit:
    bindatcmd "claim",strnpcinfo(3)+"::OnClaim";
    bindatcmd "code",strnpcinfo(3)+"::OnEditCode";
    end;
    
OnClaim:
    // if ( getgmlevel() ) end;
    mes "^FF0000 Enter the Promo Code.";
    input .@pc$;
    close2;
    
    query_sql "SELECT `nameid`, `amount` FROM `reward_codes` WHERE `code` = '" + escape_sql(.@pc$) + "'", .@item, .@amt;
    query_sql "SELECT count(*) FROM `rewardlogs` WHERE `code` = '"+ escape_sql(.@pc$) + "' AND `ip_address` = '"+getcharip(strcharinfo(0))+"', .@ipcheck;
    if ( !.@item && !.@ipcheck ) 
        dispbottom "Either invalid code or the code is already Expired";
    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$) + "','"+getcharip(strcharinfo(0))+"', NOW() )"; // ADD IP ADDRESS WHEN CLAIMED IN rewardlogs then
    }
    
    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: close; break;
        default: break;
    }
    end;
}

Try this edit your rewardlogs add ip_address also edit this line

Quote

query_sql "SELECT count(*) FROM `rewardlogs` WHERE `code` = '"+ escape_sql(.@pc$) + "' AND `ip_address` = '"+getcharip(strcharinfo(0))+"', .@ipcheck;

since i dont know what are the columns in rewardlogs hehe ?

this modification will allow player with different IP to claim the code 

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