SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 17/07/2010, 08:30 PM   #1
Emanuel_Rodriguez
Little Clucker
 
Join Date: May 2010
Posts: 39
Reputation: 4
Default Team Cars and Team Players

So like always, make sure you define the a_samp include file.

pawn Code:
#include <a_samp>

That just defines, that you are going to be scripting a San Andreas Multiplayer server. Next you will have to add the new files. We want to make Team Players, so put this under the #include, add this:

pawn Code:
new gTeam[MAX_PLAYERS];

That defines, that there are teams in you server, with a maximum of 250 players in your server(MAX_PLAYERS does not equal, infinity. In SA-MP it equals 250 players). Next we have define our teams. So above the new file, and below the include file, add this:

pawn Code:
#define GROVE_STREET 1
#define POLICE 2

This right here, defines that GROVE_STREET 1, and POLICE 2 will do something (in this case, they will be two separate teams). In order for your nametag to show up as the Team Color you are in, you must define these two, right underneath the #define POLICE 2:

pawn Code:
#define GROVE_STREET_COLOUR 0x00820FAA
#define POLICE_COLOUR 0x003DF5AA

This defines that GROVE_STREET_COLOUR is Green (0x00820FAA), and that POLICE_COLOUR is Blue (0x003DF5AA). So far our script should look like this:

pawn Code:
#include <a_samp>

#define GROVE_STREET 1
#define POLICE 2
#define GROVE_STREET_COLOUR 0x00820FAA
#define POLICE_COLOUR 0x003DF5AA

new gTeam[MAX_PLAYERS];

The Next thing you want to do is make sure that you have skins for you Team. So we are gonna add a Grove Street Gang member skin and a Police Officer skin under OnGameModeInit. So under the new file, add this:

pawn Code:
public OnGameModeInit()
{
    AddPlayerClass(105,2497.2693,-1676.9578,13.3398,23.6501,0,0,0,0,0,0); //Grove Street Gang Member (0)
    AddPlayerClass(280,1544.0514,-1675.7766,13.5577,98.0974,0,0,0,0,0,0); //Police Officer (1)
    return 1;
}

Next all we have to do is make sure the Class gets changed into a Team. So under OnPlayerRequestClass, add this:

pawn Code:
public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerTeamFromClass(playerid, classid);
    return 1;
}

What we did there was, when you get to request a skin, and you select it, it will set the team from the class you chose. Now we have to make sure that the class you chose, gives you the appropriate nametag color. So under OnPlayerSpawn, add this:

pawn Code:
public OnPlayerSpawn(playerid)
{
    SetPlayerToTeamColour(playerid);
    return 1;
}

This basically added a player who spawns, to the appropriate team Color. But nothing will work unless you have this next few lines scripted. To be able to determine whether you're a cop or a gang member, you must make sure you Set the Player Team from the Class. So underneath everything script this:

pawn Code:
SetPlayerTeamFromClass(playerid, classid)
{
    if(classid == 0)
    {
        gTeam[playerid] = GROVE_STREET;
    }
}

Next you will tell gTeam, that this is a Grove Street Gang Member, and his nametag should be green. So next add this under everything:

pawn Code:
SetPlayerToTeamColour(playerid)
{
    if(gTeam[playerid] == GROVE_STREET)
    {
        SetPlayerColor(playerid,GROVE_STREET_COLOUR); //Green
    }
}

This basically sets the Grove Street Gang Member to the Grove Street Color, we had defined earlier which was green, so, now this nametag is green. Now Lets add the Police the exact same way. It should look something like this:

pawn Code:
SetPlayerTeamFromClass(playerid, classid)
{
    if(classid == 0)
    {
        gTeam[playerid] = GROVE_STREET;
    }
    if(classid == 1)
    {
        gTeam[playerid] = POLICE;
    }
}

SetPlayerToTeamColour(playerid)
{
    if(gTeam[playerid] == GROVE_STREET)
    {
        SetPlayerColor(playerid,GROVE_STREET_COLOUR); //Green
    }
    if(gTeam[playerid] == POLICE)
    {
        SetPlayerColor(playerid,POLICE_COLOUR); // Blue
    }
}

