Jump to content
  • 0
Origami

Adding Restriction to REDEEM NPC (CP_CREDITS)

Question

Good day Rathena ! I need support here regarding @sikiro's Flux CP NPC Script .. This is use to redeam Donation Credits and convert into #CASHPOINTS ... Im having a little problem since I want to add restriction here ... 

1. Lets say I have 500 Donation credits.. The NPC will ask HOW MUCH donation credits I want to convert into CASHPOINTS .. If I input 501 the NPC will not allow me to convert since it has bigger amount than my existing credit amount ... Im not that good in SQL ,... Please help 

 

FULL SCRIPT:

Quote

prontera,139,182,4    script    Donor Rewards Redeemer    987,{
    // ----------------- NPC Settings -----------------
    // --- SET THESE BEFORE LOADING THE SCRIPT! ---
    
    // Server Name
    set .serverName$,"rAthena";
    
    // NPC Name to display during chat.
    // Default: "[Donor Rewards Redeemer]"
    set .npcName$,"[Donor Rewards Redeemer]";
    
    // DO NOT CHANGE THIS!
    // Default: "cp_redeemlog"
    set .redeemTable$,"cp_credits";
    set .itemTable$,"cp_redeemlog";
    
    // Display Credits to FluxCP Creators?
    // Help promote our product if its useful.
    // 0 = Disable. 1 = Enable.
    // Default: 1
    set .showCredits,0;
    
    // Max number of unique items to redeem at a time.
    // DO NOT RAISE THIS VALUE ABOVE 128 WITHOUT
    // MAKING THE NECESSARY SCRIPT ENGINE MODS
    // FOR SCRIPT ARRAY SIZING! DANGEROUS!
    // Default: 128
    set .numRedemptionsSimul,128; 
    // --------------- End NPC Settings ---------------

    // ----------------- Begin Script -----------------
    mes .npcName$;
    mes "Well hello there " + (Sex ? "good sir!" : "young madam!");
    mes "How may I be of assistance to you on this fine day?";
    next;
    prompt("I wish to redeem My Credits:Collect My items :Check my balance.");
    mes .npcName$;
switch(@menu) {
        case 1:
            query_sql("SELECT `balance` FROM `" + escape_sql(.redeemTable$) + "` WHERE `account_id` = " + getcharid(3) + " LIMIT 0,30", [email protected]);
            if ([email protected] > 0){
            mes "How many Donation Credits do you wish to redeem?";
            next;
            mes .npcName$;
            input [email protected],1,[email protected];
            query_sql("UPDATE `" + escape_sql(.redeemTable$) + "` SET `balance` = `balance` - " + [email protected] + " WHERE `account_id` = " + getcharid(3) + "");
            set #CASHPOINTS,#CASHPOINTS + [email protected];
            mes [email protected] + "x " ;
            } else {
                mes "My records indicate that there are no rewards awaiting to be redeemed.";
                mes "My deepest apologies for the misunderstanding.";
            }
        break;
        case 2:
            query_sql "SELECT `id`, `nameid`, `quantity` FROM `" + escape_sql(.itemTable$) + "` WHERE `account_id` = " + getcharid(3) + " AND `redeemed` = 0 LIMIT " + .numRedemptionsSimul,[email protected],[email protected],[email protected];
            if (getarraysize([email protected]) > 0) {
                mes "Items Pending Redemption: " + getarraysize([email protected]);
                for (set [email protected],0; [email protected] < getarraysize([email protected]); set [email protected],[email protected]+1)
                    if (checkweight([email protected][[email protected]],[email protected][[email protected]]) == 0) {
                        mes "I'm terribly sorry, but you are carrying too much to accept " + ([email protected] ? "any more of " : " ") + "your rewards at this time.";
                        mes "Please come back with fewer items.";
                    } else {
                        query_sql "UPDATE `" + escape_sql(.itemTable$) + "` SET `char_id` = " + getcharid(0) + ", `redeemed` = 1, `redemption_date` = NOW() WHERE `id` = " + [email protected][[email protected]];
                        getitem [email protected][[email protected]],[email protected][[email protected]];
                        mes [email protected][[email protected]] + "x " + getitemname([email protected][[email protected]]);
                    }
                if ([email protected] == getarraysize([email protected])) {
                    mes "Thank you for your patronage " + (Sex ? "fine sir." : "ma'am.");
                    mes "Please enjoy your stay on " + .serverName$ + "!";
                }
                if (.showCredits)
                    callfunc "F_FluxCredits";
            } else {
                mes "My records indicate that there are no rewards awaiting to be redeemed.";
                mes "My deepest apologies for the misunderstanding.";
            }
        break;
        case 3:
            query_sql("SELECT `balance` FROM `" + escape_sql(.redeemTable$) + "` WHERE `account_id` = " + getcharid(3) + " LIMIT 0,30", [email protected]);
            mes "You currently have " + [email protected] + " donation credits.";
        break;
    }
    close;
    // ------------------ End Script ------------------
}

