PDA

View Full Version : Help Making Admin Command


Warren
10/10/2011, 12:57 AM
Hello, I have this if (!strcmp(cmdtext, "/weapons", true)) , I need the cmd to be for RCON admins only, any help please?

TheLazySloth
10/10/2011, 01:03 AM
add if(IsPlayerAdmin(playerid))
in front of it.

Warren
10/10/2011, 01:10 AM
Thankyou, how would i add a message like "You must be RCON Admin to use that command"

TheLazySloth
10/10/2011, 01:11 AM
if(!IsPlayerAdmin(playerid)) // if not an rcon admin
{
SendClientMessage(playerid, -1, "You must be RCON Admin to use that command!"); //send message
} else {
if (!strcmp(cmdtext, "/weapons", true)) // checks if player typed /weapons
{
// blahblahblah
}
}

Edit: Aha, mmm it might be better this way....

if (!strcmp(cmdtext, "/weapons", true)) // checks if player typed /weapons
{
if(!IsPlayerAdmin(playerid)) // if not an rcon admin
{
SendClientMessage(playerid, -1, "You must be RCON Admin to use that command!"); //send message
} else {
// blahblahblah
}
}

Warren
10/10/2011, 01:43 AM
I have this

public OnPlayerCommandText(playerid, cmdtext[])
{
if(IsPlayerAdmin(playerid))if (!strcmp(cmdtext, "/weapons", true))
if (!strcmp(cmdtext, "/weapons", true)) // checks if player typed /weapons
{
if(!IsPlayerAdmin(playerid)) // if not an rcon admin
{
SendClientMessage(playerid, -1, "You must be RCON Admin to use that command!"); //send message
} else {
// blahblahblah


But it dont work it just makes the if(IsPlayerAdmin(playerid)) pointless

GrimR
10/10/2011, 02:01 AM
Use this inside of the strcmp:


if (strcmp())
{
if (!IsPlayerAdmin(playerid)) { return // message here }
}


The strcmp being your /weapon and if not RCON admin you just return SendClientMessage() that they are not RCON admin and it will exit the function so no more processing is done, hence why it is only one line.

[HiC]TheKiller
10/10/2011, 02:05 AM
Just do this


if(!strcmp(cmdtext, "/weapons", true) && IsPlayerAdmin(playerid))

That way, the command won't be called if the player is not admin :).

GrimR
10/10/2011, 02:30 AM
I think the OP wants to notify the user though, where the example I provided will do so with one line, no need for else or brackets on multiple lines.

grand.Theft.Otto
10/10/2011, 02:48 AM
if (strcmp(cmdtext, "/weapons", true, 8))
{
if(IsPlayerAdmin(playerid))
{
// weapon stuff here
return 1;
} else return SendClientMessage(playerid,-1,"You Must Be An RCON Administrator To Use This Command.");
}

TheLazySloth
10/10/2011, 02:58 AM
All of these will work, can we stop posting code now?

GrimR
10/10/2011, 03:01 AM
They will but I originally provided the best possible answer based on the question lol.

But I understand people get excited to help out, so let's wait and see how the OP goes.

TheLazySloth
10/10/2011, 03:02 AM
They will but I originally provided the best possible answer based on the question lol.

Actually, I liked grand.Theft.Otto's better then all the ones we posted.

grand.Theft.Otto
10/10/2011, 03:16 AM
They will but I originally provided the best possible answer based on the question lol.

But I understand people get excited to help out, so let's wait and see how the OP goes.

This.

Actually, I liked grand.Theft.Otto's better then all the ones we posted.

Yes, out of all the replies added, I put all of it into one so it finalizes the whole problem.

GrimR
10/10/2011, 04:31 AM
Oh yeah as in the whole source, I meant the method, trying to keep it short as doing it on iPhone at work is a pain lol always have to go back and fix things where one of my fingers slides off onto different keys and such :p

Warren
11/10/2011, 04:45 PM
Haha, Thankyou all

Warren
11/10/2011, 05:01 PM
public OnPlayerCommandText(playerid, cmdtext[])
{
if(IsPlayerAdmin(playerid))if (!strcmp(cmdtext, "/weapons", true))
{
ShowPlayerDialog(playerid, weapons, DIALOG_STYLE_LIST, "Weapon Spawner", "Knife\nBaseball Bat\nPistol\nSilenced Pistol\nDesert Eagle\nShotgun\nSawn-off Shotgun\nCombat Shotgun\nTec-9\nMicro-MP5\nMP5\nAK-47\nM4 Carbine\nCountry Rifle\nSniper Rifle\nRocket Launcher\nHeat Seeker\nFlamethrower\nGrenade\nTear Gas-Grenade\nMolotov Cocktail\nRemote Satchel with Detonator\nSpray Can\nFire Extinguisher", "Spawn", "Cancel");

} else return SendClientMessage(playerid,-1,"You Must Be An RCON Administrator To Use This Command.");

return 1;

} This doesnt work it doesnt say anything when I try to use /weapons, am I doing it wrong?

EDIT: None of my cmds work when I use the above.