How to use TeamKill Protection
#1

I have recently seeing lots of people asking for "how to use team kill protection" or something like that. Therefore, I will make a simple and easy tutorial on how to make Team Kill protection.

First, we need to define the teams at the top of your script write:
pawn Code:
#define TEAM_RED 0 // This is creating the first team named "Red"
#define TEAM_BLUE 1 // This is creating the second team named "Blue"
Now we will define the gTeam to set the teams from each other:
pawn Code:
new gTeam[MAX_PLAYERS];
Now we've defined gTeam and our teams lets create the teams and their classes. Do this in:
Code:
public OnGameModeInit()
{
     return 1;
}
pawn Code:
AddPlayerClass(118, 0, 0, 0, 0, 1, 2, 10, 10, 11,11);// This is creating a class for the player to choose from. As you should know 118 is the skin, the first three 0's are X, Y , Z and the fourth 0 is the rotation. Then the 1 is weapon id and the 2 is the ammo for weapon id 1 to spawn with and e.t.c.
AddPlayerClass(118, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);// Make sure you make these with what skins you want the teams to have and use make them spawn with their team.
Now we have the classes created we seperate the teams. Add SetPlayerTeamFromClass(playerid, classid) in your script. Make sure it is no in any other functions.
pawn Code:
SetPlayerTeamFromClass(playerid, classid)
{
      if (classid == 0)//This is using what we had at the top. #define TEAM_RED 0 if the classid = 0 then they are team red.
      {
               gTeam[playerid] = TEAM_RED;
      }
      else  //Else means any other ones will be
      {
               gTeam[playerid] = TEAM_BLUE;
      }
}
Now we must make the teamkill protection and timer. First lets make the timer. At the top of your script, again add
pawn Code:
forward TeamKill(); //This is a forward. It will wnable us to make the TeamKill() a public and create effects in the timer.
Now lets make the teamkill protecter. We will be editing here:
pawn Code:
public OnPlayerDeath(playerid, killerid, reason)
{
     return 1;
}
Under that add these lines:
pawn Code:
if(gTeam[killerid] == gTeam[playerid]) // [killerid] is the player who kills a/the player on their team. [playerid] is the player who is killed. Therefore it is saying if a player from a team kills a player on their team then they will have these effects belowll
     {
          SendClientMessage(killerid,0xAA3333AA,"You can't team kill,this is unfair,you are now frozen for 5 seconds.");// this is telling them they will be punished.
          TogglePlayerControllable(killerid,0); //this is making them freeze
          SetTimerEx("TeamKill", 5000, 0, "i", killerid); //this is creating the timer.TeamKill is what we used forward on. TeamKill will be the timer's name. 5000 is the milliseconds the timer will last. 0 means that it will not repeat. "i" means anyplayer that teamkills, and killerid is the player who killedthem.
          return 1;
     }
//Here you can have else and saying if it is a valid kill them give them money
Now we will create a public for the timer.
pawn Code:
public TeamKill()
{
    TogglePlayerControllable(playerid, 1); //unfreezing them
    SendClientMessage(playerid, 0xAA3333AA, "* You have been unfrozen!"); //sending a message saying you are unfrozen
    GameTextForPlayer(playerid, "~b~Unfrozen!", 8000, 3); //not neccesarry just creating gametext saying you are unfrozen
    return 1;
}
Now run. The script should have errors right? Well thats when you scroll up through the script and find where we forwarded the timer and do this:
pawn Code:
forward TeamKill(playerid);//this is just making us able to use playerid in this timer
No go back down to the timer used with public and add:
pawn Code:
public TeamKill(playerid)
Now you are done. This is just a basic team kill system.
Reply
#2

pawn Code:
#define gTeam[MAX_PLAYERS];
Ehm, I'm unsure if that'll work.

Did you test this actually?
Reply
#3

Quote:
Originally Posted by Hiddos
View Post
pawn Code:
#define gTeam[MAX_PLAYERS];
Ehm, I'm unsure if that'll work.

Did you test this actually?
Yes it works awesome. Sorry if you think it doesnt work thats your opinion. But on my script it works PERFECT
Reply
#4

Well I did a small compile on PAWN, 5 errors just for one line with gTeam[/];
Reply
#5

Quote:
Originally Posted by ToPhrESH
View Post
Yes it works awesome. Sorry if you think it doesnt work thats your opinion. But on my script it works PERFECT
*coughs* It's "new" not "#define". *coughs*
Reply
#6

This is not a teamkill protection, but a teamkill detector.
Reply
#7

thanks i need this
Reply
#8

Quote:
Originally Posted by Hiddos
View Post
Well I did a small compile on PAWN, 5 errors just for one line with gTeam[/];
heheheh sorry I meant to put "new". Thanks alot mikkel. dude hahahah sorry


@ Grim

No, I put it as if they team kill then they are frozen . So if they team kill they get frozen and unfrozen . I not make it to where they get kicked..
Reply
#9

I understand where you're coming from, but "Teamkill Protection" I would assume means stopping players from inflicting damage on their team mates.
Reply
#10

Quote:
Originally Posted by Grim_
View Post
This is not a teamkill protection, but a teamkill detector.
Quote:
Originally Posted by Grim_
View Post
I understand where you're coming from, but "Teamkill Protection" I would assume means stopping players from inflicting damage on their team mates.
oh very very very sorry! i must change topic name. how may i do this?
Reply
#11

Quote:
Originally Posted by ToPhrESH
View Post
oh very very very sorry! i must change topic name. how may i do this?
Edit the main post, there should be a input dialog (lol) stating "Topic title"
Reply
#12

It's not a Teamkill protection just a team making tutorial.
Reply
#13

Quote:
Originally Posted by Hiddos
View Post
Edit the main post, there should be a input dialog (lol) stating "Topic title"
Even though you edit it, it doesn't change. (Which is real shitty (SMF FTW))
Reply
#14

Quote:
Originally Posted by arbash
View Post
It's not a Teamkill protection just a team making tutorial.
You obviously can't read. If you want the tutorial scroll down.
Reply
#15

Nice tut.
Reply
#16

Quote:
Originally Posted by Nonameman
View Post
Nice tut.
Thank you
Reply
#17

SetPlayerTeam ... https://sampwiki.blast.hk/wiki/SetPlayerTeam
Quote:

Note: Players on the same team can not kill each other

Reply
#18

Quote:
Originally Posted by snoob
View Post
On a continuous note to what snoob posted, this tutorial could of been.

Quote:
Originally Posted by Carlton's Simple Example
- Anti Team Kill Tutorial
pawn Code:
#define TEAM_BLUE 1
#define TEAM_RED 2

public OnGameModeInit() {
     AddPlayerClass(...);
     AddPlayerClass(...);
     return 1;
}

public OnPlayerRequestClass(playerid, classid) {
     switch(classid) {
          case 0: SetPlayerTeam(playerid, TEAM_BLUE);
          case 1: SetPlayerTeam(playerid, TEAM_RED);
     }
     return 1;
}
No one gets killed if they are on the same team, tutorial, finished.
There should of been nothing with variables and functions involved and copied from the SA:MP Wikipedia. Not to be an ass or whatever, but just saying, it's not very useful as a tutorial.
Reply
#19

You'll also need to update the teams sometimes, seeing how SetPlayerTeam() sometimes "un-sets" them, allowing players to kill people on their team.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)