SA-MP Forums Archive
My first short admin script dont know if its written properly - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: My first short admin script dont know if its written properly (/showthread.php?tid=80918)



My first short admin script dont know if its written properly - xXiamCr4zyXx - 07.06.2009

Код:
#include <a_samp>

enum Info
{
  AdminLevel,
}
new PlayerInfo[MAX_PLAYERS][Info];

//=============================================================================

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);
        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);
        }
        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;
}
//=============================================================================
public OnPlayerCommandText( playerid, cmdtext[] )
{
  if( strcmp( cmdtext, "/ban", true ) == 0 )
  {
    
    Ban( playerid );
		SendClientMessageToAll( playerid, COLOR_RED, "%s was banned by admin %s");
    return 1;
  }
}
//=============================================================================

public OnPlayerCommandText ( playerid, cmdtext[] )
{
  if( strcmp(cmdtext, "/kick", true ) == 0 )
  {
  
		Kick( playerid);
		SendClientMessageToAll( playerid, COLOR-RED, "%s was kicked by admin %s");
		return 1;
		
	 }
}

//============================================================================
Can anyone tell to me if its typed correctly? I really dont know and i dont want to test it on server i dont want to get a fucked up server.


Re: My first short admin script dont know if its written properly - yom - 07.06.2009

No it's not, there are many mistakes. And don't copy/paste from others scripts, that's the worst way to "learn" scripting.


Re: My first short admin script dont know if its written properly - xXiamCr4zyXx - 07.06.2009

I only copied pasted from wiki


Re: My first short admin script dont know if its written properly - Weirdosport - 07.06.2009

You have 2 OnPlayerCommandText's and the ban command is useless. It will ban the person who types it, and it you can't attempt to format a string within the SendClientMessage function...