SetPlayerAmmo Question
#1

Hey everyone, I'm wondering if it's possible to do with SetPlayerAmmo so it pluses with your current amount of bullets in the weapon, I've tried:

pawn Код:
SetPlayerAmmo(playerid,2,+strval(inputtext));
But that just outputs errors

Код:
C:\Users\Oliver\Desktop\Made From Scratch Script\gamemodes\counterstrike.pwn(1335) : error 029: invalid expression, assumed zero
C:\Users\Oliver\Desktop\Made From Scratch Script\gamemodes\counterstrike.pwn(1335) : error 001: expected token: ";", but found ")"
C:\Users\Oliver\Desktop\Made From Scratch Script\gamemodes\counterstrike.pwn(1335) : error 029: invalid expression, assumed zero
C:\Users\Oliver\Desktop\Made From Scratch Script\gamemodes\counterstrike.pwn(1335) : fatal error 107: too many error messages on one line
Reply
#2

pawn Код:
SetPlayerAmmo(playerid,2,GetPlayerAmmo(playerid)+strval(inputtext));
Reply
#3

Thanks, going to go test it now, no errors so I bet it works
Reply
#4

I'm afraid it didn't work I didn't receive any ammo for my shotgun when I used it.

The money part works, just not the SetPlayerAmmo part.
pawn Код:
SetPlayerAmmo(playerid,3,GetPlayerAmmo(playerid)+strval(inputtext));
                GivePlayerMoney(playerid,-strval(inputtext)*7);
Reply
#5

not sure if it will work, i didnt' test it in gameplay but i've used something similar before.
pawn Код:
stock GiveAmmo(playerid, amount)
{
    new pAmmo = GetPlayerAmmo(playerid), //get ammo for current weapon
        pWeapon = GetPlayerWeapon(playerid), //get current weapon to determine slot
        pSlot; //to store the slot
    switch(pWeapon) //find the weapon slot
    {
        case 331: pSlot = 0;
        case 333,334,335,336,337,338,339,341: pSlot = 1;
        case 346,347,348: pSlot = 2;
        case 349,350,351: pSlot = 3;
        case 352,353,372: pSlot = 4;
        case 355,356: pSlot = 5;
        case 357,358: pSlot = 6;
        case 359,360,361,362: pSlot = 7;
        case 342,343,344,363: pSlot = 8;
        case 365,366,367: pSlot = 9;
        case 321,322,323,324,325,326: pSlot = 10;
        case 368,369,371: pSlot = 11;
    }
    SetPlayerAmmo(playerid, pSlot, (SetPlayerAmmo(playerid, pSlot, amount)+pAmmo)); //set their new ammo!
    return true;
}
use it like:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/cash", true))
    {
        GiveAmmo(playerid, 100);
        SendClientMessage(playerid, 0xFFFFFFAA, "You got 100$!");
    }
    return true;
}
Reply
#6

Nope doesn't work it still only takes the cash and doesn't give the ammo
Reply
#7

Wait.. i don't even know why i made the command /cash lol. I didn't even do anything involving cash. try this:

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/ammo", true))
    {
        GiveAmmo(playerid, 100);
        SendClientMessage(playerid, 0xFFFFFFAA, "You got 100 rounds of ammo!");
        return true;
    }
    return false;
}

//------------------------------------------------

stock GiveAmmo(playerid, amount)
{
    new pAmmo = GetPlayerAmmo(playerid), //get ammo for current weapon
        pWeapon = GetPlayerWeapon(playerid), //get current weapon to determine slot
        pSlot; //to store the slot
    switch(pWeapon) //find the weapon slot
    {
        case 331: pSlot = 0;
        case 333,334,335,336,337,338,339,341: pSlot = 1;
        case 346,347,348: pSlot = 2;
        case 349,350,351: pSlot = 3;
        case 352,353,372: pSlot = 4;
        case 355,356: pSlot = 5;
        case 357,358: pSlot = 6;
        case 359,360,361,362: pSlot = 7;
        case 342,343,344,363: pSlot = 8;
        case 365,366,367: pSlot = 9;
        case 321,322,323,324,325,326: pSlot = 10;
        case 368,369,371: pSlot = 11;
    }
    SetPlayerAmmo(playerid, pSlot, (pAmmo+amount)); //set their new ammo!
    return true;
}
not sure what i was thinking before, lol. thats what i get for thinking too early in the morning!
Reply
#8

Still not working and yea I was like: Uh why did he make a /cash command?

Anyways I believe that method wont work anyways as that would be abusable, Since it doesn't check if the player actually is wearing a shotgun (Slot 3)
Reply
#9

Oh, you only need it for slot 3? My method actually checks what weapon they have, and then detects what slot that weapons in, in order to give the ammo only to that slot, etc. Thats why the switch is there.

try something like this:

pawn Код:
new oldAmmo = GetPlayerAmmo(playerid);
SetPlayerAmmo(playerid, 3, (oldAmmo+100));
that'll just give them 100 rounds. (hopefully!)
Reply
#10

Better check that it's not me who are failing, heres the code for it (It's in a dialog)

pawn Код:
new oldAmmo = GetPlayerAmmo(playerid);
                SetPlayerAmmo(playerid, 3, (oldAmmo+strval(inputtext)));
By dialog then I mean it's a dialog not a command

Anyways, the other way would also have been working, I just do a if statement if he have a shotgun on him, then it's not abusable, anyways it might be me who are doing something wrong
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)