SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 11/01/2019, 05:45 PM   #1
RetroEX
Little Clucker
 
Join Date: Dec 2018
Posts: 3
Reputation: 0
Default changeteam command

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:
Code:
CMD:changeteam(playerid, params[])
{
    SetPlayerTeamFromClass(playerid, classid);
    return 1;
}
SetPlayerTeamFromClass:
Code:
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!
RetroEX is offline   Reply With Quote
Old 11/01/2019, 05:47 PM   #2
RetroEX
Little Clucker
 
Join Date: Dec 2018
Posts: 3
Reputation: 0
Default Re: changeteam command

I forgot, when compiling it gives me the error:
Code:
error 017: undefined symbol "classid"
for
Code:
CMD:changeteam(playerid, params[])
{
    SetPlayerTeamFromClass(playerid, classid);
    return 1;
}
RetroEX is offline   Reply With Quote
Old 11/01/2019, 08:15 PM   #3
ApolloScripter
Big Clucker
 
ApolloScripter's Avatar
 
Join Date: Sep 2018
Posts: 155
Reputation: 1
Default Re: changeteam command

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

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

PHP Code:
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 Code:
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 Code:
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 Code:
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.
__________________
ApolloScripter is online now   Reply With Quote
Old 12/01/2019, 09:41 AM   #4
RetroEX
Little Clucker
 
Join Date: Dec 2018
Posts: 3
Reputation: 0
Default Re: changeteam command

Quote:
Originally Posted by ApolloScripter View Post
Hello,RetroEX your public function has a parameter, in which it will pass a value to be performed.

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

PHP Code:
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 Code:
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 Code:
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 Code:
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!
RetroEX is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
changeteam problem.. Younes44 Scripting Help 7 06/08/2016 09:43 PM
Help with /changeteam prooftzm Scripting Help 10 05/07/2014 05:11 PM
/changeteam command HyDrAtIc Scripting Help 7 20/10/2012 08:26 PM
/changeteam marwan Help Archive 4 11/06/2011 10:03 AM
/changeteam <ID> marinov Help Archive 11 10/11/2010 12:41 AM


All times are GMT. The time now is 08:59 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.