REMEMBER: the skin id goes up by number as you go down the player class. (for example: if grove street gang member is 0, so will be the classid.

Next we must add Team Cars (If you are a Grove Street Gang Member, and you attempt to get into a Police Car, it will say, You do not have the keys to this car). So now add this in between, #define files and new files:

pawn Code:
enum TeamCars
{
GroveStreet,
Police
}

This made it where these two title ids, are TeamCars. So to make them TeamCars, make sure you define this, on top of the new file:

pawn Code:
new Cars[TeamCars];

This Defines Cars as [any team in here]. Next we create the vehicle. (you can either do AddStaticVehicle, or CreateVehicle, but make sure at the beggining, you put Cars[Team name here]). Now Add the Police Car, and the Greenwood into Los Santos, so it will look like this under OnGameModeInit:

pawn Code:
public OnGameModeInit()
{
    AddPlayerClass(105,2497.2693,-1676.9578,13.3398,23.6501,0,0,0,0,0,0); //Grove Street Gang Member (0)
    AddPlayerClass(280,1544.0514,-1675.7766,13.5577,98.0974,0,0,0,0,0,0); //Police Officer (1)
    Cars[GroveStreet] = CreateVehicle(492,2484.3054,-1655.0886,13.1036,90.8565,44,16,900); //Greenwood
    Cars[Police] = CreateVehicle(596,1536.0603,-1676.5302,13.1054,0.6847,-1,-1,900); //LSPD Cruiser
    return 1;
}

Next we make sure that the Script Gets the vehicle and know that you are not part of that team. Under everything add this:

pawn Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == 2)
    {
        new CarCheck = GetPlayerVehicleID(playerid);
        if(CarCheck == Cars[GroveStreet] )
        {
            if(gTeam[playerid] != 1)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_RED, "You Don't have the keys for this car!");
                return 1;
            }
        }
        if(CarCheck == Cars[Police] )
        {
            if(gTeam[playerid] != 2)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_RED, "You Don't have the keys for this car!");
                return 1;
            }
        }
        return 1;
    }
    return 1;
}

This here makes sure that if you try to get into one of the cars, it will not let you. For example, if gTeam(playerid) is not equal to 1, then removeplayerfromvehicle and send him a message in red saying You Don't have the keys for this car! So now, lets define the Color Red. On top of the script under the last #define, add this:

pawn Code:
#define COLOR_RED 0xFF0000AA

That just defined the Color Red. So here we are! WE ARE DONE! You have made your own player teams, and car teams! Enjoy them, and practice making more, as more more make is more progress for you!
Emanuel_Rodriguez is offline   Reply With Quote
Old 17/07/2010, 09:02 PM   #2
Thebest96
Big Clucker
 
Join Date: May 2010
Posts: 198
Reputation: 3
Default Re: Team Cars and Team Players

This is for DM server?
or rp?
Thebest96 is offline   Reply With Quote
Old 17/07/2010, 09:05 PM   #3
[XST]O_x
High-roller
 
[XST]O_x's Avatar
 
Join Date: Aug 2009
Posts: 1,960
Reputation: 94
Default Re: Team Cars and Team Players

Quote:
Originally Posted by Thebest96 View Post
This is for DM server?
or rp?
TDM/CnR IMO.

Pretty basic tutorial,but still I always appreciate effort.
Good job.
[XST]O_x is offline   Reply With Quote
Old 17/07/2010, 09:08 PM   #4
Thebest96
Big Clucker
 
Join Date: May 2010
Posts: 198
Reputation: 3
Default Re: Team Cars and Team Players

can you show me for RP?
Faction LSPD please?
Thebest96 is offline   Reply With Quote
Old 20/07/2010, 11:35 PM   #5
Desertsoulz
Huge Clucker
 
Desertsoulz's Avatar
 
Join Date: Jul 2010
Posts: 206
Reputation: 14
Default Re: Team Cars and Team Players

