Question about a command! -
Twisted_Insane - 27.03.2012
'Sup? I've scripted a "/weaps"-command, which gives players ( level 1+ ) the option to get the info of their weapons, well, usually straight to see all the weapons the player has! But for some reason, whenever I check my own weapons, it won't show them, lol! There's just written "No weapons found!". When I'm buying myself a MP5, it otherwise would show my MP5 with the given ammo:
pawn Код:
CMD:weaps(playerid,params[])
{
if(PlayerInfo[playerid][pAdmin] >= 1)
{
new Target;
if(sscanf(params, "u", Target)) return SendClientMessage(playerid, COLOR_BLUEAQUA, "USAGE: /weaps [playerid]");
if(!IsPlayerConnected(Target))
return SendClientMessage(playerid, COLOR_RED,"ERROR: Player is not connected!");
new Count;
new x;
new string[128], string2[64];
new WeapName[24], slot, weap, ammo;
new name[MAX_PLAYER_NAME];
GetPlayerName(Target,name,sizeof(name));
format(string2,sizeof(string2),"_______|- %s's Weapons -|_______",name);
SendClientMessage(playerid,COLOR_YELLOW,string2);
for(slot = 0; slot < 14; slot++)
{
GetPlayerWeaponData(Target, slot, weap, ammo);
if( ammo != 0 && weap != 0)
Count++;
}
if(Count < 1) return SendClientMessage(playerid,COLOR_LIGHTBLUE,"No weapons found!");
if(Count >= 1)
{
for (slot = 0; slot < 14; slot++)
{
GetPlayerWeaponData(Target, slot, weap, ammo);
if( ammo != 0 && weap != 0)
{
GetWeaponName(weap, WeapName, sizeof(WeapName));
if(ammo == 65535 || ammo == 1)
format(string,sizeof(string),"%s%s (1)",string, WeapName);
else format(string,sizeof(string),"%s%s (%d)",string, WeapName, ammo);
x++;
}
if(x >= 5)
{
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
x = 0;
format(string, sizeof(string), "");
}
else format(string, sizeof(string), "%s, ", string);
}
}
if(x <= 4 && x > 0)
{
string[strlen(string)-3] = '.';
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
}
}
else return SendClientMessage(playerid,COLOR_RED,"ERROR: You need to be level 1 to use this command!");
return 1;
}
I think that "GetPlayerWeaponData" is not the function which is required, right?
Re: Question about a command! -
vyper - 27.03.2012
Use this:
pawn Код:
new ammo[12], guns[12], gunname[12][20]; // new variables
for(new i = 0; i < 12; i++) // storing data
{
GetPlayerWeaponData(playerid, i+1, guns[i], ammo[i]);
GetWeaponName(guns[i], gunname[i], 20);
}
// now you can format a string and show the stored data
This is a way that you can use.
Re: Question about a command! -
Twisted_Insane - 27.03.2012
Didn't get you, could you replace it with my command so I can understand it better?
Re: Question about a command! -
vyper - 27.03.2012
pawn Код:
CMD:weaps(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 1)
{
new string[128], ammo[12], guns[12], gunname[12][20], name[MAX_PLAYER_NAME];
new id = strval(params);
if(!strlen(params)) return SendClientMessage(playerid, -1, "ERROR: /weaps [playerid]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "This player is not connected.");
else
{
for(new i = 0; i < 12; i++)
{
GetPlayerWeaponData(id, i+1, guns[i], ammo[i]);
GetWeaponName(guns[i], gunname[i], 20);
}
GetPlayerName(id, name, sizeof(name));
format(string, sizeof(string), "%s's Weapons", name);
SendClientMessage(playerid, -1, string);
format(string, sizeof(string), "%s(0) - %s(%d) - %s(%d) - %s(%d) - %s(%d) - %s(%d)", gunname[0], gunname[1], ammo[1], gunname[2], ammo[2], gunname[3], ammo[3], gunname[4], ammo[4], gunname[5], ammo[5]);
SendClientMessage(playerid, -1, string);
format(string, sizeof(string), "%s(%d) - %s(%d) - %s(%d) - %s(0) - %s(0) - %s(0)", gunname[6], ammo[6], gunname[7], ammo[7], gunname[8], ammo[8], gunname[9], gunname[10], gunname[11]);
SendClientMessage(playerid, -1, string);
}
}
else SendClientMessage(playerid, -1, "You need to be an admin with level 1+");
return 1;
}
Re: Question about a command! -
Twisted_Insane - 27.03.2012
Okay, thank you! Only one more problem: I've made a few stocks and functions, so if a player will perform a command, all the admins level 2 + will receive a message which command the player performed! If an admin performed a command, the message will be blue, if a player did, the message will be grey! But for some reason again, now any command I type, I'm getting the message "SERVER: Unknown command". The commands and the rest are working fine, and I can see which command has been performed:
pawn Код:
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
if(success)
{
if(PlayerInfo[playerid][pAdmin] == 0)
{
SendCMDToAdmins(playerid, cmdtext);
}
else if(PlayerInfo[playerid][pAdmin] >= 1)
{
SendCMD2ToAdmins(playerid, cmdtext);
}
}
if(!success)
{
if(PlayerInfo[playerid][pAdmin] == 0)
{
SendCMDToAdmins(playerid, cmdtext);
}
else if(PlayerInfo[playerid][pAdmin] >= 1)
{
SendCMD2ToAdmins(playerid, cmdtext);
}
}
}
Re: Question about a command! -
vyper - 27.03.2012
I remember having this issue few years ago.. and I think I fixed it after I returned a diffrent value somewhere ... but I don't quite remember if this is the cause tho' you can try anyway
Re: Question about a command! -
Twisted_Insane - 27.03.2012
The "/weaps"-command works so far, but it won't show me the first weapon! I spawned with a deagle, spas and MP5! It shows me something like that:
Deagle ( 0 ), Spas ( 350 ), MP5 ( 350 )
Why is the value from the deagle '0', even though I have about 350 ammo in it?
pawn Код:
CMD:weaps(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 1)
{
new string[128], ammo[12], guns[12], gunname[12][20], name[MAX_PLAYER_NAME];
new id;
if(sscanf(params, "u", id)) return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /weaps [playerid]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_RED, "This player is not connected!");
else
{
for(new i = 0; i < 12; i++)
{
GetPlayerWeaponData(id, i+1, guns[i], ammo[i]);
GetWeaponName(guns[i], gunname[i], 20);
}
GetPlayerName(id, name, sizeof(name));
format(string, sizeof(string), "_______|- %s's Weapons -|_______", name);
SendClientMessage(playerid, TEAM_GROVE_COLOR, string);
format(string, sizeof(string), "%s(0) - %s(%d) - %s(%d) - %s(%d) - %s(%d) - %s(%d)", gunname[0], gunname[1], ammo[1], gunname[2], ammo[2], gunname[3], ammo[3], gunname[4], ammo[4], gunname[5], ammo[5]);
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
format(string, sizeof(string), "%s(%d) - %s(%d) - %s(%d) - %s(0) - %s(0) - %s(0)", gunname[6], ammo[6], gunname[7], ammo[7], gunname[8], ammo[8], gunname[9], gunname[10], gunname[11]);
SendClientMessage(playerid, COLOR_YELLOW, string);
format(string, sizeof(string), "________________________________");
SendClientMessage(playerid, TEAM_GROVE_COLOR, string);
}
}
else return SendClientMessage(playerid, COLOR_RED, "You need to be level 1 to use that command!");
return 1;
}
Re: Question about a command! -
vyper - 28.03.2012
Oh that's because I did a little mistake with the variables order
Try this:
pawn Код:
CMD:weaps(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 1)
{
new string[128], ammo[12], guns[12], gunname[12][20], name[MAX_PLAYER_NAME];
new id;
if(sscanf(params, "u", id)) return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /weaps [playerid]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_RED, "This player is not connected!");
else
{
for(new i = 0; i < 12; i++)
{
GetPlayerWeaponData(id, i+1, guns[i], ammo[i]);
GetWeaponName(guns[i], gunname[i], 20);
}
GetPlayerName(id, name, sizeof(name));
format(string, sizeof(string), "_______|- %s's Weapons -|_______", name);
SendClientMessage(playerid, TEAM_GROVE_COLOR, string);
format(string, sizeof(string), "%s(%d) - %s(%d) - %s(%d) - %s(%d) - %s(%d) - %s(%d)", gunname[0], ammo[0], gunname[1], ammo[1], gunname[2], ammo[2], gunname[3], ammo[3], gunname[4], ammo[4], gunname[5], ammo[5]); // edited line - here was the problem at the vars
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
format(string, sizeof(string), "%s(%d) - %s(%d) - %s(%d) - %s(%d) - %s(%d) - %s(%d)", gunname[6], ammo[6], gunname[7], ammo[7], gunname[8], ammo[8], gunname[9], ammo[9], gunname[10], ammo[10], gunname[11], ammo[11]); // edited line - here was the problem at the vars
SendClientMessage(playerid, COLOR_YELLOW, string);
format(string, sizeof(string), "________________________________");
SendClientMessage(playerid, TEAM_GROVE_COLOR, string);
}
}
else return SendClientMessage(playerid, COLOR_RED, "You need to be level 1 to use that command!");
return 1;
}