14.04.2012, 05:38
how i can add command /duty for admin only pls help iam two day sreach for it
new bool:IsOnAdminDuty[MAX_PLAYERS] = false;
CMD:aduty(playerid,params[]) // Onduty
{
if(!IsPlayerAdmin(playerid))
{
SendClientMessage(playerid,-1,"You are not authorised to use that command.");
return 1;
}
if(IsOnAdminDuty[playerid] == false)
{
IsOnAdminDuty[playerid] = true;
new pname[24],dstring[124];
GetPlayerName(playerid,pname,sizeof(pname));
format(dstring,sizeof(dstring),"Administrator %s is now on duty.",pname);
SendClientMessageToAll(-1,dstring);
SetPlayerHealth(playerid,99999);
SetPlayerArmour(playerid,99999);
SetPlayerSkin(playerid,271);
}
return 1;
}
CMD:aoffduty(playerid,params[]) // Off duty
{
if(!IsPlayerAdmin(playerid))
{
SendClientMessage(playerid,-1,"You are not authorised to use that command.");
return 1;
}
if(IsOnAdminDuty[playerid] == true)
{
IsOnAdminDuty[playerid] = false;
new name[24],ostring[124];
GetPlayerName(playerid,name,sizeof(name));
format(ostring,sizeof(ostring),"Administrator %s is now off duty.",name);
SendClientMessageToAll(-1,ostring);
SetPlayerHealth(playerid,100);
SetPlayerArmour(playerid,0);
}
return 1;
}
CMD:admins(playerid,params[]) // Admins command
{
SendClientMessage(playerid,-1,"----Current on duty Administrators----");
for(new i = 0; i <MAX_PLAYERS; i++)
{
if(IsOnAdminDuty[i] == true)
{
new aname[24],astring[124];
GetPlayerName(playerid,aname,sizeof(aname));
format(astring,sizeof(astring),"%s",aname);
SendClientMessage(playerid,-1,astring);
}
}
return 1;
}
new AdminDutyStatus;
new AdminDutyStatus[MAX_PLAYERS];
public OnPlayerDisconnect(playerid, reason)
{
return 1;
}
AdminDutyStatus(playerid) = 0;
0. We use a semicolon to close variables, meaning we've got nothing else to define/set that variable as. Wonder why there's a 'return 1' inside the brackets? Every time we run a function, you need to return something back to the main callback so it is informed that the command was executed, otherwise the compiler will give you an error message. (I'm not exactly clear on the reasons as of yet to go about preaching in detail. If I should appear wrong, please do correct me.)public OnPlayerDisconnect(playerid, reason)
{
AdminDutyStatus(playerid) = 0;
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
// Do something here
return 1;
}
return 0;
}
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
// Do something here
return 1;
}
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
AdminDutyStatus = 1;
return 1;
}
return 0;
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
if(AdminDutyStatus == 0) /* <-- Checking IF this variable 'AdminDutyStatus' equals 0. So technically, it's checking if the player is off duty when (s)he types the command.*/
{ /* Since we called a new function "IF", we also create a new set of brackets. Anything done within these brackets will be conditional of the IF statement*/
/* You can place additional admin goodies here, such as enabled god mode, etc. */
return 1; // Returns the result
}
}
return 0;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
if(AdminDutyStatus == 0)
{
return 1;
}
else
}
return 0;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
if(AdminDutyStatus == 0)
{
return 1;
}
else
{
AdminDutyStatus = 0;
return 1;
}
}
return 0;
}
{
if (strcmp("/Aduty", cmdtext, true, 10) == 0)
{
if(AdminDutyStatus == 0)
{
AdminDutyStatus = 1;
return 1;
}
else
{
AdminDutyStatus = 0;
return 1;
}
}
return 0;
}