[Tutorial] How to make an anti-teamkill -Easy- (with OPSP)
#1

Hi everyone,

You may have searched in this forum for an anti teamkill system...
as you can notice, there are not so many anti teamkill systems, and nor are there any anti-teamkill system that really makes the shooter NOT BEING ABLE to kill the target.

So I wanted to make this little tutorial : )

So how does it work?
Well, when a player shoots a player from its own team, then the shooter will die and get a message that teamkilling is not allowed. however, the target will regain the damage he lost by a teamkill-attempt, so that the victim of teamkilling doesn't have to die immediately...

Note: u are only going to be able to use this script, if u already worked with teams in your GM/Filterscript, otherwise U are going to get errors...

So, how are we going to do this?


STEP 1

First of all we will need a little include, made by wups, and it can be downloaded here:
http://forum.sa-mp.com/showthread.ph...highlight=OPSP

To install, u have to click the version u want, then copy the pastebin material, paste in notepad and save as OPSP.inc

then move it to the folder: pawno/include
and just paste it there...
next u wanna add
PHP Code:
#include <OPSP> 
at the top of your GM, or the script u wanna make our little anti-teamkill thing in.
Paste it under
PHP Code:
#include <a_samp> 
Ok, then add this somewhere in your Script:

PHP Code:
public OnPlayerShootPlayer(Shooter,Target,Float:HealthLost,Float:ArmourLost)
{
    return 
1;

STEP 2

now we are going to start to script.

so we have
PHP Code:
public OnPlayerShootPlayer(Shooter,Target,Float:HealthLost,Float:ArmourLost)
{
    return 
1;

now add this under the first { bracket:

PHP Code:
if ( Shooter != INVALID_PLAYER_ID 
    { 
        if ( 
GetPlayerTeamTarget ) == GetPlayerTeamShooter ) ) // check if the victim is from the same team as the shooter. 
        

            new 
Float:hp;
    
GetPlayerHealth(Targethp);
            
SetPlayerHealth(Targethp HealthLost);
            
SetPlayerHealthShooter);
            
SendClientMessageShooterCOLOR_RED"Team killing is not allowed!" ); 
            
GivePlayerMoneyShooter, - 5000 ); 
    }

So, we will get this:

PHP Code:
public OnPlayerShootPlayer(Shooter,Target,Float:HealthLost,Float:ArmourLost)
{
   if ( 
Shooter != INVALID_PLAYER_ID 
    { 
        if ( 
GetPlayerTeamTarget ) == GetPlayerTeamShooter ) ) // check if the victim is from the same team as the shooter. 
        

 
            new 
Float:hp;
            
GetPlayerHealth(Targethp);
            
SetPlayerHealth(Targethp HealthLost);
            
SetPlayerHealthShooter);
            
SendClientMessageShooterCOLOR_RED"Team killing is not allowed!" ); 
            
GivePlayerMoneyShooter, - 5000 ); 
        }
    }
    return 
1;

Just compile the script, save it and u don't have problems with teamkilling in your server anymore!
enjoy your Teamkilling-free server

Bye
Reply
#2

If you are on the same team as the player, they cant hurt you anyway. You pretty much give the player health that they have not lost.
Reply
#3

Quote:
Originally Posted by knackworst
View Post
pawn Code:
SetPlayerHealth( Target, HealthLost); //Give back the victim the damage that he lost.
Are you serious? So if I shoot you, and you lose 5 health, it sets your health to 5? wow.
Reply
#4

pawn Code:
SetPlayerHealth( Target, HealthLost);
(here you set his health to healthlost, if he lost 5 heal, his heal setted to 5.)
need to be
pawn Code:
SetPlayerHealth( Target, (GetPlayerHealth(Target) + HealthLost));
(Get his healt + the healthlost = his health before attack)
Reply
#5

o, sorry my bad, I must have made a mistake
Reply
#6

Quote:
Originally Posted by wouter0100
View Post
pawn Code:
SetPlayerHealth( Target, HealthLost);
(here you set his health to healthlost, if he lost 5 heal, his heal setted to 5.)
need to be
pawn Code:
SetPlayerHealth( Target, (GetPlayerHealth(Target) + HealthLost));
(Get his healt + the healthlost = his health before attack)
Which is still wrong:
pawn Code:
new Float:hp;
GetPlayerHealth(target, hp);
SetPlayerHealth(target, hp + healthlost);
Add capitals wherever necessary.
Reply
#7

Hiddos, I've never quite understood why the API was programmed to save a lot of method's returns as variables - such as GetPlayerHealth and GetPlayerName. Surely just returning it would be easier for the user, so we could just do:
pawn Code:
new Float:hp = GetPlayerHealth(playerid);
Reply
#8

This will not protect from minigun, and in some other "situations". Better use SetPlayerTeam
Reply
#9

You should also return the Armour.
pawn Code:
if(HealthLost > 0.0)
{
     new Float:hp;
     GetPlayerHealth(Target, hp);
     SetPlayerHealth(Target, hp + HealthLost);
}
if(ArmourLost > 0.0)
{
     new Float:Armour;
     GetPlayerHealth(Target, Armour);
     SetPlayerHealth(Target, Armour + HealthLost);
}
Reply
#10

If you try to hit a team it kills you? Hmm not good you will die everytime.

Try using this guys:

On top:

pawn Code:
forward TeamProtection();
And this under OnGameModeInit

pawn Code:
SetTimer("TeamProtection", 5000 ,true);
And anywhere in GM.

pawn Code:
public TeamProtection()
{
    for(new i; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            SetPlayerTeam(i, gTeam[i]);
        }
    }
}
This code is 100% working if you put it rite paths.

Thanks.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)