Commands not working properly -
JXF - 21.05.2016
hello, I am a beginner trying to learn how to script.
I made two commands, /gun and /aod.
/gun still gives you weapons even though you are not logged in with rcon, and /aod crashes my server client.
/gun:
Код:
CMD:gun(pid,params[])
{
if(IsPlayerAdmin(playerid))
GivePlayerWeapon(pid, 38, 6000);
GivePlayerWeapon(pid, 24, 6000);
GivePlayerWeapon(pid, 4, 1);
SCM(pid, COLOR_LIGHTBLUE, " You have been granted admin weapons.");
if(!IsPlayerAdmin(playerid))
SCM(pid, COLOR_RED, ADMIN_MESSAGE);
return 1;
}
/aod:
Код:
CMD:aod(pid, params[])
{
if(!IsPlayerAdmin(playerid))
SCM(pid, COLOR_RED, ADMIN_MESSAGE);
if(IsPlayerAdmin(playerid))
SPH(pid, 400);
SetPlayerArmour(pid, 100);
SCMToAll(COLOR_LIME, "Admin %s is now on duty. /w him for help.");
return 1;
}
- trying to make an admin on duty command
SPH = SetPlayerHealth
SCM = SendClientMessage
pid = playerid
Re: Commands not working properly -
justjamie - 21.05.2016
pawn Код:
CMD:gun(pid,params[])
{
if(IsPlayerAdmin(playerid))
{
GivePlayerWeapon(pid, 38, 6000);
GivePlayerWeapon(pid, 24, 6000);
GivePlayerWeapon(pid, 4, 1);
SCM(pid, COLOR_LIGHTBLUE, " You have been granted admin weapons.");
if(!IsPlayerAdmin(playerid))
SCM(pid, COLOR_RED, ADMIN_MESSAGE);
return 1;
}
else SCM(pid, COLOR_ADMIN, ADMIN_MESSAGE);
}
pawn Код:
CMD:aod(pid, params[])
{
if(IsPlayerAdmin(playerid))
{
SCM(pid, COLOR_RED, ADMIN_MESSAGE);
if(IsPlayerAdmin(playerid))
SPH(pid, 400);
SetPlayerArmour(pid, 100);
SCMToAll(COLOR_LIME, "Admin %s is now on duty. /w him for help.");
return 1;
}
else SCM(pid, COLOR_ADMIN, ADMIN_MESSAGE);
}
no problem
Re: Commands not working properly -
Stinged - 21.05.2016
Use curly braces.
Код:
CMD:gun(pid,params[])
{
if(IsPlayerAdmin(playerid))
{
GivePlayerWeapon(pid, 38, 6000);
GivePlayerWeapon(pid, 24, 6000);
GivePlayerWeapon(pid, 4, 1);
SCM(pid, COLOR_LIGHTBLUE, " You have been granted admin weapons.");
}
else SCM(pid, COLOR_RED, ADMIN_MESSAGE);
return 1;
}
CMD:aod(pid, params[])
{
if(!IsPlayerAdmin(playerid)) SCM(pid, COLOR_RED, ADMIN_MESSAGE);
else
{
SPH(pid, 400);
SetPlayerArmour(pid, 100);
SCMToAll(COLOR_LIME, "Admin %s is now on duty. /w him for help.");
}
return 1;
}
Re: Commands not working properly -
Konstantinos - 21.05.2016
You should always use brackets { } for a block of code because currently your code will give deagle and knife even if the player is not admin. Calling it once is also enough:
PHP код:
CMD:gun(pid,params[])
{
if(!IsPlayerAdmin(pid)) return SCM(pid, COLOR_RED, ADMIN_MESSAGE);
GivePlayerWeapon(pid, 38, 6000);
GivePlayerWeapon(pid, 24, 6000);
GivePlayerWeapon(pid, 4, 1);
SCM(pid, COLOR_LIGHTBLUE, " You have been granted admin weapons.");
return 1;
}
---
About /aod command, using specifiers in client messages directly without format will result in server crash.
PHP код:
CMD:aod(pid, params[])
{
if(!IsPlayerAdmin(pid)) return SCM(pid, COLOR_RED, ADMIN_MESSAGE);
SPH(pid, 400);
SetPlayerArmour(pid, 100);
new string[65], name[MAX_PLAYER_NAME];
GetPlayerName(pid, name, MAX_PLAYER_NAME);
format(string, sizeof string, "Admin %s is now on duty. /w him for help.", name);
SCMToAll(COLOR_LIME, string);
return 1;
}
EDIT: Apparently I was too slow :P
Re: Commands not working properly -
JXF - 21.05.2016
Thank you for your tips. They have really helped me, Konstantinos and Stinged.
However, there is a small problem. In the place of %s, the name of the admin is not shown.
Also, I would like it to be so that when you type /aod again, your admin duty status will disappear, as well as a client message to all with "Admin %s is no longer on duty." Sorry if I didn't state this at the beginning.
Re: Commands not working properly -
Konstantinos - 21.05.2016
How is it not shown? I re-looked the code in case I missed anything but the code is fine.
As for the toggling, an array to store whether the player is in duty or not is needed.
PHP код:
// global:
new gPlayer_OnDuty[MAX_PLAYERS];
// OnPlayerConnect:
gPlayer_Duty[playerid] = 0;
// unless you want the player to be automatically on duty or even after logging, set them to 1 where needed
CMD:aod(pid, params[])
{
if(!IsPlayerAdmin(pid)) return SCM(pid, COLOR_RED, ADMIN_MESSAGE);
new string[65], name[MAX_PLAYER_NAME];
GetPlayerName(pid, name, MAX_PLAYER_NAME);
if (!gPlayer_Duty[playerid]) // not on duty
{
SPH(pid, 400);
SetPlayerArmour(pid, 100);
format(string, sizeof string, "Admin %s is now on duty. /w him for help.", name);
SCMToAll(COLOR_LIME, string);
gPlayer_Duty[playerid] = 1; // set them on duty
}
else // on duty
{
// code for health/armour..
format(string, sizeof string, "Admin %s is no longer on duty.", name);
SCMToAll(COLOR_LIME, string);
gPlayer_Duty[playerid] = 0;
}
return 1;
}
Re: Commands not working properly -
JXF - 21.05.2016
Код:
public OnPlayerConnect(playerid)
{
gPlayer_Duty[playerid] = 1;
}
CMD:aod(pid,params[])
{
if(!IsPlayerAdmin(pid)) return SCM(pid, COLOR_RED, ADMIN_MESSAGE);
new aod[65], name[MAX_PLAYER_NAME];
GetPlayerName(pid, name, MAX_PLAYER_NAME);
if(!gPlayer_Duty[playerid])
{
SPH(pid, 99999);
SetPlayerArmour(pid, 100);
format(aod, sizeof aod, "Admin %s is now on duty. Use /report for any assistance.", name);
SCMToAll(COLOR_LIME, aod);
gPlayer_Duty[playerid] = 1;
}
else
{
SPH(pid, 100);
SetPlayerArmour(pid, 0);
}
format(aod, sizeof aod, "Admin %s is no longer on duty.", name);
SCMToAll(COLOR_BLUE, aod);
gPlayer_Duty[playerid] = 0;
}
return 1;
}
}
Код:
C:\Users\Marius\Desktop\GM\gamemodes\GM.pwn(389) : error 021: symbol already defined: "OnPlayerConnect"
C:\Users\Marius\Desktop\GM\gamemodes\GM.pwn(391) : warning 209: function "OnPlayerConnect" should return a value
C:\Users\Marius\Desktop\GM\gamemodes\GM.pwn(419) : warning 209: function "cmd_aod" should return a value
C:\Users\Marius\Desktop\GM\gamemodes\GM.pwn(420) : error 010: invalid function or declaration
the global was supposed to be gPlayer_Duty[MAX_PLAYERS];
only the invalid function or declaration and warnings are the problems now.
Re: Commands not working properly -
Konstantinos - 21.05.2016
The global is:
pawn Код:
new gPlayer_Duty[MAX_PLAYERS];
Your script has already OnPlayerConnect callback, so add:
pawn Код:
gPlayer_Duty[playerid] = 1;
in it.
There are also two extra closed brackets, take a look at my post again for correcting the command.
Re: Commands not working properly -
JXF - 21.05.2016
Corrected it. Thank you very much.