SA-MP Forums Archive
givegun command help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: givegun command help (/showthread.php?tid=546022)



givegun command help - Rabea - 12.11.2014

hi, i'm doing givegun command, but its not working idk why, anyone can fix it?
this command if i did /givegun [playerid] [bullets] it will give another player same weapon with bullets, and the player that gave the another player, will lose just bullets.

pawn Код:
CMD:givegun(playerid,params[])
{
  new id, wam;
  if(sscanf(params, "ui", id, wam))return SendClientMessage(playerid,-1,"usage: /givegun [playerid] [bullets]");
  if(id == INVALID_PLAYER_ID)return SendClientMessage(playerid,-1,"invalid player id!");
  if(GetPlayerWeapon(playerid) == 0)return SendClientMessage(playerid, -1, "You have no weapon in your hand you could pass!");
  if(GetPlayerAmmo(playerid) < wam)return SendClientMessage(playerid,-1,"You do not have enough Munnition");
  GivePlayerWeapon(id, GetPlayerWeapon(playerid), wam);
  SetPlayerAmmo(playerid, GetPlayerAmmo(playerid) -wam); // this line
  new string[128], sendername[24], sendername1[24], weaponname[24];
  GetPlayerName(playerid, sendername, 24),GetPlayerName(id, sendername1, 24), GetWeaponName(GetPlayerWeapon(playerid), weaponname, 24);
  format(string, sizeof(string), "Player %s has given you the weapon %s with %i each shot!", sendername, weaponname, wam);
  SendClientMessage(id, -1, string);
  format(string, sizeof(string), "You have the players  %s %s handed over the weapon with each shot i%",sendername1, weaponname, wam);
  SendClientMessage(playerid,-1,string);
  return 1;
}



pawn Код:
warning 202: number of arguments does not match definition



Re: givegun command help - Rabea - 12.11.2014

okay its working fine, but i added isplayernearplayer, but when i try to /givegun it says " player is too far away " even if he is near me
pawn Код:
CMD:givegun(playerid,params[])
{
  new id, playerb, wam;
  if(sscanf(params, "ui", id, wam))return SendClientMessage(playerid,-1,"usage: /givegun [playerid] [bullets]");
  if(id == INVALID_PLAYER_ID)return SendClientMessage(playerid,-1,"invalid player id!");
  if(GetPlayerWeapon(playerid) == 0)return SendClientMessage(playerid, -1, "You have no weapon in your hand you could pass!");
  if(!IsPlayerNearPlayer(playerid, playerb, 5)) return SendClientMessage(playerid, COLOR_GREY, "You are too far away from that player.");
  if(GetPlayerAmmo(playerid) < wam)return SendClientMessage(playerid,-1,"You do not have enough Munnition");
  GiveZaiatWeapon(id, GetPlayerWeapon(playerid), wam);
  SetPlayerAmmo(playerid, GetPlayerWeapon(playerid), GetPlayerAmmo(playerid) - wam);
  new string[128], sendername[24], sendername1[24], weaponname[24];
  GetPlayerName(playerid, sendername, 24),GetPlayerName(id, sendername1, 24), GetWeaponName(GetPlayerWeapon(playerid), weaponname, 24);
  format(string, sizeof(string), "* %s has gave %s a %s with $s bullets.", NORPN(playerb), NORPN(playerid), weaponname, wam);
  SendNearbyMessage(playerid, 6, string, COLOR_LIGHTBLUE, COLOR_LIGHTBLUE, COLOR_LIGHTBLUE, COLOR_LIGHTBLUE, COLOR_LIGHTBLUE);
  /*format(string, sizeof(string), "Player %s has given you the weapon %s with %i each shot!", sendername, weaponname, wam);
  SendClientMessage(id, -1, string);
  format(string, sizeof(string), "You have the players  %s %s handed over the weapon with each shot i%",sendername1, weaponname, wam);
  SendClientMessage(playerid,COLOR_GREY,string);*/

  return 1;
}
can u help?


Re: givegun command help - Ahmad45123 - 12.11.2014

Code of the function: IsPlayerNearPlayer ?


Re: givegun command help - Rabea - 12.11.2014

i don't understand what you mean -_- i'm not good with scripting..


Re: givegun command help - Rabea - 12.11.2014

its working only at interiors xD


Re: givegun command help - Quickie - 12.11.2014

try this one dude
pawn Код:
CMD:givegun(playerid,params[])
{
  new id, playerb, wam;
  if(sscanf(params, "ui", id, wam))return SendClientMessage(playerid,-1,"usage: /givegun [playerid] [bullets]");
  if(id == INVALID_PLAYER_ID)return SendClientMessage(playerid,-1,"invalid player id!");
  if(GetPlayerWeapon(playerid) == 0)return SendClientMessage(playerid, -1, "You have no weapon in your hand you could pass!");
  if(!IsPlayerNearPlayer(playerid, id, 5)) return SendClientMessage(playerid, COLOR_GREY, "You are too far away from that player."); // <<<<<<<<<<<<<<<<<<<<
  if(GetPlayerAmmo(playerid) < wam)return SendClientMessage(playerid,-1,"You do not have enough Munnition");
  GiveZaiatWeapon(id, GetPlayerWeapon(playerid), wam);
  SetPlayerAmmo(playerid, GetPlayerWeapon(playerid), GetPlayerAmmo(playerid) - wam);
  new string[128], sendername[24], sendername1[24], weaponname[24];
  GetPlayerName(playerid, sendername, 24),GetPlayerName(id, sendername1, 24), GetWeaponName(GetPlayerWeapon(playerid), weaponname, 24);
  format(string, sizeof(string), "* %s has gave %s a %s with $s bullets.", NORPN(playerb), NORPN(playerid), weaponname, wam);
  SendNearbyMessage(playerid, 6, string, COLOR_LIGHTBLUE, COLOR_LIGHTBLUE, COLOR_LIGHTBLUE, COLOR_LIGHTBLUE, COLOR_LIGHTBLUE);
  /*format(string, sizeof(string), "Player %s has given you the weapon %s with %i each shot!", sendername, weaponname, wam);
  SendClientMessage(id, -1, string);
  format(string, sizeof(string), "You have the players  %s %s handed over the weapon with each shot i%",sendername1, weaponname, wam);
  SendClientMessage(playerid,COLOR_GREY,string);*/

  return 1;
}
where did "playerb" come from?


Re: givegun command help - Rabea - 12.11.2014

Works thanks both <3
+rep