// ------------ Credits to FluxCP Creators ------------
// - Please do not modify or delete this function or  -
// - its contents. To disable the credits from being  -
// - shown, set .showCredits to 0 in the NPC Settings -
// - at the top of this file.                         -
// ----------------------------------------------------

function    script    F_FluxCredits    {
    mes "-----------------------------------";
    mes "Powered by Flux Control Panel.";
    mes "Copyright © 2008-2012 Matthew Harris and Nikunj Mehta.";
    mes "http://fluxcp.googlecode.com/";
    return;
}
 

The line that I need to modify:

 

Quote

        case 1:
            query_sql("SELECT `balance` FROM `" + escape_sql(.redeemTable$) + "` WHERE `account_id` = " + getcharid(3) + " LIMIT 0,30", [email protected]);
            if ([email protected] > 0){
            mes "How many Donation Credits do you wish to redeem?";
            next;
            mes .npcName$;
            input [email protected],1,[email protected];
            query_sql("UPDATE `" + escape_sql(.redeemTable$) + "` SET `balance` = `balance` - " + [email protected] + " WHERE `account_id` = " + getcharid(3) + "");
            set #CASHPOINTS,#CASHPOINTS + [email protected];
            mes [email protected] + "x " ;
            } else {
                mes "My records indicate that there are no rewards awaiting to be redeemed.";
                mes "My deepest apologies for the misunderstanding.";
            }
        break;

THANKYOU !!!

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Need to add check

        case 1:
            query_sql("SELECT `balance` FROM `" + escape_sql(.redeemTable$) + "` WHERE `account_id` = " + getcharid(3), .@credits);
            if (.@credits > 0){
            mes "How many Donation Credits do you wish to redeem?";
            next;
            mes .npcName$;
            input .@withdrawCredits,1,.@credits;
            if(.@withdrawCredits > .@credits) {
              	mes "You don't have enough credits.";
              	close;
            }
            query_sql("UPDATE `" + escape_sql(.redeemTable$) + "` SET `balance` = `balance` - " + .@withdrawCredits + " WHERE `account_id` = " + getcharid(3) + "");
            set #CASHPOINTS,#CASHPOINTS + [email protected];
            mes .@withdrawCredits + "x " ;
            } else {
                mes "My records indicate that there are no rewards awaiting to be redeemed.";
                mes "My deepest apologies for the misunderstanding.";
            }
        break;

 

Edited by Balfear

Share this post


Link to post
Share on other sites
  • 0
5 hours ago, Balfear said:

Need to add check

        case 1:
            query_sql("SELECT `balance` FROM `" + escape_sql(.redeemTable$) + "` WHERE `account_id` = " + getcharid(3), .@credits);
            if (.@credits > 0){
            mes "How many Donation Credits do you wish to redeem?";
            next;
            mes .npcName$;
            input .@withdrawCredits,1,.@credits;
            if(.@withdrawCredits > .@credits) {
              	mes "You don't have enough credits.";
              	close;
            }
            query_sql("UPDATE `" + escape_sql(.redeemTable$) + "` SET `balance` = `balance` - " + .@withdrawCredits + " WHERE `account_id` = " + getcharid(3) + "");
            set #CASHPOINTS,#CASHPOINTS + [email protected];
            mes .@withdrawCredits + "x " ;
            } else {
                mes "My records indicate that there are no rewards awaiting to be redeemed.";
                mes "My deepest apologies for the misunderstanding.";
            }
        break;

 

Hi sir ! Ive tested it but doesnt work 😞 Im just curious tho sir .. what those this mean ? 

input .@withdrawCredits,1,.@credits;

Why add ,1 after the [email protected] ?? when it has to be only [email protected] ?

Edited by erjsanmiguel
adding question

Share this post


Link to post
Share on other sites
  • 0
On 5/4/2021 at 6:59 PM, erjsanmiguel said:

Hi sir ! Ive tested it but doesnt work 😞 Im just curious tho sir .. what those this mean ? 

input .@withdrawCredits,1,.@credits;

Why add ,1 after the [email protected] ?? when it has to be only [email protected] ?


1 -  is the minimum.
[email protected] - is the maximum. value is depend on your balance from cp_credits table

try this..

change

input .@withdrawCredits,1,.@credits;

into

input .@withdrawCredits;
Edited by Alzhea

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

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.