#1

Can someone help me with this problem?

I've created a custom shop, everything works except armor buy.

pawn Код:
new Float:armour;
            GetPlayerArmour(playerid, armour);
            if(armour >= MAX_ARMOUR)
            {
                PlayerPlaySound(playerid, 1053, 0.0, 0.0, 0.0);
                GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~n~~n~~n~~w~You cannot buy any more armor.", 5000, 3);
            }
            else OnPlayerBuyInAmmuNation(playerid, 0, 100, COST_ARMOR);
Basically, i want to check if the player armor is full, if is positive, don't let him buy more armor.

The problem is, even if my armour is at maximum, i still can buy more armor but im getting that gametext message. Any help?
Reply
#2

Are you calling the OnPlayerBuyInAmmuNation function anywhere? I don't see any problems with your code.

Edit: I mean, anywhere other than the else statement. If not, your function might be the cause of your problem.
Reply
#3

No just calling in that code.

pawn Код:
public OnPlayerBuyInAmmuNation(playerid, weaponid, ammo, cost)
{
    new const fmt_str[] = "* Weapon purchased for "GREEN"$%d. "WHITE"Thank you for shopping with Ammunation!";
    new str[sizeof(fmt_str) + 3];
    GivePlayerMoney(playerid, -cost);
    GivePlayerWeapon(playerid, weaponid, ammo);
    if(!weaponid) SetPlayerArmour(playerid, ammo);
    format(str, sizeof str, fmt_str, cost);
    SendClientMessage(playerid, -1, str);
    return 1;
}
Reply
#4

I will run some tests on my local server and hopefully let you know about the solution. Meanwhile, can you re-check if anything prompts your buying function?
Reply
#5

can you change

pawn Код:
forward OnPlayerBuyInAmmuNation(playerid, weaponid, ammo, cost);
public OnPlayerBuyInAmmuNation(playerid, weaponid, ammo, cost)
to

pawn Код:
OnPlayerBuyInAmmuNation(playerid, weaponid, ammo, cost)
and try again?

Actually nevermind, it won't change anything. Your code works just fine on my local server, I can't buy more armor when I am already on full armor.

Screenshot;

https://prnt.sc/kciefm
Reply
#6

try now
Код HTML:
OnPlayerBuyInAmmuNation(playerid, weaponid, ammo, cost)
{
	new str[256];
    GivePlayerMoney(playerid, -cost);
    GivePlayerWeapon(playerid, weaponid, ammo);
    if(!weaponid) SetPlayerArmour(playerid, ammo);
    format(str, sizeof(str), "* Weapon purchased for {2ebc29}$%d. {ffffff}Thank you for shopping with Ammunation!", cost);
    SendClientMessage(playerid, -1, str);
    return 1;
}
Reply
#7

Quote:
Originally Posted by Florin48
Посмотреть сообщение
try now
Код HTML:
OnPlayerBuyInAmmuNation(playerid, weaponid, ammo, cost)
{
	new str[256];
    GivePlayerMoney(playerid, -cost);
    GivePlayerWeapon(playerid, weaponid, ammo);
    if(!weaponid) SetPlayerArmour(playerid, ammo);
    format(str, sizeof(str), "* Weapon purchased for {2ebc29}$%d. {ffffff}Thank you for shopping with Ammunation!", cost);
    SendClientMessage(playerid, -1, str);
    return 1;
}
You are doing exactly what he does in a different way, I don't see how changing string formatting will fix his issue.

To OP; Are you 100% sure you are not calling the function for armor anywhere else?
Reply
#8

@Rufio just checked now. I can't actually buy more armor as i have, but money are deducted just like if i purchase it..

@Florin: What you did is just change string parameters..
Reply
#9

Well, I could give you a temporary solution until we can find a permanent one, what you can do is this;

add this on top of your script somewhere;

pawn Код:
new successfulBuy[MAX_PLAYERS];
we'll edit it soon to tell the script if the buying action was successful

add this in OnPlayerConnect;

pawn Код:
successfulBuy[playerid] = 0;
change your armor buying to this;

pawn Код:
new Float:armour;
            GetPlayerArmour(playerid, armour);
            if(armour >= MAX_ARMOUR)
            {
                PlayerPlaySound(playerid, 1053, 0.0, 0.0, 0.0);
                GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~n~~n~~n~~w~You cannot buy any more armor.", 5000, 3);
            }
            else {
                successfulBuy[playerid] = 1;
                OnPlayerBuyInAmmuNation(playerid, 0, 100, COST_ARMOR);
            }
and add this if statement to your function;

pawn Код:
if(successfulBuy[playerid]) {
This will basically check if your function was called through the right means and not anywhere else. If your money doesn't get deducted this time, that means you are calling your armor buying function somewhere else as well.

Edit: Also don't forget to add successfulBuy[playerid] to all your items and don't forget to set successfulBuy back to 0 once the purchase is complete.
Reply
#10

Thank you for your patience. I'll check better if i find something strange.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)