OnPlayerPickUpPickup problem
#1

pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == m4[ 0 ] || m4[ 1 ] || m4[ 2 ] || m4[ 3 ])
    {
        GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~m4!", 2500, 6);
        GivePlayerWeapon(playerid, 31, 20);
    }
   
    else if(pickupid == Rocket)
    {
        GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Rocket launcher!", 2500, 6);
        GivePlayerWeapon(playerid, 35, 3);
    }
   
    else if(pickupid == Spaz[ 0 ] || Spaz[ 1 ])
    {
        GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Spaz12!", 2500, 6);
        GivePlayerWeapon(playerid, 27, 20);
    }
   
    else if(pickupid == Tec9[ 0 ] || Tec9[ 1 ] || Tec9[ 2 ])
    {
        GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Tec9!", 2500, 6);
        GivePlayerWeapon(playerid, 32, 20);
    }
   
    else if(pickupid == Shotgun[ 0 ] || Shotgun[ 1 ] )
    {
        GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Shotgun!", 2500, 6);
        GivePlayerWeapon(playerid, 25, 25);
    }
   
    else if(pickupid == sniper[ 0 ] || sniper[ 1 ] || sniper[ 2 ])
    {
        GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Sniper!", 2500, 6);
        GivePlayerWeapon(playerid, 34, 10);
    }
   
    else if(pickupid == Desert[ 0  ] || Desert[ 1 ])
    {
        GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Desert!", 2500, 6);
        GivePlayerWeapon(playerid, 24, 13);
    }
   
    else if(pickupid == Uzi[ 0 ] || Uzi[ 1 ])
    {
        GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Uzi!", 2500, 6);
        GivePlayerWeapon(playerid, 28, 50);
    }
   
    else if(pickupid == Ah[ 0 ] || Ah[ 1 ])
    {
        if(Ah[ 0 ]) return GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Health pack!", 2500, 6);
        if(Ah[ 1 ]) return GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Armour pack!", 2500, 6);
        ahpicked[ playerid ][ 0 ] = true;
        ahpicked[ playerid ][ 1 ] = true;
    }
    return 1;
}
When i try to pick anything that is not m4, it says it's an m4 and gives me m4 ammo.. but also gives me the other gun ammo, gives me both... please help!
Reply
#2

show the code where you define the pick ups.
Reply
#3

yeah show the code of defining them
Reply
#4

pawn Код:
new m4[ 4 ], Rocket, Spaz[ 2 ], Tec9[ 3 ], Shotgun[ 2 ], Desert[ 2 ], sniper[ 3 ], Uzi[ 2 ];
Creation:

pawn Код:
public OnGameModeInit()
{
    m4[ 0 ] = CreatePickup(356, 2, 44.7975,1532.1158,12.7500, -1);
    m4[ 1 ] = CreatePickup(356, 2, 44.4806,1512.6018,12.7500, -1);
    m4[ 2 ] = CreatePickup(356, 2, 26.5943,1490.2959,12.7500, -1);
    m4[ 3 ] = CreatePickup(356, 2, -8.0397,1492.3533,12.7500, -1);
    Rocket = CreatePickup(359, 2, 12.1302,1519.8992,12.7560, -1);
    Spaz[ 0 ] = CreatePickup(351, 2, 49.0691,1516.0593,14.0457, -1);
    Spaz[ 1 ] = CreatePickup(351, 2, -25.7448,1517.5323,14.0457, -1);
    Tec9[ 0 ] = CreatePickup(372 , 2, 49.0328,1501.4786,14.0457, -1);
    Tec9[ 1 ] = CreatePickup(372 , 2, -25.6564,1539.7822,14.0457, -1);
    Tec9[ 2 ] = CreatePickup(372 , 2, 48.9823,1539.4341,14.0457, -1);
    Shotgun[ 0 ] = CreatePickup(349 , 2, 11.3106,1489.3499,13.266, -1);
    Shotgun[ 1 ] = CreatePickup(349 , 2, 15.6130,1489.8904,13.2660, -1);
    Desert[ 0 ] = CreatePickup(348, 2, 35.1271,1550.7230,12.750, -1);
    Desert[ 1 ] = CreatePickup(348, 2, 35.1271,1550.7230,12.750, -1);
    sniper[ 0 ] = CreatePickup(358, 2, 5.0655,1551.1831,12.7560, -1);
    sniper[ 1 ] = CreatePickup(358, 2, -2.3343,1551.1136,12.7560, -1);
    sniper[ 2 ] = CreatePickup(358, 2, 13.4171,1491.6609,16.7056, -1);
    Uzi[ 0 ] = CreatePickup(352, 2, -25.7545,1539.1781,14.0457, -1);
    Uzi[ 1 ] = CreatePickup(352, 2, -25.8899,1501.3649,14.0457, -1);
        return 1;
}
Another problem, when a player spawns he gets all the weapons created in pickups somehow, idk what's wrong honestly.

