Houselocker help
#1

Hi,
This is my houselocker command:
pawn Код:
COMMAND:houselocker(playerid, params[])
{// houselocker [take / put ] [sguns/sdrugs] [amount]
        new tmp[ 64 ], tmp2[ 64 ], tmp3;
        if(PlayerTemp[playerid][tmphouse]!=-1)
        {
            new filename[20]; format(filename,sizeof(filename),"Casa%d.txt",House[PlayerTemp[playerid][tmphouse]][HouseID]);
            new cursguns = dini_Int(filename,"materials");
            new cursdrugs = dini_Int(filename,"sdrugs");
            if(sscanf(params, "ssd",tmp,tmp2,tmp3))
            {
                SendClientMSG(playerid, COLOR_LIGHTGREY, "LOCKER: There is currently %d Guns and %d Drugs in the locker.", dini_Int(filename,"sguns"), dini_Int(filename,"sdrugs"));
                return SCP(playerid, "[ take / put ] [ materials / sdrugs ] [ amount ]");
            }
            if(!strcmp(tmp, "take"))
            {
                if(!strlen(tmp2)) return SCP(playerid,"take [ materials / sdrugs ] [ amount ]");
                if(!strcmp(tmp2,"materials"))
                {
                if(tmp3>cursguns)
                if(PlayerInfo[playerid][sguns]<tmp3)
                if(PlayerInfo[playerid][sguns]<0)
                    {
                        SendClientError(playerid,  "Invalid amount");
                        return 1;
                    }
                    if(!cursguns)

                    format(filename,sizeof(filename),"Casa%d.txt",House[PlayerTemp[playerid][tmphouse]][HouseID]);
                    dini_IntSet(filename, "sguns", cursguns-tmp3);
                    PlayerInfo[playerid][sguns] += tmp3;
                    SendClientMSG(playerid, COLOR_LIGHTGREY, "LOCKER: You have taken %d materials from your house locker.", tmp3);
                }
                else if(!strcmp(tmp2,"sdrugs"))
                {
                if(!cursdrugs)
                if(tmp3>cursdrugs)
                {
                    SendClientError(playerid,  "Invalid amount");
                    return 1;
                }
                    dini_IntSet(filename,"sdrugs", cursdrugs-tmp3);
                //  format(filename,sizeof(filename),"Casa%d.txt",House[PlayerTemp[playerid][tmphouse]][HouseID]);
                    PlayerInfo[playerid][sdrugs] += tmp3;
                    SendClientMSG(playerid, COLOR_LIGHTGREY, "LOCKER: You have taken %d drugs from your house locker.", tmp3);
                }
            }
            else if(!strcmp(tmp, "put"))
            {
                if(!strlen(tmp2)) return SCP(playerid,"put [ materials / sdrugs ] [ amount ]");
                if(!strcmp(tmp2,"sguns"))
                {
                                if(PlayerInfo[playerid][sguns]<tmp3)
                                if(PlayerInfo[playerid][sguns]<0)
                    {
                        SendClientError(playerid, "Invalid amount");
                        return 1;
                    }
                        dini_IntSet(filename, "sguns" , cursguns+tmp3);
                        PlayerInfo[playerid][sguns] -= tmp3;
                        SendClientMSG(playerid, COLOR_LIGHTGREY, "LOCKER: You have put %d materials from your house locker.", tmp3);
                    }
                    else if(!strcmp(tmp2,"sdrugs"))
                    {
                            if(PlayerInfo[playerid][sdrugs]<tmp3)
                    {
                        SendClientError(playerid, "Invalid amount");
                        return 1;
                    }
                        dini_IntSet(filename,"sdrugs", cursdrugs+tmp3);
                        PlayerInfo[playerid][sdrugs] -= tmp3;
                        SendClientMSG(playerid, COLOR_LIGHTGREY, "LOCKER: You have put %d drugs from your house locker.", tmp3);
                    }
            }
        }
        return 1;
}
But, everyone can take even in negative amounts, and bug it so they exploit it for ALOT of materials.
How do i fix this?
Reply
#2

bump
Reply
#3

bumping again
Reply
#4

Nobody an idea?
Reply
#5

1. I advise you not to update files inside of commands as that can potentially enable 'spamming' -> promoting lag. I recommend creating a variable that detects if the 'data' has been modified: then make a function that saves every x minutes (using a timer for this), you only want to save data if it's been modified: efficient. Also this way players cannot spam. Or at least return a function to save the variables to file. This'll make it much more easier to edit if needs editing in the future.

2. You should loop through and see IF THE PLAYER OWNS THAT HOUSE THEY ARE IN. You are only detecting if the house is owned (-1)?
Review existing house systems: how do they know if players are inside that particular house?
3. Negative values probably caused by not having the IF statement that says the item has to be of positive quantity.
Reply
#6

Under "take" try this:
Код:
if(tmp3 < 0) return SendClientError(playerid,  "Invalid amount");
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)