[Tutorial] Basic Join a team command
#1

In this tutorial, I will show you how to make a very basic command to join a team.

Firstly, We start by defining our teams. So before your OnGameModeInit add this.

pawn Код:
#define team_cop 1 // Cop team
#define team_criminal 2 // Criminal team
And now defining our team colors, so;

pawn Код:
#define copcolor 0x375FFFFF
#define criminalcolor 0xFF0000FF
Now we want to add a new Global Variable to store our teams, So again before OnGameModeInit add the following;
pawn Код:
new pTeam[MAX_PLAYERS];
Now we want to add the command to join a team, So under OnPlayerCommandText, Paste this.

pawn Код:
if (strcmp("/cop", cmdtext, true, 10) == 0)
{
    SendClientMessage(playerid, soldiercolor, "You are now on the cop team");
    pTeam[playerid] = team_cop;
    SetPlayerSkin(playerid, 281);
    GivePlayerWeapon(playerid, 17, 10);
    SetPlayerPos(playerid, 309, 2060, 18);
    return 1;
}
Now even though this code is pretty self explanatory, I will explain it for you.

pawn Код:
SendClientMessage(playerid, copcolor, "You are now on the cop team");
Basically this will send whoever entered the command (playerid) Then send them the string "You are now on the cop team" In the color blue (Defined as copcolor).

pawn Код:
pTeam[playerid] = team_cop;
Now this will set the player who executed the command into the cop team, Storing it in the variable pTeam.

pawn Код:
SetPlayerSkin(playerid, 281);
Self explanatory, Sets the players skin to 281 (Easily changeable just choose a skin id from here and replace the 281 with your selected skin id.

pawn Код:
GivePlayerWeapon(playerid, 17, 10);
Also self explanatory, Gives the player the selected gun and amount of ammo (Ids are in that order so replace 17 for your gun id and 10 for the amount of ammo) Gun ids can be found here

pawn Код:
SetPlayerPos(playerid, 309, 2060, 18);
Once again, Self explanatory. 309 is your x co-ordinate, 2060 is your y co-ordinate and 18 is your z co-ordinate.
(You can get these by going in-game and typing /save at the co-ordinates location you want, Then going into your user files.




Note: I am not saying this is the best way to create teams in anyway. However this can be used as a learning base for new scripters. You can also improve this and maybe soon i will update this tutorial to add team cars using enums also.

Hope this tutorial has helped, Again if i have missed something out then please notify me so i can correct it.
Reply
#2

Nice and simple tut,can be useful for newbies/beginners
Reply
#3

So, please explain me what the 10 does in this line?
pawn Код:
if (strcmp("/cop", cmdtext, true, 10) == 0)
Copy-pasta without even looking at a function's parameters.
Reply
#4

idk still why people copy paste can't they learn it on their own and then help other guys who are in needs of help?
Reply
#5

useful for beginners, nice work.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)