help with weapon drop
#1

how i do that when i kill someone he drop his weapon and i can take it
Reply
#2

Well You'd need to find the OnPlayerDeath function in your gamemode script (or filterscript) and create 3 float variables to save the location of the player
e.g.
pawn Код:
OnPlayerDeath(playerid,killerid,reason)
{
  new Float:PlayerX;
  new Float:PlayerY;
  new Float:PlayerZ;
}
Then you would need to save the dead player's location using those variables
e.g.
pawn Код:
OnPlayerDeath(playerid,killerid,reason)
{
  new Float:PlayerX;
  new Float:PlayerY;
  new Float:PlayerZ;
  GetPlayerPos(playerid,PlayerX,PlayerY,PlayerZ);
}
Then create a conditional to check if the dying player even has a weapon to drop and inside it use a function to turn the weaponid to it's respective modelid for the pickup. The function will return the value of the modelid and therefore needs to be saved to a variable. The function needs to be placed outside any other functions
e.g.
pawn Код:
WeaponToModel(reason)
{
  switch(reason)
  {
    case 2:
    {
      return 333;
    }
    case 3:
    {
      return 334;
    }
    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 40:
    {
      return 364;
    }
    case 41:
    {
      return 365;
    }
    case 42:
    {
      return 366;
    }
    case 43:
    {
      return 367;
    }
    case 44:
    {
      return 368;
    }
    case 45:
    {
      return 369;
    }
    case 46:
    {
      return 371;
    }
  }
}
pawn Код:
OnPlayerDeath(playerid,killerid,reason)
{
  new Float:PlayerX;
  new Float:PlayerY;
  new Float:PlayerZ;
  GetPlayerPos(playerid,PlayerX,PlayerY,PlayerZ);
  if(GetPlayerWeapon(playerid)>1)
  {
    new WeaponModel = WeaponToModel(reason);
  }
}
Then you need to use the variable to drop the object in the exact place the player died making sure you use the correct parameters in the createpickup line

pawn Код:
OnPlayerDeath(playerid,killerid,reason)
{
  new Float:PlayerX;
  new Float:PlayerY;
  new Float:PlayerZ;
  GetPlayerPos(playerid,PlayerX,PlayerY,PlayerZ);
  if(GetPlayerWeapon(playerid)>1)
  {
    new WeaponModel = WeaponToModel(reason);
    CreatePickup(WeaponModel,3,PlayerX,PlayerY,PlayerZ);
  }
}
Now when a player dies the weapon the player was carrying is dropped in his place. Be weary though, there is a max amount of objects that one player can see, also other players will be able to pick it up. Creating a script that makes it so that only one person can pick up it is a longer tutorial =p

In short, final product
pawn Код:
WeaponToModel(reason)
{
  switch(reason)
  {
    case 2:
    {
      return 333;
    }
    case 3:
    {
      return 334;
    }
    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 40:
    {
      return 364;
    }
    case 41:
    {
      return 365;
    }
    case 42:
    {
      return 366;
    }
    case 43:
    {
      return 367;
    }
    case 44:
    {
      return 368;
    }
    case 45:
    {
      return 369;
    }
    case 46:
    {
      return 371;
    }
  }
}

OnPlayerDeath(playerid,killerid,reason)
{
  new Float:PlayerX;
  new Float:PlayerY;
  new Float:PlayerZ;
  GetPlayerPos(playerid,PlayerX,PlayerY,PlayerZ);
  if(GetPlayerWeapon(playerid)>1)
  {
    new WeaponModel = WeaponToModel(reason);
    CreatePickup(WeaponModel,3,PlayerX,PlayerY,PlayerZ);
  }
}
Reply
#3

ok tnx man and how i do that the money on player when someone kill him his money drop also?
Reply
#4

Samething, but instead of GetPlayerWeapon, do GetPlayerMoney, and You wouldn't need to find the weapon model, just use the cash model (don't remember)
Reply
#5

there is a little mistake.In your script the pickup will be the weapon of the killer
and the dying player pick up the dropped weapon...

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
  new Float:X;
  new Float:Y;
  new Float:Z;
  GetPlayerPos(playerid,X,Y,Z);
  if(GetPlayerWeapon(playerid)>1)
  {
    new WeaponModel = WeaponToModel(GetPlayerWeapon(playerid));
    CreatePickup(WeaponModel,3,X-2,Y,Z);
  }
}
(i use Float:X... because in my script there were allready a Float:PlayerX...)

but how can i change ammo? the dropped weapons only had 10 ammo...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)