[Tutorial] Getting Started on TDM Scripting for newbie (Setting up team, Setting up team color, Anti teamkill[EXPLAINED]
#1

============================
INTRODUCTION

============================
Hello guys, im back with new tutorial. This tutorial explaining about how to getting started on TDM Scripting for you guys that have just getting started and want to make simple TDM. So why wasting time. lets start!

REQUIRETMENTS
1.Pawno basic scripting knowledge
2.Brain

Working
1.Setting Up Our team by class!
Okay so the first step we are going on do here is setting up our team depends by classes. Take it, we had army class skin, so we want to set it as army team, etc.

First, we are going to add our classes. We gotta put it on call back function OnGameModeInit
pawn Code:
public OnGameModeInit()
{
AddPlayerClass(287,-1318.9600,495.7722,18.2344,268.8795,0,0,0,0,0,0);
AddPlayerClass(285,-1615.5643,683.4233,7.1875,176.2447,0,0,0,0,0,0);
return 1;
}
Here i had army class which spawned on Militarry ship on San Fierro:
pawn Code:
AddPlayerClass(287,-1318.9600,495.7722,18.2344,268.8795,0,0,0,0,0,0);
And that another one is SWAT skin spawned on SFPD Office
We have just added our classes!Now time to setting up the team!

Before to setting up team, we are going to create a variable which stands for handle player team
In the top of your script add this:

pawn Code:
new pTeam[MAX_PLAYERS];
You might get this warning when you hit compile:
pawn Code:
Symbol that is never used, pTeam
Dont worry, it will be fixed soon!

And dont forget to define the team:
pawn Code:
#define ARMY 0
#define COP 1

And now time to setting up your team.
Add this:
pawn Code:
public OnPlayerRequestClass(playerid,classid)
{
if(classid == 0)
{
pTeam[playerid] = ARMY;
}
if(classid == 1)
{
pTeam[playerid] = COP;
}
return 1;
}
Lil explanation:
Generally, when we are connected there will be classes to shown. If we switch to first class, we setted the team to ARMY. While, if switch for next class /second class,we setted the team to COP

And ofc, we dont want everyone kill each other. Therefore, we gotta set player color depends on their team. Add this:

pawn Code:
public OnPlayerSpawn(playerid)
{
if(pTeam[playerid] == ARMY)
{
SetPlayerColour(playerid,COLOR_GREY);//Change the color, as color you have defined Before
}
if(pTeam[playerid] == COPS)
{
SetPlayerColour(playerid,COLOR_BLUE);//Change the color, as color you have defined
GivePlayerWeapon(playerid,31,200);
}
}
Okay lil explanation:
If player select Army skin on class selection, once they spawned, their color will be turned to Grey. Otherwise, if they selected SWAT skin on class selection, once they spawned, their color will be turned to blue. And, they will be given a M4 Per spawned.Of course you can change it as you want.

Okay we have done here, and we setted UP OUR TEAM!
Now, we want make simple anti teamkill! So, when they attacked their teammate, they will get warnings to not do teamkill.

Add this:
pawn Code:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    if(pTeam[issuerid] == pTeam[playerid])
    {
        new Float:health,Float:Armour;
        GetPlayerHealth(playerid,health);//get the player health
        GetPlayerArmour(playerid,Armour);//get player amour
        SetPlayerHealth(playerid,health);/set their health to default health
        SetPlayerArmour(playerid,Armour);//set their armour to default armour
        GameTextForPlayer(issuerid,"Watch your shoot!",2000,5);//give a warning to attacker, that he attacked teammate
    }
    else
    {
        PlayerPlaySound(issuerid,1057,0,0,0);//Playing a sound for attacker, that he has damaged someone
     }
    return 1;
}
issuerid is stands for attacker id, that just attacked someone. If he attacked teammate, he will get warning, by gametext.



Okay we've done here. I hope this tutorial helped
Reply
#2

Why use a variable for teams? You could just use natives: GetPlayerTeam / SetPlayerTeam
Reply
#3

Quote:
Originally Posted by dusk
View Post
Why use a variable for teams? You could just use natives: GetPlayerTeam / SetPlayerTeam
To make it a bit easily
Reply
#4

No More comments?
Reply
#5

Nice tutorial

+REP
Reply
#6

What dusk said,

SetPlayerTeam will automatically disable team killing, I would only use variables if I wanted friendly fire turned off.
Reply
#7

pawn Code:
PlayerPlaySound(issuerid,1057,0,0,0);//Playing a sound for attacker, that he has damaged someone
Is this the beeping noise or what noise is it? And the tutorial is ok.
Reply
#8

Quote:
Originally Posted by DanishHaq
View Post
pawn Code:
PlayerPlaySound(issuerid,1057,0,0,0);//Playing a sound for attacker, that he has damaged someone
Is this the beeping noise or what noise is it? And the tutorial is ok.
Well, it would like to play the "ding dong" sound when you hit someone
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)