Givegun command. -
Strier - 25.02.2013
pawn Код:
CMD:givegun(playerid, params[]) {
new tmp[256], tmp2[256], tmp3[256], Index; tmp = strtok(params, Index), tmp2 = strtok(params,Index), tmp3 = strtok(params, Index);
if(isnull(tmp) || isnull(tmp3)) return SendClientMessage(playerid, -1, "Usage: /givegun [playerid] [ammo]");
new player1 = strval(tmp), weap, ammo, WeapName[32], string[128];
if(!IsNumeric(tmp2)) weap = GetWeaponIDFromName(tmp2); else weap = strval(tmp2);
if(IsPlayerConnected(player1) && player1 != INVALID_PLAYER_ID)
{
GetWeaponName(weap, WeapName, 32);
WeapName[32] = GetPlayerWeapon(playerid);
format(string, sizeof(string), "You gave %s a %s with %d rounds of ammo!" GetName(player1), WeapName, ammo);
SendClientMessage(playerid, COLOR_YELLOW, string);
if(player1 != playerid)
{
format(string, sizeof(string), "%s gave you a %s with %d rounds of ammo", GetName(playerid), WeapName, ammo);
SendClientMessage(playerid, COLOR_YELLOW, string);
}
return GivePlayerWeapon(player1, weap, ammo);
}else return SendClientMessage(playerid, COLOR_YELLOW, "[ * ] This player seems not to be online!");
}
Errors:
pawn Код:
C:\Users\Guille\Desktop\Samp scripting\Server23\server12\gamemodes\TD.pwn(9984) : warning 204: symbol is assigned a value that is never used: "str2"
C:\Users\Guille\Desktop\Samp scripting\Server23\server12\gamemodes\TD.pwn(10048) : error 032: array index out of bounds (variable "WeapName")
C:\Users\Guille\Desktop\Samp scripting\Server23\server12\gamemodes\TD.pwn(10049) : error 001: expected token: "-string end-", but found "-identifier-"
C:\Users\Guille\Desktop\Samp scripting\Server23\server12\gamemodes\TD.pwn(10049) : warning 215: expression has no effect
C:\Users\Guille\Desktop\Samp scripting\Server23\server12\gamemodes\TD.pwn(10049) : warning 215: expression has no effect
C:\Users\Guille\Desktop\Samp scripting\Server23\server12\gamemodes\TD.pwn(10049) : error 001: expected token: ";", but found ")"
C:\Users\Guille\Desktop\Samp scripting\Server23\server12\gamemodes\TD.pwn(10049) : error 029: invalid expression, assumed zero
C:\Users\Guille\Desktop\Samp scripting\Server23\server12\gamemodes\TD.pwn(10049) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
Lines
pawn Код:
format(string, sizeof(string), "You gave %s a %s with %d rounds of ammo!" GetName(player1), WeapName, ammo);
WeapName[32] = GetPlayerWeapon(playerid);
thanks in advanced.
Re: Givegun command. -
RoboN1X - 25.02.2013
pawn Код:
GetWeaponName(weap, WeapName, 32);
WeapName[32] = GetPlayerWeapon(playerid);
You already get the weapon name, the WeapName size is just 32 so you just can use WeapName[0] to WeapName[31], btw why are you returning the weapon id of playerid that is using the command to be placed in the string character index number 32?
pawn Код:
format(string, sizeof(string), "You gave %s a %s with %d rounds of ammo!" GetName(player1), WeapName, ammo);
also you missed comma after the double quotes.
So, try change them to
pawn Код:
CMD:givegun(playerid, params[]) {
new tmp[256], tmp2[256], tmp3[256], Index; tmp = strtok(params, Index), tmp2 = strtok(params,Index), tmp3 = strtok(params, Index);
if(isnull(tmp) || isnull(tmp3)) return SendClientMessage(playerid, -1, "Usage: /givegun [playerid] [ammo]");
new player1 = strval(tmp), weap, ammo, WeapName[32], string[128];
if(!IsNumeric(tmp2)) weap = GetWeaponIDFromName(tmp2); else weap = strval(tmp2);
if(IsPlayerConnected(player1) && player1 != INVALID_PLAYER_ID)
{
GetWeaponName(weap, WeapName, 32);
format(string, sizeof(string), "You gave %s a %s with %d rounds of ammo!", GetName(player1), WeapName, ammo);
SendClientMessage(playerid, COLOR_YELLOW, string);
if(player1 != playerid)
{
format(string, sizeof(string), "%s gave you a %s with %d rounds of ammo", GetName(playerid), WeapName, ammo);
SendClientMessage(playerid, COLOR_YELLOW, string);
}
return GivePlayerWeapon(player1, weap, ammo);
}else return SendClientMessage(playerid, COLOR_YELLOW, "[ * ] This player seems not to be online!");
}
i deleted the WeapName[32] = GetPlayerWeapon and added the missed comma
Not yet tested, hope it helps
Respuesta: Givegun command. -
Strier - 26.02.2013
Huh... it's supposed to be working with two tmp's, tmp and tmp3, but it uses 3... AND if i'm holding a gun the format sends a random gun, (I mean not the one i'm holding).. new code:
pawn Код:
CMD:givegun(playerid, params[]) {
new tmp[256], tmp2[256], tmp3[256], Index; tmp = strtok(params, Index), tmp2 = strtok(params,Index), tmp3 = strtok(params, Index);
if(isnull(tmp) || isnull(tmp3)) return SendClientMessage(playerid, -1, "Usage: /givegun [playerid] [ammo]");
new player1 = strval(tmp), weap, ammo, WeapName[32], string[128];
if(!IsNumeric(tmp2)) weap = GetWeaponIDFromName(tmp2); else weap = strval(tmp2);
if(!IsPlayerConnected(player1) && player1 != INVALID_PLAYER_ID)
{
GetPlayerWeapon(playerid);
GetWeaponName(weap, WeapName, 32);
format(string, sizeof(string), "You gave %s a %s with %d rounds of ammo!", GetName(player1), WeapName, ammo);
SendClientMessage(playerid, COLOR_YELLOW, string);
if(player1 != playerid)
{
format(string, sizeof(string), "%s gave you a %s with %d rounds of ammo", GetName(playerid), WeapName, ammo);
SendClientMessage(playerid, COLOR_YELLOW, string);
}
return GivePlayerWeapon(player1, weap, ammo);
}else return SendClientMessage(playerid, COLOR_YELLOW, "[ * ] This player seems not to be online!");
}