SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 02/08/2011, 07:15 AM   #1
Basicz
Gangsta
 
Basicz's Avatar
 
Join Date: Aug 2010
Location: Indonesia, Surabaya.
Posts: 629
Reputation: 35
Default Make your own team deathmatch with SetPlayerTeam

Hi peoples, in this tutorial I will teach you how to make your own Team deathmatch ( TDM ) gamemode.

1. Introduction
- What is Team Deathmatch?

It is some kind of a deathmatch, but with teams!

2. Requirements
1. A basic PAWN knowledge.

3. Creating the gamemode
Open your pawno program, click CTRL+A on your keyboard ( Select all ) and delete it.

Add the following code :

Code:
#include    < a_samp >
We are including a_samp, the include itself also includes some other files, which will help us ( Some includes got an useful functions ).

Next, we will define team ID's
Code:
#define TEAM_BALLAS ( 0 ) // Defines TEAM_BALLAS as team ID 0
#define TEAM_CJ ( 1 ) // Defines TEAM_CJ as team ID 1

Below it add :

Code:
main( )

- What is that thing?

As far as I know, it's a callback which starts after OnGameModeInit, and AFAIK it won't be called on a filterscript ( #define FILTERSCRIPT )


Code:
main( )
{ // Opening bracket
    print( ">> Team deathmatch by < yourname > has been loaded!" );
} // Closing bracket

print is a function which will sends a message on the server console.

And add this :
Code:
public OnGameModeInit( ) // This callback is called when the gamemode is started.
{
    return 1; // This means, the gamemode is processed succesfully AFAIK.
}

3.1. Adding classes
Quote:
You will probably want to move some of your spawn points about so everyone doesn't spawn in the same place, which would make a rather boring deathmatch and camping amazingly easy. This is where the debug mode comes in. Run "samp_debug.exe" in your San Andreas root directory and whenever you want to save a co-ordinate type "/save" in the game (press "t" or the key under escape to bring up the text/chat prompt). This will save your current position, angle and playerid to a file called "savedpositions.txt" in your Documents/GTA SA Userfiles/savedpositions.txt
Quoted from SA-MP wiki.

Let's continue!

Add the classes ( from savedpositions.txt ) below OnGameModeInit
Code:
public OnGameModeInit( )
{
    AddPlayerClass( 102, 1958.3783, 1343.1572, 15.3746, 269.1425, 5, 0, 22, 100, 32, 50 ); // Ballas
    // The class above is classid 0.

    AddPlayerClass( 0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0 ); // CJ
    // Multiply the classid + 1, so this class is classid 1.

    AddPlayerClass( 1, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0 ); // The truth
    // Multiply the classid + 1 again, so this is classid 2.

    return 1;
}

AddPlayerClass will add a class, this is the arguments :
Code:
AddPlayerClass( skinID, Float: X, Float: Y, Float: Z, Float: A, Weapon 0, Ammo 0, Weapon 1, Ammo 1, Weapon 2, Ammo 2 );
.

Let's continue again.

Now we will add a callback which will calls when a player is on class selection.

Code:
public OnPlayerRequestClass( playerid, classid ) //  This is called when a player is on class selection
{
    return 1; // This means the callback is executed succesfully AFAIK.
}

We will add gametexts!

Code:
public OnPlayerRequestClass( playerid, classid ) //  This is called when a player is on class selection
{
    switch ( classid ) // This is like a if/elseif statement.
    {
        case 0: // If the classid is 0
        { // Then
            GameTextForPlayer( playerid, "~r~TEAM Ballas", 300, 3 );
            // Sends a gametext for player
            // ~r~ is a red color in gametext.
            // Arguments : Player ID, const string[ ], time ( milliseconds ), style 
            // Wiki for more info
            SetPlayerTeam( playerid, TEAM_BALLAS ); // Sets the player's team to TEAM_BALLAS
        }

        case 1: // If the classid is 1
        { // Then
            GameTextForPlayer( playerid, "~g~TEAM CJ", 300, 3 );
            // Sends a gametext for player
            // ~g~ is a green color in gametext.
            // Arguments : Player ID, const string[ ], time ( milliseconds ), style 
            // Wiki for more info
            SetPlayerTeam( playerid, TEAM_CJ ); // Sets the player's team to TEAM_CJ
        }

        case 2: // If the classid is 2
        { // Then
            GameTextForPlayer( playerid, "~g~TEAM CJ", 300, 3 );
            // Sends a gametext for player
            // ~g~ is a green color in gametext.
            // Arguments : Player ID, const string[ ], time ( milliseconds ), style 
            // Wiki for more info
            SetPlayerTeam( playerid, TEAM_CJ ); // Sets the player's team to TEAM_CJ
        }
    }    
    return 1; // This means the callback is executed succesfully AFAIK.
}

Let's continue.

We will add an anti-teamkill! ( With SetPlayerTeam they can still be killed with knifes. )

Code:
public OnPlayerDeath( playerid, killerid, reason ) // This is called when a player deaths.
{
    if ( killerid != INVALID_PLAYER_ID ) // If the killerid are NOT an invalid player
    { // Then
        if ( GetPlayerTeam( killerid ) == GetPlayerTeam( playerid ) ) // If killerid's team == playerid's team ( who has been killed )
        { // Then
            SetPlayerHealth( killerid, -1 ); // Kills the killer ( Setting the health to -1 ).

            SendClientMessage( killerid, -1, "No teamkilling." ); // Sends a message to the killer with a white colour ( -1 ), with the message " No teamkilling. ".

            GivePlayerMoney( killerid, - 5000 ); // Take $5000 from the killerid, because teamkilling,
        }

        else // Another team killed the player
        {
            SendClientMessage( killerid, -1, "Nice shot!" ); // Sends a message to the killer with a white colour ( -1 ) with the message "Nice Shot! ".

            GivePlayerMoney( killerid, 5000 ); // Gives the killerid $5000.
        }
    }

    SendDeathMessage(  killerid, playerid, reason ); // Sends a death message about the killerid is killing the player, with the reason ( At the middle right of your game, can be toggled by pressing F9 ).

    return 1; // This means the callback is executed succesfully AFAIK.
}

The whole gamemode should looks like :
Code:
#include    < a_samp >

#define TEAM_BALLAS ( 0 ) // Defines TEAM_BALLAS as team ID 0
#define TEAM_CJ ( 1 ) // Defines TEAM_CJ as team ID 1

main( )
{ // Opening bracket
    print( ">> Team deathmatch by < yourname > has been loaded!" );
} // Closing bracket

public OnGameModeInit( )
{
    AddPlayerClass( 102, 1958.3783, 1343.1572, 15.3746, 269.1425, 5, 0, 22, 100, 32, 50 ); // Ballas
    // The class above is classid 0.

    AddPlayerClass( 0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0 ); // CJ
    // Multiply the classid + 1, so this class is classid 1.

    AddPlayerClass( 1, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0 ); // The truth
    // Multiply the classid + 1 again, so this is classid 2.

    return 1;
}

public OnPlayerRequestClass( playerid, classid ) //  This is called when a player is on class selection
{
    switch ( classid ) // This is like a if/elseif statement.
    {
        case 0: // If the classid is 0
        { // Then
            GameTextForPlayer( playerid, "~r~TEAM Ballas", 300, 3 );
            // Sends a gametext for player
            // ~r~ is a red color in gametext.
            // Arguments : Player ID, const string[ ], time ( milliseconds ), style
            // Wiki for more info
            SetPlayerTeam( playerid, TEAM_BALLAS ); // Sets the player's team to TEAM_BALLAS
        }

        case 1: // If the classid is 1
        { // Then
            GameTextForPlayer( playerid, "~g~TEAM CJ", 300, 3 );
            // Sends a gametext for player
            // ~g~ is a green color in gametext.
            // Arguments : Player ID, const string[ ], time ( milliseconds ), style
            // Wiki for more info
            SetPlayerTeam( playerid, TEAM_CJ ); // Sets the player's team to TEAM_CJ
        }

        case 2: // If the classid is 2
        { // Then
            GameTextForPlayer( playerid, "~g~TEAM CJ", 300, 3 );
            // Sends a gametext for player
            // ~g~ is a green color in gametext.
            // Arguments : Player ID, const string[ ], time ( milliseconds ), style
            // Wiki for more info
            SetPlayerTeam( playerid, TEAM_CJ ); // Sets the player's team to TEAM_CJ
        }
    }
    return 1; // This means the callback is executed succesfully AFAIK.
}

public OnPlayerDeath( playerid, killerid, reason ) // This is called when a player deaths.
{
    if ( killerid != INVALID_PLAYER_ID ) // If the killerid are NOT an invalid player
    { // Then
        if ( GetPlayerTeam( killerid ) == GetPlayerTeam( playerid ) ) // If killerid's team == playerid's team ( who has been killed )
        { // Then
            SetPlayerHealth( killerid, -1 ); // Kills the killer ( Setting the health to -1 ).

            SendClientMessage( killerid, -1, "No teamkilling." ); // Sends a message to the killer with a white colour ( -1 ), with the message " No teamkilling. ".

            GivePlayerMoney( killerid, - 5000 ); // Take $5000 from the killerid, because teamkilling,
        }

        else // Another team killed the player
        {
            SendClientMessage( killerid, -1, "Nice shot!" ); // Sends a message to the killer with a white colour ( -1 ) with the message "Nice Shot! ".

            GivePlayerMoney( killerid, 5000 ); // Gives the killerid $5000.
        }
    }

    SendDeathMessage(  killerid, playerid, reason ); // Sends a death message about the killerid is killing the player, with the reason ( At the middle right of your game, can be toggled by pressing F9 ).

    return 1; // This means the callback is executed succesfully AFAIK.
}

That's all I can bring, because I had a homework ATM.

Hope it can be useful for newbies!

p.s. This is my first tutorial I have ever made.
__________________

- Quina, from the game " Final Fantasy IX "
Basicz is offline   Reply With Quote
Old 02/08/2011, 07:16 AM   #2
Kush
Gangsta
 
Join Date: May 2011
Posts: 791
Reputation: 123
Default Re: Make your own team deathmatch with SetPlayerTeam

Not bad, Good Job. Explain more on Functions.

+Rep.
__________________
Quote:
Originally Posted by Dripac
i have more reputation than you, that means i am more clever than you my friend
Kush is offline   Reply With Quote
Old 02/08/2011, 07:22 AM   #3
Basicz
Gangsta
 
Basicz's Avatar
 
Join Date: Aug 2010
Location: Indonesia, Surabaya.
Posts: 629
Reputation: 35
Default Re: Make your own team deathmatch with SetPlayerTeam

Thanks for the quick reply, I will explain more ASAP, because I am busy right now.
__________________

- Quina, from the game " Final Fantasy IX "
Basicz is offline   Reply With Quote
Old 02/08/2011, 07:28 AM   #4
Shockey HD
Gangsta
 
Shockey HD's Avatar
 
Join Date: Jul 2011
Posts: 686
Reputation: 14
Default Re: Make your own team deathmatch with SetPlayerTeam

Can be very useful, nice tutorial.
__________________
Shockey HD is offline   Reply With Quote
Old 02/08/2011, 08:29 AM   #5
Lorenc_
High-roller
 
Lorenc_'s Avatar
 
Join Date: Jan 2010
Location: Australia
Posts: 4,279
Reputation: 1115
Default Re: Make your own team deathmatch with SetPlayerTeam

SetPlayerTeam can be buggy, I just noticed myself. I tried to implement anti-teamkill but it wouldn't work half of the time for some players that attempt team killing, overall nice.
__________________


Join the best Cops And Robbers in SA-MP, today. svr.irresistiblegaming.com:7777
Lorenc_ is offline   Reply With Quote
Old 02/08/2011, 08:33 AM   #6
Kush
Gangsta
 
Join Date: May 2011
Posts: 791
Reputation: 123
Default Re: Make your own team deathmatch with SetPlayerTeam

Quote:
Originally Posted by Lorenc_ View Post
SetPlayerTeam can be buggy, I just noticed myself. I tried to implement anti-teamkill but it wouldn't work half of the time for some players that attempt team killing, overall nice.
Agreed. I myself experienced problems with SetPlayerTeam. It would be best to simply create a variable which would represent each team.
__________________
Quote:
Originally Posted by Dripac
i have more reputation than you, that means i am more clever than you my friend
Kush is offline   Reply With Quote
Old 02/08/2011, 12:08 PM   #7
emokidx
Gangsta
 
emokidx's Avatar
 
Join Date: Jul 2011
Posts: 555
Reputation: 63
Default Re: Make your own team deathmatch with SetPlayerTeam

SetPlayerTeam is not very good for anti-teamkill as everyone has said..

nice tut,, it would help newbies
emokidx is offline   Reply With Quote
Old 18/11/2011, 08:28 PM   #8
Astralis
High-roller
 
Join Date: Sep 2009
Location: France
Posts: 3,108
Reputation: 388
Default Re: Make your own team deathmatch with SetPlayerTeam

good and explained. 5/5
__________________
http://samp4you.com
Hosted Tab 25€/mo || 100 Slots 5,50€/mo
Astralis is online now   Reply With Quote
Old 18/11/2011, 08:53 PM   #9
mehdi-jumper
High-roller
 
mehdi-jumper's Avatar
 
Join Date: Sep 2011
Location: New-Zealand
Posts: 1,878
Reputation: 51
Default Re : Make your own team deathmatch with SetPlayerTeam

Very nice, thanks but I have a problem: I want to have an anti teamkill in Los Santos but I don't want to have an anti tk on my /dm, special place like area 59 etc.. How to do that ?
mehdi-jumper is offline   Reply With Quote
Old 12/07/2013, 09:04 AM   #10
[email protected]
Huge Clucker
 
Er@x3r's Avatar
 
Join Date: Apr 2012
Posts: 333
Reputation: 14
Default Re: Make your own team deathmatch with SetPlayerTeam

nice tut but i have a problem




E:\grand theft auto\server\gamemodes\gangz.pwn(72) : error 040: duplicate "case" label (value 4)
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


1 Error.
Er@x3r 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
[GameMode] Team Deathmatch bestr32 Gamemode Scripts 15 17/03/2011 12:20 PM
team deathmatch team error Breaker Server Support 0 18/09/2010 10:12 PM
Team deathmatch Freddy Z Help Archive 8 05/01/2010 07:18 AM


All times are GMT. The time now is 11:59 AM.


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