[Tutorial] ZCMD - Commands collection [PART 1]
#5

Quote:
Originally Posted by Twisted_Insane
View Post
pawn Code:
CMD:freeze(playerid,params[])
{
  if(PlayerInfo[playerid][pAdmin] >=4 ) //setting permissions, again your enum-stuff here, don't take mine 1:1
  {

  }

  return 1;
}
Now, we'll not only got to define the stuff from earlier, we'll also check the enum's variables and set them to true, so the compiler knows that the player's frozen in this command!

pawn Code:
COMMAND:freeze(playerid,params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 5)
    {
            new Target; //defines the playerid we wanna freeze
            if(sscanf(params, "u", Target)) SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /freeze [playerid]"); //tell sscanf again if the parameters/syntax is wrong to return a special message
            if(!IsPlayerConnected(Target)) //if the ID doesn't exist, return an error-message
                return SendClientMessage(playerid, COLOR_GREY, "ERROR:Player is not connected!");
            if(!sscanf(params, "u", Target))
            {
               if(Target == playerid) return SendClientMessage(playerid, COLOR_RED, "ERROR: Cant perform this command on yourself!" ); //I wouldn't add this line, because it won't let you perform this CMD on yourself
                if(PlayerInfo[Target][pAdmin] > PlayerInfo[playerid][pAdmin]) return SendClientMessage(playerid,red,"ERROR: You cant perform this on Admins that are higher than your level!"); // if the player you're performing this command on has a higher level as you, return a message, you ain't able to freeze him
                new tname[MAX_PLAYER_NAME]; //define the new target-name of the playerid
                GetPlayerName(Target,tname,sizeof(tname)); //get the playername with this function
                new pname[MAX_PLAYER_NAME]; //define the adminname
                GetPlayerName(playerid,pname,sizeof(pname)); //get the adminname with this function
                new tstring[128]; //define the string for the player (victim)
                new pstring[128];// define the string for the admin which is performing
                new astring[128];//define the string for all the players which are online
                format(tstring,sizeof(tstring),"You have been frozen by administrator %s! You cant move!",pname); //this is formatting the player-string, while it's also getting the adminname
                format(pstring,sizeof(pstring),"You have frozen player %s(%d)!",tname,Target); //this is formatting the adminname-string, while it's also getting the playername and his ID(target)
                format(astring,sizeof(astring),"Administrator %s has frozen %s!",pname,tname); //this is formatting the all-string, while it's sending this message to everybody and is getting admin- and playername
                SendClientMessage(Target,COLOR_GOLD,tstring);//sends the message to the victim
                SendClientMessage(playerid,TEAM_GROVE_COLOR,pstring);//sends the message to the admin
                SendClientMessageToAll(COLOR_LIGHTBLUE,astring);//sends the message to everybody
                TogglePlayerControllable(Target,0); //with that function, the player won't be able to mov, while we're using the variable "Target" as the playerid
                PlayerInfo[Target][Frozen] = 1;//IMPORTANT:we're getting the variable "[frozen]" out of the enum, and set it's value to "1', the compiler knows now that the player is frozen
            }
           
    }
       
// if he doesn't have permissions, return that message!
    else return SendClientMessage(playerid,COLOR_RED,"ERROR: You must be level 5 to use this command!");
    return 1;
}
The most important thing for you is this line:
pawn Code:
PlayerInfo[Target][Frozen] = 1;
We're telling the compiler, that he should put the variable "frozen" outta the enum into the info of the player! If you set the value to 1, the compiler knows that the player is frozen now!

Also that wasn't that difficult, the "unfreeze-CMD" is the same, we just have to set the enum's variable to "0" that the compiler knows that the player's unfrozen yet:

