weapon drop problem
#1

Hi I'm using this weapon drop fs it's good but there is a problem with the ammo. When I tried to pickup a weapon that has an ammo it give different ammo not what I dropped.

Let say I have minigun with 500 ammo. I let myself get killed and after I tried to pickup my minigun the ammo became 1500. So how to make it back to normal ammo 500?

Код HTML:
#define <a_samp>//this always defined 


new DropLimit = 4; // above
new DeleteTime = 20; //above

public OnPlayerDeath(playerid, killerid, reason)
 {
  DropPlayerWeapons(playerid); //here, we send that, when you die, you will drop your weaps (sorry da english)
  return 1;
 }


forward DropPlayerWeapons(playerid);
public DropPlayerWeapons(playerid)
{
    new playerweapons[13][2];
    new Float:x,Float:y,Float:z;
    GetPlayerPos(playerid, x, y, z);//here gets your position..!

    for(new i=0; i<13; i++)
    {
        GetPlayerWeaponData(playerid, i, playerweapons[i][0], playerweapons[i][1]);
        new model = GetWeaponType(playerweapons[i][0]);// this to get, what weapons are you using in the moment !
        new times = floatround(playerweapons[i][1]/10.0001);
        new Float:X = x + (random(3) - random(3));
        new Float:Y = y + (random(3) - random(3));
        if(playerweapons[i][1] != 0 && model != -1)
        {
            if(times > DropLimit) times = DropLimit;
            for(new a=0; a<times; a++)
            {
                new pickupid = CreatePickup(model, 3, X, Y, z);//this is the place where you die, there you will drop your weapons !
                SetTimerEx("DeletePickup", DeleteTime*1000, false, "d", pickupid);//there you may change the time 1 *1000 to *19283718293712 whatever...!
            }
        }
    }
    return 1;
}



forward DeletePickup(pickupid);
public DeletePickup(pickupid)
{
    DestroyPickup(pickupid);
    return 1;
}



GetWeaponType(weaponid) //explainin' 
{
    switch(weaponid)
    {
        case 1: return 331; case 2: return 333; case 3: return 334; // this is to define the weapons
        case 4: return 335; case 5: return 336; case 6: return 337;
        case 7: return 338; case 8: return 339; case 9: return 341;
        case 10: return 321; case 11: return 322; case 12: return 323;
        case 13: return 324; case 14: return 325; case 15: return 326;
        case 16: return 342; case 17: return 343; case 18: return 344;
        case 22: return 346; case 23: return 347; case 24: return 348;
        case 25: return 349; case 26: return 350; case 27: return 351;
        case 28: return 352; case 29: return 353; case 30: return 355;
        case 31: return 356; case 32: return 372; case 33: return 357;
        case 34: return 358; case 35: return 359; case 36: return 360;
        case 37: return 361; case 38: return 362; case 39: return 363;
        case 41: return 365; case 42: return 366; case 46: return 371; //example, this case is the id 46 is the parachute, we will drop the parachute, that's if  you got one
    }
    return -1;
}
Reply
#2

This is where the weapon drop.

Код HTML:
forward DropPlayerWeapons(playerid);
public DropPlayerWeapons(playerid)
{
    new playerweapons[13][2];
    new Float:x,Float:y,Float:z;
    GetPlayerPos(playerid, x, y, z);//here gets your position..!

    for(new i=0; i<13; i++)
    {
        GetPlayerWeaponData(playerid, i, playerweapons[i][0], playerweapons[i][1]);
        new model = GetWeaponType(playerweapons[i][0]);// this to get, what weapons are you using in the moment !
        new times = floatround(playerweapons[i][1]/10.0001);
        new Float:X = x + (random(3) - random(3));
        new Float:Y = y + (random(3) - random(3));
        if(playerweapons[i][1] != 0 && model != -1)
        {
            if(times > DropLimit) times = DropLimit;
            for(new a=0; a<times; a++)
            {
                new pickupid = CreatePickup(model, 3, X, Y, z);//this is the place where you die, there you will drop your weapons !
                SetTimerEx("DeletePickup", DeleteTime*1000, false, "d", pickupid);//there you may change the time 1 *1000 to *19283718293712 whatever...!
            }
        }
    }
    return 1;
}
Reply
#3