My onplayerspawn

pawn Код:
public OnPlayerSpawn(playerid)
{
    return 1;
}
Reply
#5

the || check will not work when you stack them variables (pickupids) like you did above, an almost similar approach could look like
pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    switch(pickupid)
    {
        case m4[ 0 ] , m4[ 1 ] , m4[ 2 ] , m4[ 3 ]:
        {
            GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~m4!", 2500, 6);
            GivePlayerWeapon(playerid, 31, 20);
        }
        case Rocket:
        {
            GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Rocket launcher!", 2500, 6);
            GivePlayerWeapon(playerid, 35, 3);
        }
        case Spaz[ 0 ],Spaz[ 1 ]:
        {
            GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Spaz12!", 2500, 6);
            GivePlayerWeapon(playerid, 27, 20);
        }
        case Tec9[ 0 ] , Tec9[ 1 ] , Tec9[ 2 ]:
        {
            GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Tec9!", 2500, 6);
            GivePlayerWeapon(playerid, 32, 20);
        }
        case Shotgun[ 0 ] , Shotgun[ 1 ]:
        {
            GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Shotgun!", 2500, 6);
            GivePlayerWeapon(playerid, 25, 25);
        }
        case sniper[ 0 ] , sniper[ 1 ] , sniper[ 2 ]:
        {
            GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Sniper!", 2500, 6);
            GivePlayerWeapon(playerid, 34, 10);
        }
        case Desert[ 0  ] , Desert[ 1 ]:
        {
            GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Desert!", 2500, 6);
            GivePlayerWeapon(playerid, 24, 13);
        }
        case Uzi[ 0 ] , Uzi[ 1 ]:
        {
            GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Uzi!", 2500, 6);
            GivePlayerWeapon(playerid, 28, 50);
        }
        case Ah[ 0 ] , Ah[ 1 ]:
        {
            if(Ah[ 0 ]) return GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Health pack!", 2500, 6);
            if(Ah[ 1 ]) return GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Armour pack!", 2500, 6);
            ahpicked[ playerid ][ 0 ] = true;
            ahpicked[ playerid ][ 1 ] = true;
        }
    }
    return 1;
}
..should work, it looks ugly aswell, but the conditions look more obvious with the switch/case. imo ^^
Reply
#6

Hm, weird.. i get these errors in the switch statement you gave me.

