06.01.2015, 22:36
nvmnvm
Hello there!
Could you tell me which command processor you use and what variable stores the admin level? |
CMD:forcerules(playerid,params[])
{
new targetID,string[128],pName[MAX_PLAYER_NAME],tName[MAX_PLAYER_NAME];
if(User[playerid][accountAdmin] == 0) return SendClientMessage(playerid,-1,"You are not authorized enough.");
if(sscanf(params,"i",targetID)) return SendClientMessage(playerid,-1,"[USAGE]: /forcerules [player ID]");
if(!IsPlayerConnected(targetID)) return SendClientMessage(playerid,-1,"You have specified an incorrect ID.");
else
{
GetPlayerName(playerid,pName,sizeof(pName));
GetPlayerName(targetID,tName,sizeof(tName));
format(string,sizeof(string),"%s has forced you to view the /rules!",pName);
SendClientMessage(targetID,-1,string);
format(string,sizeof(string),"%s has forced %s to view the rules!",pName,tName);
AdminMessage(-1,string);
// Put your /rules messages/dialogs here.
}
return 1;
}
forward AdminMessage(color, string[]);
public AdminMessage(color,string[])
{
for(new i=0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(User[i][accountAdmin] >= 1)
{
SendClientMessage(i, color, string);
}
}
}
return 1;
}
// Define the dialog ID:
#define DIALOG_RULES (500)
// Store all rules in an array...
new const serverRules[][] = {
// ID, Rule
{0, "A test this is"},
{1, "This is a test"},
{2, "Is this a test"}
};
CMD:forcerules(playerid, params[])
{
new string[500], targetid; // Ensure the string's cell size is big enough for all your rules (in the array), and add a integer variable
// Check if they are an admin, if not; return an error message
if(!User[playerid][accountAdmin])
return SendClientMessage(playerid, 0xFF0000AA, "ERROR:{ffffff} You're not an admin!");
// SSCANF; check if the params are used (correctly), if not; return an error message
if(sscanf(params, "u", targetid))
return SendClientMessage(playerid, 0xFF0000AA, "ERROR:{ffffff} /forcerules [player: ID/name]");
// If the entered ID is not connected (or invalid), return an error message
if(!IsPlayerConnected(targetid))
return SendClientMessage(playerid, 0xFF0000AA, "ERROR:{ffffff} The ID you have entered is invalid!");
// Loop through the array and format the array data in a string
for(new i; i < sizeof(serverRules); i ++)
{
// Pull the previous string, pull the value of "i" (to count the rules), and pull the array info
format(string, sizeof(string), "%s{74ADCC}%d{E0E0E0}: %s\n", string, i, serverRules[i][1]);
}
// Show a dialog to "targetid" as DIALOG_STYLE_MSGBOX with our formatted string.
ShowPlayerDialog(targetid, DIALOG_RULES, DIALOG_STYLE_MSGBOX, "Rules", string, "Accept", "Deny");
// Format the string, using a cell size of 95; (43 for text, + 2x 24 = 48; 48+43 = 91)
format(string, 95, "ACMD: (%d) %s has forced /rules on (%d) %s.", playerid, GetUserName(playerid), targetid, GetUserName(playerid));
SendAdminMsg(string); // Send a message to admins only; see function below.
// Format a string with a cell size of 80; size 50 for the text, + 24 for the player name.
format(string, 80, "Admin (%d) %s has forced you to view the /rules.", playerid, GetUserName(playerid));
SendClientMessage(targetid, -1, string); // Send a message to "targetid".
// Return 1; or "true"
return true;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
// Check if the dialog a user replied to is DIALOG_RULES
if(dialogid == DIALOG_RULES)
{
// Using a switch statement to determine which action to perform based on "response"'s value
switch(response)
{ // Case false aka 0; (they pressed "Deny"); kick the player.
case false: return Kick(playerid);
// Case true aka 1; (they pressed "Accept"); send them a confirmation message.
case true: return SendClientMessage(playerid, 0x74ADCCAA, "You have accepted the rules!");
}
}
// Return false to make the dialog pass into another script.
return false;
}
SendAdminMsg(text[])
{
// Using foreach for player loops:
foreach(new i: Player)
{
// If "i" is connected...
if(IsPlayerConnected(i))
{
// If "i" has an admin level greater than 0...
if(User[i][accountAdmin] > 0)
{
// Return the client message.
SendClientMessage(i, -1, text);
}
}
}
// Return false.
return false;
}
GetUserName(playerid)
{
// Define the name variable...
new name[MAX_PLAYER_NAME char];
// Pull the name...
GetPlayerName(playerid, name, sizeof(name));
// Return it.
return name;
}