Quote:
C:\Users\Desertsoulz_2\Desktop\SA-MP\GTA San Andreas\SAMP\gamemodes\ADMINS.pwn(9) : error 001: expected token: "-identifier-", but found "-integer value-"
C:\Users\Desertsoulz_2\Desktop\SA-MP\GTA San Andreas\SAMP\gamemodes\ADMINS.pwn(20) : warning 213: tag mismatch
C:\Users\Desertsoulz_2\Desktop\SA-MP\GTA San Andreas\SAMP\gamemodes\ADMINS.pwn(20) : error 032: array index out of bounds (variable "Cars")
C:\Users\Desertsoulz_2\Desktop\SA-MP\GTA San Andreas\SAMP\gamemodes\ADMINS.pwn(21) : warning 213: tag mismatch
C:\Users\Desertsoulz_2\Desktop\SA-MP\GTA San Andreas\SAMP\gamemodes\ADMINS.pwn(21) : error 032: array index out of bounds (variable "Cars")
C:\Users\Desertsoulz_2\Desktop\SA-MP\GTA San Andreas\SAMP\gamemodes\ADMINS.pwn(22) : warning 213: tag mismatch
C:\Users\Desertsoulz_2\Desktop\SA-MP\GTA San Andreas\SAMP\gamemodes\ADMINS.pwn(22) : error 032: array index out of bounds (variable "Cars")
C:\Users\Desertsoulz_2\Desktop\SA-MP\GTA San Andreas\SAMP\gamemodes\ADMINS.pwn(23) : warning 213: tag mismatch
C:\Users\Desertsoulz_2\Desktop\SA-MP\GTA San Andreas\SAMP\gamemodes\ADMINS.pwn(23) : error 032: array index out of bounds (variable "Cars")
C:\Users\Desertsoulz_2\Desktop\SA-MP\GTA San Andreas\SAMP\gamemodes\ADMINS.pwn(60) : warning 213: tag mismatch
C:\Users\Desertsoulz_2\Desktop\SA-MP\GTA San Andreas\SAMP\gamemodes\ADMINS.pwn(60) : error 032: array index out of bounds (variable "Cars")
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
Please respond, I tried to make an Admin team for CnR

Here's the script.


Code:
#include <a_samp>

#define ADMINS 99
#define ADMINS_COLOR 0xFF00FFAA //Purple
#define COLOR_RED 0xFF0000AA //RED

enum TeamCars
{
ADMINS
}

new gTeam[MAX_PLAYERS];
new Cars[TeamCars];

public OnGameModeInit()
{
    AddPlayerClass(163,2127.6602,2377.6648,10.8203,182.7401,0,0,0,0,0,0);
    AddPlayerClass(164,2127.6602,2377.6648,10.8203,182.7401,0,0,0,0,0,0);

	Cars[ADMINS] = CreateVehicle(522,2091.4963,2361.1116,10.8058,183.7787,85,0,1000); //
	Cars[ADMINS] = CreateVehicle(522,2093.6804,2360.7153,10.8131,180.7032,85,0,1000); //
	Cars[ADMINS] = CreateVehicle(522,2095.8301,2361.1843,10.8129,177.7382,85,0,1000); //
	Cars[ADMINS] = CreateVehicle(522,2098.3806,2361.2388,10.8129,177.9737,85,0,1000); //
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerTeamFromClass(playerid, classid);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    SetPlayerToTeamColour(playerid);
    return 1;
}

SetPlayerTeamFromClass(playerid, classid)
{
    if(classid == 99)
    {
        gTeam[playerid] = ADMINS;
    }
}

SetPlayerToTeamColour(playerid)
{
    if(gTeam[playerid] == ADMINS)
    {
        SetPlayerColor(playerid,ADMINS_COLOR); //Purple
    }
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == 2)
    {
        new CarCheck = GetPlayerVehicleID(playerid);
        if(CarCheck == Cars[ADMINS] )
        {
            if(gTeam[playerid] != 99)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_RED, "You can't drive this car!");
                return 1;
            }
        }
        return 1;
    }
    return 1;
}
Desertsoulz is offline   Reply With Quote
Old 20/07/2010, 11:46 PM   #6
Scenario
Godfather
 
