Hey sarge, I was interested by the whole sm_gimme thing you spoke about a few pages back, so I went into the code of this plugin, and after hours of testing and tons of headaches, I finally made a working sm_gimme command that doesn't require a name input.
Setting up the command
Code:
RegAdminCmd("sm_gimme", Command_Gimme, ADMFLAG_CUSTOM3, "Give Temporary Weapon sm_gimme <itemindex>");
Coding for the command
Code:
public Action:Command_Gimme(client, args)
{
new String:arg2[32];
new weaponLookupIndex = 0;
if (args != 1) {
ReplyToCommand(client, "[TF2Items] Usage: sm_gimme <itemindex>");
return Plugin_Handled;
}
/* Get the arguments */
GetCmdArg(1, arg2, sizeof(arg2));
weaponLookupIndex = StringToInt(arg2);
new weaponSlot;
new String:formatBuffer[32];
Format(formatBuffer, 32, "%d_%s", weaponLookupIndex, "slot");
new bool:isValidItem = GetTrieValue(g_hItemInfoTrie, formatBuffer, weaponSlot);
if (!isValidItem)
{
ReplyToCommand(client, "[TF2Items] Invalid Weapon ID");
return Plugin_Handled;
}
if (!cvar_valveweapons && weaponLookupIndex > 9000)
{
ReplyToCommand(client, "[TF2Items] You're not an admin!");
return Plugin_Handled;
}
else
{
Command_WeaponBase(client, weaponLookupIndex, weaponSlot);
LogAction(client, client, "\"%L\" gave weapon %d to \"%L\"", client, weaponLookupIndex, client);
}
if (cvar_notify == 1 || cvar_notify == 2)
{
if (!cvar_valveweapons) {
PrintToConsole(client, "[TF2Items] ", "Gave weapon %d!", weaponLookupIndex);
} else {
PrintToConsole(client, "[TF2Items] ", "Gave weapon %d!", weaponLookupIndex);
}
}
else PrintToConsole(client, "[TF2Items] Gave weapon %d!", weaponLookupIndex);
return Plugin_Handled;
}
Of course, you'll probably notice I used PrintToConsole. The reason I decided to do this, was for a friend of mine who just got his own server. And he had specific requests for the command, which were:
- He didn't want messages appearing in chat
- He wanted donators to be able to use the command
- He didn't want his donators being able to access any weapons with ID's over 9000
Also, I didn't know if I could use "if" by itself, which is why I did this:
Code:
if (!cvar_valveweapons) {
PrintToConsole(client, "[TF2Items] ", "Gave weapon %d!", weaponLookupIndex);
But hey, the command works perfectly, though I haven't checked my error logs yet. So whaddya think?