Need help with pickup pickups using keys
#1

Hey guys I have this code:
pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    OnWeaponDropPickup(playerid, pickupid)
    return 1;
}

stock OnWeaponDropPickup(playerid, pickupid)
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        for(new a=0; a<13; a++)
        {
            if(WeaponDrop[i][a] == pickupid)
            {
                WeaponDrop[i][a] = -1;
                DestroyPickup(pickupid);
                GivePlayerWeapon(playerid, WeaponData[i][a][0], WeaponData[i][a][1]);
                WeaponData[i][a][0] = -1;
                WeaponData[i][a][1] = -1;
            }
        }
        if(WeaponDrop[i][13] == pickupid)
        {
            WeaponDrop[i][13] = -1000;
            DestroyPickup(pickupid);
            GivePlayerMoney(playerid, 1000);
            WeaponData[i][13][0] = -1;
            WeaponData[i][13][1] = -1;
        }
    }

    return 1;
}
I want to make it like when i press key_crouch it gives me the weapon not when I enter it, Can anyone help me at this. and also I dont want it like I press crouch then i enter and get the pickup, simply to stand in the pickup and press c. I am unable to put the OnWeaponDropPickup(playerid, pickupid) under onPlayerKeyStateChange because it uses pickupid. Please help
Reply
#2

When they enter a pickup, save it's ID in a variable. When they press KEY_CROUCH, give them the pickup (you have the ID stored in a variable). You may also want to check if they're still near it.
Reply
#3

Just add a variable under OnPlayerKeyStateChange with a timer.

pawn Код:
new player_Crouchbutton[MAX_PLAYERS];

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
      if(newkeys & KEY_CROUCH) && !(oldkeys & KEY_CROUCH))
      {
            if(player_Crouchbutton[playerid] == 0)
            {
                  player_Crouchbutton[playerid] = 1;
                  SetTimerEx("OnCrouchButton", 2000, false, "i", playerid);
            }
      }
}
forward OnCrouchButton(playerid);
public OnCrouchButton(playerid)
{
      player_Crouchbutton[playerid] = 0;
}
And then, edit your code like this;

pawn Код:
stock OnWeaponDropPickup(playerid, pickupid)
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        for(new a=0; a<13; a++)
        {
            if(WeaponDrop[i][a] == pickupid && player_Crouchbutton[playerid] == 1)
            {
                WeaponDrop[i][a] = -1;
                DestroyPickup(pickupid);
                GivePlayerWeapon(playerid, WeaponData[i][a][0], WeaponData[i][a][1]);
                WeaponData[i][a][0] = -1;
                WeaponData[i][a][1] = -1;
            }
        }
        if(WeaponDrop[i][13] == pickupid && player_Crouchbutton[playerid] == 1)
        {
            WeaponDrop[i][13] = -1000;
            DestroyPickup(pickupid);
            GivePlayerMoney(playerid, 1000);
            WeaponData[i][13][0] = -1;
            WeaponData[i][13][1] = -1;
        }
    }

    return 1;
}
Please note that your pickup type needs to be 1 for get that working.
Reply
#4

but the OnWeaponDropPickup still get called when i enter pickup which means if i am standing in the pickup and press crouch nothing happns, I have to press it then re-enter the pickup before it becomes 0 again?
Reply
#5

Not really. If your pickup type is 1, the callback gets called every moment your character updates when you keep standing in the pickup. That's why I told it's going to work only on pickup type 1.
Reply
#6

Quote:

Not really. If your pickup type is 1, the callback gets called every moment your character updates when you keep standing in the pickup. That's why I told it's going to work only on pickup type 1.

Thank you, its working good
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)