How to create a /forcerules command?
#1

nvmnvm
Reply
#2

Hello there!

Could you tell me which command processor you use and what variable stores the admin level?
Reply
#3

Quote:
Originally Posted by Rufio
Посмотреть сообщение
Hello there!

Could you tell me which command processor you use and what variable stores the admin level?
ZCMD, User[playerid][accountAdmin]

ty

I'm not sure about the 'User[playerid][accountAdmin]' if thats what you wanted, I'm new at this and also this gamemode is downloaded and I'm just editing, heh.

Thanks, REPed.
Reply
#4

Yeah, that was what I wanted, the code would be;

pawn Код:
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;
}
and at the end of your script, place this;

pawn Код:
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;
}
No problem, this should work.

Edit: Eh, sorry about the indentation mistakes as it is hard to write a script at forums.
Reply
#5

Thanks mate you're awesome

Please remove
Reply
#6

No problem and what should I remove? If that's the script I wrote, I am afraid I can't, the forum rules suggest us to keep them, it is meant to be for public access in case somebody else needs help about the same script.
Reply
#7

Oh I meant remove the thread(To the betas), anyway thanks

p.s; REPed and can't wait for your Tutorial in your signature
Reply
#8

Ah no problem, glad that I could be helpful

And yeah, I will write it whenever I find time to do so, currently occupied with my own Roleplay server project

Feel free to PM me/post in this topic if you have got any more questions and/or concerns. Good luck with scripting!
Reply
#9

Consider using more efficient methods instead. You'll need sscanf2, zcmd and foreach for my method to work. It is way more efficient than above methods and I really urge you to use it over the outdated methods Rufio recommended.

pawn Код:
// 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;
}
As for the custom functions we used (also explained):

pawn Код:
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;
}
Which will look like: http://i.imgur.com/a41wasG.png (compiled and tested). Please mind my English as I'm very tired atm, feel free to reply in case you don't understand something.

Also, in the future please don't edit your topic's main post so users can find this whenever they are looking for help or advice.
Reply
#10

^

Can you please gimme that as a filterscript? That'd be great, as I'd like to put it in a new filterscript.

Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)