pawn Code:
COMMAND:unfreeze(playerid,params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 5)
    {
            new Target; //defines the playerid we wanna unfreeze
            if(sscanf(params, "u", Target)) SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /unfreeze [playerid]"); //tell sscanf again if the parameters/syntax is wrong to return a special message
            if(!IsPlayerConnected(Target)) //if the ID doesn't exist, return an error-message
                return SendClientMessage(playerid, COLOR_GREY, "ERROR:Player is not connected!");
            if(!sscanf(params, "u", Target))
            {
               if(Target == playerid) return SendClientMessage(playerid, COLOR_RED, "ERROR: Cant perform this command on yourself!" ); //I wouldn't add this line, because it won't let you perform this CMD on yourself
                if(PlayerInfo[Target][pAdmin] > PlayerInfo[playerid][pAdmin]) return SendClientMessage(playerid,red,"ERROR: You cant perform this on Admins that are higher than your level!"); // if the player you're performing this command on has a higher level as you, return a message, you ain't able to unfreeze him
                new tname[MAX_PLAYER_NAME]; //define the new target-name of the playerid
                GetPlayerName(Target,tname,sizeof(tname)); //get the playername with this function
                new pname[MAX_PLAYER_NAME]; //define the adminname
                GetPlayerName(playerid,pname,sizeof(pname)); //get the adminname with this function
                new tstring[128]; //define the string for the player (victim)
                new pstring[128];// define the string for the admin which is performing
                new astring[128];//define the string for all the players which are online
                format(tstring,sizeof(tstring),"You have been unfrozen by administrator %s! You cant move!",pname); //this is formatting the player-string, while it's also getting the adminname
                format(pstring,sizeof(pstring),"You have unfrozen player %s(%d)!",tname,Target); //this is formatting the adminname-string, while it's also getting the playername and his ID(target)
                format(astring,sizeof(astring),"Administrator %s has unfrozen %s!",pname,tname); //this is formatting the all-string, while it's sending this message to everybody and is getting admin- and playername
                SendClientMessage(Target,COLOR_GOLD,tstring);//sends the message to the victim
                SendClientMessage(playerid,TEAM_GROVE_COLOR,pstring);//sends the message to the admin
                SendClientMessageToAll(COLOR_LIGHTBLUE,astring);//sends the message to everybody
                TogglePlayerControllable(Target,1; //with that function, the player will be able to move again, while we're using the variable "Target" as playerid again
                PlayerInfo[Target][Frozen] = 0;//IMPORTANT:we're getting the variable "[frozen]" out of the enum, and set it's value to "0", the compiler knows now that the player is unfrozen
            }
           
    }
       
// if he doesn't have permissions, return that message!
    else return SendClientMessage(playerid,COLOR_RED,"ERROR: You must be level 5 to use this command!");
    return 1;
}
[/I]
I believe I told you already...You don't need three strings for messages, also you missed a closing parenthesis in the unfreeze command.
Reply


Messages In This Thread
ZCMD - Commands collection [PART 1] - by Twisted_Insane - 17.02.2012, 15:39
Re: ZCMD - Commands collection [PART 1] - by Konstantinos - 17.02.2012, 15:52
Re: ZCMD - Commands collection [PART 1] - by Mr.Fames - 17.02.2012, 15:57
Re: ZCMD - Commands collection [PART 1] - by Twisted_Insane - 17.02.2012, 18:29
Re: ZCMD - Commands collection [PART 1] - by [ABK]Antonio - 18.02.2012, 10:45
Re: ZCMD - Commands collection [PART 1] - by Twisted_Insane - 18.02.2012, 11:11
Re: ZCMD - Commands collection [PART 1] - by [Diablo] - 18.02.2012, 12:10
Re: ZCMD - Commands collection [PART 1] - by Twisted_Insane - 18.02.2012, 13:12
Re: ZCMD - Commands collection [PART 1] - by Twisted_Insane - 25.02.2012, 18:49
Re: ZCMD - Commands collection [PART 1] - by Karl[NDZ] - 20.03.2012, 14:00
Re: ZCMD - Commands collection [PART 1] - by Twisted_Insane - 20.03.2012, 14:07
Re: ZCMD - Commands collection [PART 1] - by Wickeed - 01.04.2012, 20:31
Re: ZCMD - Commands collection [PART 1] - by Twisted_Insane - 01.04.2012, 21:05
Re: ZCMD - Commands collection [PART 1] - by Ash. - 01.04.2012, 21:12
Re: ZCMD - Commands collection [PART 1] - by Twisted_Insane - 01.04.2012, 21:34
Re: ZCMD - Commands collection [PART 1] - by StrangeLove - 28.05.2012, 12:35
Re: ZCMD - Commands collection [PART 1] - by gnoomen2 - 07.08.2012, 00:13
Re: ZCMD - Commands collection [PART 1] - by gnoomen2 - 07.08.2012, 17:53
Re: ZCMD - Commands collection [PART 1] - by Diogo123 - 27.08.2012, 23:21
Re: ZCMD - Commands collection [PART 1] - by Chu - 25.09.2013, 06:49
Re: ZCMD - Commands collection [PART 1] - by Jhony_Blaze - 16.12.2014, 20:32
Re: ZCMD - Commands collection [PART 1] - by Arastair - 18.12.2014, 08:28
Re: ZCMD - Commands collection [PART 1] - by dopeboy1040 - 03.04.2017, 14:58
Re: ZCMD - Commands collection [PART 1] - by Variable™ - 04.04.2017, 12:00

Forum Jump:


Users browsing this thread: 1 Guest(s)