SA-MP Forums Archive
[Tutorial] Anti-Teamshoot - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Anti-Teamshoot (/showthread.php?tid=224930)



Anti-Teamshoot - robintjeh - 12.02.2011

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.


Re: Anti-Teamshoot - Grim_ - 12.02.2011

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


Re: Anti-Teamshoot - robintjeh - 12.02.2011

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


Re: Anti-Teamshoot - Grim_ - 12.02.2011

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

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


Re: Anti-Teamshoot - robintjeh - 12.02.2011

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


Re: Anti-Teamshoot - Grim_ - 12.02.2011

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.


Re: Anti-Teamshoot - Kwarde - 12.02.2011

@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.