#1

hello i was looking on samp forum for to make a /makeadmin command and was wondering how to save it, so all files / users go in that folder.and if they admin it has admin lvl = [adminlevel] in the file/ heres what i got
Код:
enum Info
{
   AdminLevel,
}
new PlayerInfo[MAX_PLAYERS][Info];

[color= green] // ______________________________[/color]
public OnPlayerConnect(playerid)
{
  PlayerInfo[playerid][AdminLevel] = 0;
	return 1;
}
_________________
public OnPlayerCommandText(playerid, cmdtext[])
{
	new cmd[256], idx;
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/makeadmin", true) == 0)
{
       new string[128];
       new tmp[256];
       new player[MAX_PLAYER_NAME], giveplayer[MAX_PLAYER_NAME];
       new giveplayerid;
       if (IsPlayerAdmin(playerid))
       {
               tmp = strtok(cmdtext, idx);
               if(!strlen(tmp))
               {
                       SendClientMessage(playerid, ORANGE, "USAGE: /makeadmin [playerid] [level]");
                       SendClientMessage(playerid, ORANGE, "FUNCTION: Player will be an admin.");
                       return 1;
               }
               giveplayerid = ReturnUser(tmp);
_________________________
ReturnUser(text[], playerid = INVALID_PLAYER_ID)

{

        new pos = 0;

        while (text[pos] < 0x21) // Strip out leading spaces

        {

                if (text[pos] == 0) return INVALID_PLAYER_ID; // No passed text

                pos++;

        }

        new userid = INVALID_PLAYER_ID;

        if (IsNumeric(text[pos])) // Check whole passed string

        {

                // If they have a numeric name you have a problem (although names are checked on id failure)

                userid = strval(text[pos]);

                if (userid >=0 && userid < MAX_PLAYERS)

                {

                        if(!IsPlayerConnected(userid))

                        {

                                /*if (playerid != INVALID_PLAYER_ID)

                                {

                                        SendClientMessage(playerid, 0xFF0000AA, "User not connected");

                                }*/

                                userid = INVALID_PLAYER_ID;

                        }

                        else

                        {

                                return userid; // A player was found

                        }

                }

                /*else

                {

                        if (playerid != INVALID_PLAYER_ID)

                        {

                                SendClientMessage(playerid, 0xFF0000AA, "Invalid user ID");

                        }

                        userid = INVALID_PLAYER_ID;

                }

                return userid;*/

                // Removed for fallthrough code

        }

        // They entered [part of] a name or the id search failed (check names just incase)

        new len = strlen(text[pos]);

        new count = 0;

        new name[MAX_PLAYER_NAME];

        for (new i = 0; i < MAX_PLAYERS; i++)

        {

                if (IsPlayerConnected(i))

                {

                        GetPlayerName(i, name, sizeof (name));

                        if (strcmp(name, text[pos], true, len) == 0) // Check segment of name

                        {

                                if (len == strlen(name)) // Exact match

                                {

                                        return i; // Return the exact player on an exact match

                                        // Otherwise if there are two players:

                                        // Me and MeYou any time you entered Me it would find both

                                        // And never be able to return just Me's id

                                }

                                else // Partial match

                                {

                                        count++;

                                        userid = i;

                                }

                        }

                }

        }

        if (count != 1)

        {

                if (playerid != INVALID_PLAYER_ID)

                {

                        if (count)

                        {

                                SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow earch");

                        }

                        else

                        {

                                SendClientMessage(playerid, 0xFF0000AA, "No matching user found");

                        }

                }

                userid = INVALID_PLAYER_ID;

        }

        return userid; // INVALID_USER_ID for bad return

}

IsNumeric(const string[])

{

        for (new i = 0, j = strlen(string); i < j; i++)

        {

                if (string[i] > '9' || string[i] < '0') return 0;

        }

        return 1;

}

strtok(string[],&idx,seperator = ' ')

{

        new ret[128], i = 0, len = strlen(string);

        while(string[idx] == seperator && idx < len) idx++;

        while(string[idx] != seperator && idx < len)

        {

            ret[i] = string[idx];

            i++;

                idx++;

        }

        while(string[idx] == seperator && idx < len) idx++;

        return ret;

}
[color=green] // ^^^ that under the script
               tmp = strtok(cmdtext, idx);
               new level = strval(tmp);
               if(giveplayerid != INVALID_PLAYER_ID)
               {
                       GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                       GetPlayerName(playerid, player, sizeof(player));
                       PlayerInfo[giveplayerid][AdminLevel] = level;
                       printf("Admin %s made %s a level %d admin.", player, giveplayer, level);
                       format(string, sizeof(string), "You are now an administrator level %d thanks to %s.", level,  player);
                       SendClientMessage(giveplayerid, 0x00C2ECFF, string);
                       format(string, sizeof(string), "You have given %s level %d admin.",  giveplayer,PlayerInfo[giveplayerid][AdminLevel]);
                               SendClientMessage(playerid, 0x00C2ECFF, string);
                               SendClientMessageToAll(0x660000AA,"AdmCmd: %s has been premoted %s to a level %d admin");
               }
               else if(giveplayerid == INVALID_PLAYER_ID)
               {
                       format(string, sizeof(string), "%i is not an active player.", giveplayerid);
                       SendClientMessage(playerid, 0xE60000FF, string);
               }
       }
       else
       {
           SendClientMessage(playerid, 0xE60000FF, "You are not a lead admin!");
       }
       return 1;
       }
	return 0;
}
rep if you help me thanks
Reply
#2

Use a saving system like dini or Y_INI.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)