Scenario's Avatar
 
Join Date: Feb 2010
Location: Heaven
Posts: 7,801
Reputation: 701
Default Re: Team Cars and Team Players

Nevermind

Last edited by Scenario; 20/07/2010 at 11:59 PM.
Scenario is offline   Reply With Quote
Old 26/07/2010, 03:22 PM   #7
3ventic
Huge Clucker
 
3ventic's Avatar
 
Join Date: Jun 2009
Location: Finland
Posts: 317
Reputation: 70
Default Re: Team Cars and Team Players

Quote:
Originally Posted by Desertsoulz View Post
Please respond, I tried to make an Admin team for CnR

Here's the script.


Code:
#include <a_samp>

#define ADMINS 99
#define ADMINS_COLOR 0xFF00FFAA //Purple
#define COLOR_RED 0xFF0000AA //RED

enum TeamCars
{
ADMINS
}

new gTeam[MAX_PLAYERS];
new Cars[TeamCars];

public OnGameModeInit()
{
    AddPlayerClass(163,2127.6602,2377.6648,10.8203,182.7401,0,0,0,0,0,0);
    AddPlayerClass(164,2127.6602,2377.6648,10.8203,182.7401,0,0,0,0,0,0);

	Cars[ADMINS] = CreateVehicle(522,2091.4963,2361.1116,10.8058,183.7787,85,0,1000); //
	Cars[ADMINS] = CreateVehicle(522,2093.6804,2360.7153,10.8131,180.7032,85,0,1000); //
	Cars[ADMINS] = CreateVehicle(522,2095.8301,2361.1843,10.8129,177.7382,85,0,1000); //
	Cars[ADMINS] = CreateVehicle(522,2098.3806,2361.2388,10.8129,177.9737,85,0,1000); //
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerTeamFromClass(playerid, classid);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    SetPlayerToTeamColour(playerid);
    return 1;
}

SetPlayerTeamFromClass(playerid, classid)
{
    if(classid == 99)
    {
        gTeam[playerid] = ADMINS;
    }
}

SetPlayerToTeamColour(playerid)
{
    if(gTeam[playerid] == ADMINS)
    {
        SetPlayerColor(playerid,ADMINS_COLOR); //Purple
    }
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == 2)
    {
        new CarCheck = GetPlayerVehicleID(playerid);
        if(CarCheck == Cars[ADMINS] )
        {
            if(gTeam[playerid] != 99)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_RED, "You can't drive this car!");
                return 1;
            }
        }
        return 1;
    }
    return 1;
}
Try using

Code:
enum TeamCars
{
ADMIN
}
instead of ADMINS and change every Cars[ADMINS] to Cars[ADMIN]. But don't change any other ADMINS.

Here's the full code with those changed:
Code:
#include <a_samp>

#define ADMINS 99
#define ADMINS_COLOR 0xFF00FFAA //Purple
#define COLOR_RED 0xFF0000AA //RED

enum TeamCars
{
ADMIN
}

new gTeam[MAX_PLAYERS];
new Cars[TeamCars];

public OnGameModeInit()
{
    AddPlayerClass(163,2127.6602,2377.6648,10.8203,182.7401,0,0,0,0,0,0);
    AddPlayerClass(164,2127.6602,2377.6648,10.8203,182.7401,0,0,0,0,0,0);

	Cars[ADMIN] = CreateVehicle(522,2091.4963,2361.1116,10.8058,183.7787,85,0,1000); //
	Cars[ADMIN] = CreateVehicle(522,2093.6804,2360.7153,10.8131,180.7032,85,0,1000); //
	Cars[ADMIN] = CreateVehicle(522,2095.8301,2361.1843,10.8129,177.7382,85,0,1000); //
	Cars[ADMIN] = CreateVehicle(522,2098.3806,2361.2388,10.8129,177.9737,85,0,1000); //
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerTeamFromClass(playerid, classid);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    SetPlayerToTeamColour(playerid);
    return 1;
}