Код:
D:\Documents and Settings\usuario\Escritorio\Scripting 3x\gamemodes\fy_desert.pwn(336) : error 008: must be a constant expression; assumed zero
D:\Documents and Settings\usuario\Escritorio\Scripting 3x\gamemodes\fy_desert.pwn(341) : error 008: must be a constant expression; assumed zero
D:\Documents and Settings\usuario\Escritorio\Scripting 3x\gamemodes\fy_desert.pwn(346) : error 008: must be a constant expression; assumed zero
D:\Documents and Settings\usuario\Escritorio\Scripting 3x\gamemodes\fy_desert.pwn(351) : error 008: must be a constant expression; assumed zero
D:\Documents and Settings\usuario\Escritorio\Scripting 3x\gamemodes\fy_desert.pwn(356) : error 008: must be a constant expression; assumed zero
D:\Documents and Settings\usuario\Escritorio\Scripting 3x\gamemodes\fy_desert.pwn(361) : error 008: must be a constant expression; assumed zero
D:\Documents and Settings\usuario\Escritorio\Scripting 3x\gamemodes\fy_desert.pwn(366) : error 008: must be a constant expression; assumed zero
D:\Documents and Settings\usuario\Escritorio\Scripting 3x\gamemodes\fy_desert.pwn(371) : error 008: must be a constant expression; assumed zero
D:\Documents and Settings\usuario\Escritorio\Scripting 3x\gamemodes\fy_desert.pwn(376) : error 017: undefined symbol "Ah"
D:\Documents and Settings\usuario\Escritorio\Scripting 3x\gamemodes\fy_desert.pwn(376) : warning 215: expression has no effect
D:\Documents and Settings\usuario\Escritorio\Scripting 3x\gamemodes\fy_desert.pwn(376) : error 001: expected token: ";", but found "]"
D:\Documents and Settings\usuario\Escritorio\Scripting 3x\gamemodes\fy_desert.pwn(376) : error 029: invalid expression, assumed zero
D:\Documents and Settings\usuario\Escritorio\Scripting 3x\gamemodes\fy_desert.pwn(376) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


12 Errors.
Reply
#7

Won't even work since case statements require constants.
Reply
#8

Just compiled and noticed.. so any ideas of how can i fix it vince? sorry for bothering you.
Reply
#9

aaw indeed, those arent constants. IF you can assure that the same pickupids get used when creating them, then its ok to use constant values for checking. imagine the first pickup gets created and returns its id into the variable m4[0], as soon you know its value (returned pickupid), then you can start replacing them into the switch/case statements...

argh nvm all that crap above: use that one (you simply forgot to add the "pickupid==" to each to.be.checked value, so here it is:
pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == m4[ 0 ] || pickupid == m4[ 1 ] || pickupid == m4[ 2 ] || pickupid == m4[ 3 ])
    {
        GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~m4!", 2500, 6);
        GivePlayerWeapon(playerid, 31, 20);
    }
   
    else if(pickupid == Rocket)
    {
        GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Rocket launcher!", 2500, 6);
        GivePlayerWeapon(playerid, 35, 3);
    }
   
    else if(pickupid == Spaz[ 0 ] || pickupid == Spaz[ 1 ])
    {
        GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Spaz12!", 2500, 6);
        GivePlayerWeapon(playerid, 27, 20);
    }
   
    else if(pickupid == Tec9[ 0 ] || pickupid == Tec9[ 1 ] || pickupid == Tec9[ 2 ])
    {
        GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Tec9!", 2500, 6);
        GivePlayerWeapon(playerid, 32, 20);
    }
   
    else if(pickupid == Shotgun[ 0 ] || pickupid == Shotgun[ 1 ] )
    {
        GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Shotgun!", 2500, 6);
        GivePlayerWeapon(playerid, 25, 25);
    }
   
    else if(pickupid == sniper[ 0 ] || pickupid == sniper[ 1 ] || pickupid == sniper[ 2 ])
    {
        GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Sniper!", 2500, 6);
        GivePlayerWeapon(playerid, 34, 10);
    }
   
    else if(pickupid == Desert[ 0  ] || pickupid == Desert[ 1 ])
    {
        GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Desert!", 2500, 6);
        GivePlayerWeapon(playerid, 24, 13);
    }
   
    else if(pickupid == Uzi[ 0 ] || pickupid == Uzi[ 1 ])
    {
        GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Uzi!", 2500, 6);
        GivePlayerWeapon(playerid, 28, 50);
    }
   
    else if(pickupid == Ah[ 0 ])
    {
        GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Health pack!", 2500, 6);
        ahpicked[ playerid ][ 0 ] = true;
    }
    else if(pickupid == Ah[ 1 ])
    {
        GameTextForPlayer(playerid, "~n~~n~~n~~n~~w~~h~Armour pack!", 2500, 6);
        ahpicked[ playerid ][ 1 ] = true;
    }
    return 1;
}
"you forgot"? so did i. stupid me. who agrees? ^^

oh btw, the ahpicked-bug is fixed now. no more "return SendClientMessage()" before the ahpicked[]=true;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)