Quote:
Originally Posted by dr.pepper
dcmd
Try this:
On Callback: OnPlayerCommandText:
pawn Код:
dcmd(giveweapon,10,cmdtext);
Somewhere In your Script:
pawn Код:
dcmd_giveweapon(playerid, cmdtext[]) { new tmp[256], index; new lookupid, weapon, wname[64]; tmp = strtok(cmdtext, index); if (!strlen(tmp)) return SendClientMessage(playerid, 0xFF444499,"/givegun <playerid> <gunid>"); lookupid = strval(tmp); weapon = strval(tmp); if (!IsPlayerConnected(lookupid)) { return SendClientMessage(playerid, 0xFF444499, "Player is not connected."); } if (weapon < 1 || weapon > 46) return SendClientMessage(playerid, 0xFF444499, "Invalid weapon ID, valid id's are between 0 and 46"); GivePlayerWeapon(lookupid, weapon, 2000); GetWeaponName(weapon, wname, 64); format(tmp, sizeof(tmp), "* Admin %s(%d) gave you a %s with 2000 ammo", PlayerName(playerid), playerid, wname); SendClientMessage(lookupid, 0x99FF00AA, tmp); return 1; }
If you don't have strtok:
Somewhere in your script:
pawn Код:
strtok(const string[], &index) { new length = strlen(string); while ((index < length) && (string[index] <= ' ')) { index++; }
new offset = index; new result[20]; while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1))) { result[index - offset] = string[index]; index++; } result[index - offset] = EOS; return result; }
|
Hell no!
- dcmd is slow and unstable
- strtok is slow as hell and should never be used by anyone
pawn Код:
CMD:giveweapon(playerid, params[])
{
if(!IsPlayerAdmin(playerid))
return false;
if(sscanf(params, "udd", id, weaponid, ammo)
return SendClientMessage(playerid, 0xFFFFFFFF, "SYNTAX: /giveweapon [nick/id] [weaponid] [ammo]);
if(id == INVALID_PLAYER_ID)
return SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: You specified an invalid player ID.");
// You may want to run a check to make sure the admin is using a valid weapon ID here.
new string[128];
GivePlayerWeapon(id, weaponid, ammo);
format(string, sizeof(string), "%s(%d) has given you weapon ID %d with %d ammo.", GetName(playerid), playerid, weaponid, ammo);
SendClientMessage(id, 0xFFFFFFFF, string);
format(string, sizeof(string), "You have given %s(%d) weapon ID %d with %d ammo.", GetName(id), id, weaponid, ammo);
SendClientMessage(playerid, 0xFFFFFFFF, string);
return 1;
}
stock GetName(playerid)
{
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
return pName;
}
You will need the
ZCMD and
sscanf include files. This code is untested, therefore
I make no guarantee that it will work properly, it should however.