The thing with pickups is, if you create a normal pickup and the model is an M4 for example, it will automatically give ammo to the player regardless. The only way to fix this is to set the pickup type to 1. As read here on the wiki:
Quote:
Originally Posted by SA-MP Wiki
Certain pickup types come with 'automatic responses', for example using an M4 model in the pickup will automatically give the player the weapon and some ammo. For fully scripted pickups, type 1 should be used.
This code should work properly. You may already have some code in place, so feel free to replace it with this respectively:
pawn Код:
#include <a_samp>//this always defined

#define DROP_LIMIT      1000 //Not sure what exactly this is, but my assumption is that you're using for the maximum amount of ammo that can be dropped.
#define DELETE_TIME     20

//These variables must be global if you are going to use them in multiple callbacks. You cannot use a variable from DropPlayerWeapons in OnPlayerPickUpPickup.
new weaponspickup[MAX_PLAYERS][13]; //Used to identify the weapon dropped by the certain player.
new weaponsamount[MAX_PLAYERS][13][2]; //Used to get the amount of ammo in the weapon once it is dropped.

public OnPlayerDeath(playerid, killerid, reason)
{
    DropPlayerWeapons(playerid); //here, we send that, when you die, you will drop your weaps (sorry da english)
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    for(new i = 0; i < 11; i++)
    {
        DeletePickup(weaponspickup[playerid][i]);
    }
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    for(new i = 0; i < MAX_PLAYERS; i++) //Foreach would be the better option here.
    {
        for(new j = 0; j < 11; j++) //As much as a loop inside a loop pains me to see, this may be the only way.
        {
            if(pickupid == weaponspickup[i][j])
            {
                GivePlayerWeapon(playerid, weaponsamount[i][j][0], weaponsamount[i][j][1]);
                DeletePickup(weaponspickup[i][j]);
                break;
            }
        }
    }
    return 1;
}

stock DropPlayerWeapons(playerid)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    new weaponid, ammo, model;
    for(new i = 0; i < 11; i++)
    {
        GetPlayerWeaponData(playerid, i, weaponid, ammo);
        weaponsamount[playerid][i][0] = weaponid;
        model = GetWeaponType(weaponid);
        if(model == -1) continue;
        ammo = floatround((ammo / 10));
        new Float:X = x + (random(3) - random(3));
        new Float:Y = y + (random(3) - random(3));
        if(ammo > DROP_LIMIT) ammo = DROP_LIMIT;
        weaponsamount[playerid][i][1] = ammo;
        weaponspickup[playerid][i] = CreatePickup(model, 1, X, Y, z);
        SetTimerEx("DeletePickup", DELETE_TIME * 1000, false, "i", weaponspickup[playerid][i]);
    }
    ResetPlayerWeapons(playerid);
    return 1;
}

forward DeletePickup(pickupid);
public DeletePickup(pickupid)
{
    DestroyPickup(pickupid);
    return 1;
}

stock GetWeaponType(weaponid) //explainin'
{
    switch(weaponid)
    {
        case 1: return 331; case 2: return 333; case 3: return 334; // this is to define the weapons
        case 4: return 335; case 5: return 336; case 6: return 337;
        case 7: return 338; case 8: return 339; case 9: return 341;
        case 10: return 321; case 11: return 322; case 12: return 323;
        case 13: return 324; case 14: return 325; case 15: return 326;
        case 16: return 342; case 17: return 343; case 18: return 344;
        case 22: return 346; case 23: return 347; case 24: return 348;
        case 25: return 349; case 26: return 350; case 27: return 351;
        case 28: return 352; case 29: return 353; case 30: return 355;
        case 31: return 356; case 32: return 372; case 33: return 357;
        case 34: return 358; case 35: return 359; case 36: return 360;
        case 37: return 361; case 38: return 362; case 39: return 363;
        case 41: return 365; case 42: return 366; case 46: return 371; //example, this case is the id 46 is the parachute, we will drop the parachute, that's if  you got one
    }
    return -1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)