changeteam command
#1

Hi!
I'm working on a server which has 2 teams and I want to make the /changeteam command.
I am new in scripting, so please explain me if you can.
I tried to make something like this:
Код:
CMD:changeteam(playerid, params[])
{
    SetPlayerTeamFromClass(playerid, classid);
    return 1;
}
SetPlayerTeamFromClass:
Код:
forward SetPlayerTeamFromClass(playerid, classid);
   public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerTeamFromClass(playerid, classid);
    return 1;
}
public SetPlayerTeamFromClass(playerid, classid)
{
if(classid == 0 || classid == 1 || classid == 2 || classid == 3)
    {
        gTeam[playerid] = COPS;
        GameTextForPlayer(playerid,"~b~COPS",3000,5);
        SetPlayerPos(playerid,1975.2399,-1220.0157,25.0779); 
        SetPlayerCameraPos(playerid,1969.5686,-1224.0016,24.9909); 
        SetPlayerCameraLookAt(playerid,1975.2399,-1220.0157,25.0779);
        SetPlayerFacingAngle(playerid,122.4500);
        SetPlayerColor(playerid,0xA000FFFF); 
    }
else if(classid == 4 || classid == 5 || classid == 6 || classid == 7)
    {
        gTeam[playerid] = ROBBERS;
        GameTextForPlayer(playerid,"~r~ROBBERS",3000,5);
        SetPlayerPos(playerid,2500.6060,-1672.1453,13.3512);
        SetPlayerCameraPos(playerid,2507.0615,-1674.3574,13.3732);
        SetPlayerCameraLookAt(playerid,2500.6060,-1672.1453,13.3512);
        SetPlayerFacingAngle(playerid,252.4717);
        SetPlayerColor(playerid,0x55FF00FF);
    }
}
Thanks!
Reply
#2

I forgot, when compiling it gives me the error:
Код:
error 017: undefined symbol "classid"
for
Код:
CMD:changeteam(playerid, params[])
{
    SetPlayerTeamFromClass(playerid, classid);
    return 1;
}
Reply
#3

Hello,RetroEX your public function has a parameter, in which it will pass a value to be performed.

PHP код:
public SetPlayerTeamFromClass(playeridclassid//classid is your parameter 
so for example, you use this function, in your command

PHP код:
CMD:changeteam(playeridparams[])
{
    
SetPlayerTeamFromClass(playeridclassid);
    return 
1;

This will give error, because classid is the parameter of your function, if you want to put some player on another team, you need to put the ID of that team, as described below:

PHP код:
CMD:changeteam(playeridparams[])
{
    
SetPlayerTeamFromClass(playerid1); //For example "1"
    
return 1;

So, how it works inside of your function?
As you called your function in the command, and put "1" as the class id, then the classid of this function will assume the value of 1, and will execute every body of the function.

PHP код:
public SetPlayerTeamFromClass(playeridclassid//classid will be "1"
{
if(
classid == || classid == || classid == || classid == 3)
    {
        
gTeam[playerid] = COPS;
        
GameTextForPlayer(playerid,"~b~COPS",3000,5);
        
SetPlayerPos(playerid,1975.2399,-1220.0157,25.0779); 
        
SetPlayerCameraPos(playerid,1969.5686,-1224.0016,24.9909); 
        
SetPlayerCameraLookAt(playerid,1975.2399,-1220.0157,25.0779);
        
SetPlayerFacingAngle(playerid,122.4500);
        
SetPlayerColor(playerid,0xA000FFFF); 
    }
else if(
classid == || classid == || classid == || classid == 7)
    {
        
gTeam[playerid] = ROBBERS;
        
GameTextForPlayer(playerid,"~r~ROBBERS",3000,5);
        
SetPlayerPos(playerid,2500.6060,-1672.1453,13.3512);
        
SetPlayerCameraPos(playerid,2507.0615,-1674.3574,13.3732);
        
SetPlayerCameraLookAt(playerid,2500.6060,-1672.1453,13.3512);
        
SetPlayerFacingAngle(playerid,252.4717);
        
SetPlayerColor(playerid,0x55FF00FF);
    }

Here, the code checks if the classid equals any of these numbers, and if it is, will execute the code below, as we put "1" it will return "true".
PHP код:
if(classid == || classid == || classid == || classid == 3
I do not know if it understood correctly how it works, but you can read HERE, this will give a great visibility on pawn and its functionalities.
Reply
#4

Quote:
Originally Posted by ApolloScripter
Посмотреть сообщение
Hello,RetroEX your public function has a parameter, in which it will pass a value to be performed.

PHP код:
public SetPlayerTeamFromClass(playeridclassid//classid is your parameter 
so for example, you use this function, in your command

PHP код:
CMD:changeteam(playeridparams[])
{
    
SetPlayerTeamFromClass(playeridclassid);
    return 
1;

This will give error, because classid is the parameter of your function, if you want to put some player on another team, you need to put the ID of that team, as described below:

PHP код:
CMD:changeteam(playeridparams[])
{
    
SetPlayerTeamFromClass(playerid1); //For example "1"
    
return 1;

So, how it works inside of your function?
As you called your function in the command, and put "1" as the class id, then the classid of this function will assume the value of 1, and will execute every body of the function.

PHP код:
public SetPlayerTeamFromClass(playeridclassid//classid will be "1"
{
if(
classid == || classid == || classid == || classid == 3)
    {
        
gTeam[playerid] = COPS;
        
GameTextForPlayer(playerid,"~b~COPS",3000,5);
        
SetPlayerPos(playerid,1975.2399,-1220.0157,25.0779); 
        
SetPlayerCameraPos(playerid,1969.5686,-1224.0016,24.9909); 
        
SetPlayerCameraLookAt(playerid,1975.2399,-1220.0157,25.0779);
        
SetPlayerFacingAngle(playerid,122.4500);
        
SetPlayerColor(playerid,0xA000FFFF); 
    }
else if(
classid == || classid == || classid == || classid == 7)
    {
        
gTeam[playerid] = ROBBERS;
        
GameTextForPlayer(playerid,"~r~ROBBERS",3000,5);
        
SetPlayerPos(playerid,2500.6060,-1672.1453,13.3512);
        
SetPlayerCameraPos(playerid,2507.0615,-1674.3574,13.3732);
        
SetPlayerCameraLookAt(playerid,2500.6060,-1672.1453,13.3512);
        
SetPlayerFacingAngle(playerid,252.4717);
        
SetPlayerColor(playerid,0x55FF00FF);
    }

Here, the code checks if the classid equals any of these numbers, and if it is, will execute the code below, as we put "1" it will return "true".
PHP код:
if(classid == || classid == || classid == || classid == 3
I do not know if it understood correctly how it works, but you can read HERE, this will give a great visibility on pawn and its functionalities.
Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)