[Tutorial] Anti-Teamshoot
#1

Hello,

This is an tut about how to make an anti-teamshoot. You will need this include: OnPlayerShootPlayer.

pawn Code:
//Anti teamshoot by Robintjeh
public OnPlayerShootPlayer(shooter,target,Float:damage)
{
    if(PlayerInfo[shooter][pTeam] == PlayerInfo[target][pTeam])
    {
    new Float:newhealth;
    GetPlayerHealth(target, newhealth);
    newhealth = newhealth+sizeof(damage);
    SetPlayerHealth(target, newhealth);
    }
    else return 1;
    return 1;
}
You can better change PlayerInfo[shooter][pTeam] to your own team system.

Explanation of code:
if(PlayerInfo[shooter][pTeam] == PlayerInfo[target][pTeam])
If the team of the shooter and the target is the same,
new Float:newhealth;
GetPlayerHealth(target, newhealth);
Get the players health.
newhealth = newhealth+sizeof(damage);
SetPlayerHealth(target, newhealth);
Calculate the current HP + the damage that was dealt and set it to before the shot.
else return 1;
If the teams aren't the same, do not change nothing at all.

Constructive critism is appreciated.
Reply
#2

You could always just use SetPlayerTeam to disable team-kill.
Reply
#3

Team-Kill, yes. But this is diffrent. This does no damage at all to a player from the same team.
Reply
#4

Neither does SetPlayerTeam, that's the point of the function.

https://sampwiki.blast.hk/wiki/SetPlayerTeam
Reply
#5

Huh? That didn't work for me before. When was that added?
Reply
#6

It always has it bugs. It appears that the first time someone joins they don't get set the proper team (best way I can personally explain it). If you reset the team about 5 seconds after the player spawns, it will eliminate all the bugs.

The function has always been around, to what I remember.
Reply
#7

@Robintjeh: Indeed, SetPlayerTeam does already exists, BUT
This one ain't always working. Sometimes it does, sometimes it doesn't (for me). So I prefer this script

Quote:

else return 1;
return 1;

That "else return 1;" is not needed.
It's now like this:

"if Team(shooter) is the same as team (target)" (the code)
"else" return 1;
else if ( (is not (if team(shooter) is the same as team(terget)) && !else)" return 1

I hope that that is a bit clear. Well look, here's another example:

pawn Code:
stock IsPlayerRich(playerid)
{
    if(GetPlayerMoney(playerid) >= 150000)
        return 1;
    else
        return 0;
    return 0;
}
Now it checks like this:

"if money of 'playerid' >= 150000" : RETURN 1;
else : RETURN 0;
If it's not both of them (can't exist in this function) RETURN 0;

So this function could be:
pawn Code:
stock IsPlayerRich(playerid)
{
    if(GetPlayerMoney(playerid) >= 150000) return 1;
    return 0;
}
or even
pawn Code:
stock IsPlayerRich(playerid) return GetPlayerMoney(playerid) >= 150000 ? true : false;
However, my point is: the "else return 1;" is not needed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)