/Dropgun doesn't create the object
#5

and here is updated version without unnecessary arrays in enum

pawn Код:
#define MAX_OBJ 50 // Limit
// -----------------------------------------------------------------------------
enum dGunEnum
{
    ObjData[3]
};
new dGunData[MAX_OBJ][dGunEnum];

CMD:dropgun(playerid, params[])
{
    if(GetPlayerState(playerid) != PLAYER_STATE_ONFOOT) return 1;
    new GunID = GetPlayerWeapon(playerid);
    new GunAmmo = GetPlayerAmmo(playerid);
    if(GunID > 0 && GunAmmo > 0)
    {
        new slot = -1;
        for(new i = 0; i < MAX_OBJ; i++)
            if(dGunData[i][ObjData][0] == 0)
            {
                slot = i;
                break;
            }

        if(slot < 0) return SendClientMessage(playerid, 0x33AA3300, "You can not throw weapons at the moment, try back later!");
        RemovePlayerWeapon(playerid, GunID);
        dGunData[slot][ObjData][1] = GunID;
        dGunData[slot][ObjData][2] = GunAmmo;
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        dGunData[slot][ObjData][0] = CreateObject(GunObjects[GunID], x, y, z-1.0, 93.7, 120.0, 120.0);
        new buffer[50];
        format(buffer, sizeof(buffer), "You threw %s", GunNames[dGunData[slot][ObjData][1]]);
        SendClientMessage(playerid, 0x33AA3300, buffer);
    }
    return 1;
}

CMD:pickupgun(playerid, params[])
{
    if(GetPlayerState(playerid) != PLAYER_STATE_ONFOOT) return 1;

    new slot = -1;
    new Float:x, Float:y, Float:z;
    for(new i = 0; i < MAX_OBJ; i++)
        if(dGunData[i][ObjData][0] > 0 && IsValidObject(dGunData[i][ObjData][0]))
        {
            GetObjectPos(dGunData[i][ObjData][0], x, y, z);
            if(IsPlayerInRangeOfPoint(playerid, 5.0, x, y, z))
            {
                slot = i;
                break;
            }
        }

    if(slot < 0) return SendClientMessage(playerid, 0x33AA3300, "You are not near the weapon which you can pick up!");
    DestroyObject(dGunData[slot][ObjData][0]);
    GiveDodWeapon(playerid, dGunData[slot][ObjData][1], dGunData[slot][ObjData][2]);
    dGunData[slot][ObjData][0] = 0;
    new buffer[50];
    format(buffer, sizeof(buffer), "You picked up %s", GunNames[dGunData[slot][ObjData][1]]);
    SendClientMessage(playerid, 0x33AA3300, buffer);
    return 1;
}
Reply


Messages In This Thread
/Dropgun doesn't create the object - by NeXoR - 03.04.2016, 21:51
Re: /Dropgun doesn't create the object - by NeXoR - 03.04.2016, 22:34
Re: /Dropgun doesn't create the object - by Jefff - 03.04.2016, 22:51
Re: /Dropgun doesn't create the object - by NeXoR - 03.04.2016, 22:56
Re: /Dropgun doesn't create the object - by Jefff - 03.04.2016, 22:59

Forum Jump:


Users browsing this thread: 1 Guest(s)