SetPlayerTeamFromClass(playerid, classid)
{
    if(classid == 99)
    {
        gTeam[playerid] = ADMINS;
    }
}

SetPlayerToTeamColour(playerid)
{
    if(gTeam[playerid] == ADMINS)
    {
        SetPlayerColor(playerid,ADMINS_COLOR); //Purple
    }
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == 2)
    {
        new CarCheck = GetPlayerVehicleID(playerid);
        if(CarCheck == Cars[ADMIN] )
        {
            if(gTeam[playerid] != 99)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_RED, "You can't drive this car!");
                return 1;
            }
        }
        return 1;
    }
    return 1;
}
3ventic is offline   Reply With Quote
Old 26/07/2010, 03:34 PM   #8
R@ger
Big Clucker
 
Join Date: Apr 2010
Posts: 73
Reputation: 0
Default Re: Team Cars and Team Players

nice emanuel +1
R@ger is offline   Reply With Quote
Old 29/07/2010, 07:30 PM   #9
Steven82
High-roller
 
Join Date: Nov 2009
Posts: 2,431
Reputation: 186
Default Re: Team Cars and Team Players

Dude, are people seriously asking to show you how to make them like RP? He just did, you just got to edit some things up. And thats all.
__________________
If you read my old posts; I apologize in advance.
Steven82 is offline   Reply With Quote
Old 30/07/2010, 03:40 AM   #10
Scenario
Godfather
 
Scenario's Avatar
 
Join Date: Feb 2010
Location: Heaven
Posts: 7,801
Reputation: 701
Default Re: Team Cars and Team Players

Quote:
Originally Posted by 3ventic View Post
Try using

Code:
enum TeamCars
{
ADMIN
}
instead of ADMINS and change every Cars[ADMINS] to Cars[ADMIN]. But don't change any other ADMINS.

Here's the full code with those changed:
Code:
#include <a_samp>

#define ADMINS 99
#define ADMINS_COLOR 0xFF00FFAA //Purple
#define COLOR_RED 0xFF0000AA //RED

enum TeamCars
{
ADMIN
}

new gTeam[MAX_PLAYERS];
new Cars[TeamCars];

public OnGameModeInit()
{
    AddPlayerClass(163,2127.6602,2377.6648,10.8203,182.7401,0,0,0,0,0,0);
    AddPlayerClass(164,2127.6602,2377.6648,10.8203,182.7401,0,0,0,0,0,0);

	Cars[ADMIN] = CreateVehicle(522,2091.4963,2361.1116,10.8058,183.7787,85,0,1000); //
	Cars[ADMIN] = CreateVehicle(522,2093.6804,2360.7153,10.8131,180.7032,85,0,1000); //
	Cars[ADMIN] = CreateVehicle(522,2095.8301,2361.1843,10.8129,177.7382,85,0,1000); //
	Cars[ADMIN] = CreateVehicle(522,2098.3806,2361.2388,10.8129,177.9737,85,0,1000); //
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerTeamFromClass(playerid, classid);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    SetPlayerToTeamColour(playerid);
    return 1;
}

SetPlayerTeamFromClass(playerid, classid)
{
    if(classid == 99)
    {
        gTeam[playerid] = ADMINS;
    }
}

SetPlayerToTeamColour(playerid)
{
    if(gTeam[playerid] == ADMINS)
    {
        SetPlayerColor(playerid,ADMINS_COLOR); //Purple
    }
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == 2)
    {
        new CarCheck = GetPlayerVehicleID(playerid);
        if(CarCheck == Cars[ADMIN] )
        {
            if(gTeam[playerid] != 99)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_RED, "You can't drive this car!");
                return 1;
            }
        }
        return 1;
    }
    return 1;
}
Uh, what's your point? Do you think if you change one darn letter it will make it only for admins? Are you insane?
Scenario 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



All times are GMT. The time now is 03:09 AM.


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