Fair Fight anti 2vs1, 3vs1 etc. -
Gryphus One - 25.09.2012
Hi, this is the first filterscript I release. It's purpose is to avoid alone players being unfairly fought 2 vs 1, 3 vs 1, 4 vs 1... and to force everyone to fight 1 vs 1.
I must admit that I haven't fully tested this script and therefore I can't guarantee it's free of bugs, but I think it should work. Its code is the following:
pawn Код:
#include <a_samp>
#define TIMEBETWEENATTACKS 20
// Number of SECONDS that have to pass between a player is attacked by different players.
new LastAttacker[MAX_PLAYERS];
new TimeOfLastAttack[MAX_PLAYERS];
forward PlayerIsNotAttacking(playerid);
// This function makes playerid not be marked as the last attacker of any other players.
public PlayerIsNotAttacking(playerid)
{
new count;
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(LastAttacker[i] == playerid)
{
LastAttacker[i] = INVALID_PLAYER_ID;
count++;
}
}
return count;
}
#define TIMEBETWEENATTACKS2 (TIMEBETWEENATTACKS * 1000)
forward CheckIfDifferentAttacker(victim, attacker);
public CheckIfDifferentAttacker(victim, attacker)
{
if( (attacker != INVALID_PLAYER_ID) && (attacker != victim) )
// The victim has definitely been attacked by another player.
{
if( (attacker != LastAttacker[victim]) && (LastAttacker[victim] != INVALID_PLAYER_ID) && (LastAttacker[victim] != victim) )
// The current attacker is not the previous one.
{
if( (GetTickCount() - TimeOfLastAttack[victim]) < TIMEBETWEENATTACKS2 )
// Not enough time has passed.
{
if( IsPlayerStreamedIn(LastAttacker[victim], victim) )
// The original attacker of the victim is still streamed in.
{
return 1;
}
}
}
// If these lines are reached it's because the attack is fair.
TimeOfLastAttack[victim] = GetTickCount();
LastAttacker[victim] = attacker;
}
return 0;
}
public OnFilterScriptInit()
{
print("\n--------------------------------------");
print("Fair Fight Filterscript");
print("--------------------------------------\n");
return 1;
}
public OnPlayerConnect(playerid)
{
PlayerIsNotAttacking(playerid);
LastAttacker[playerid] = INVALID_PLAYER_ID;
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
PlayerIsNotAttacking(playerid);
// If playerid is attacking you and he dies, another player will
// be allowed to attack you without it being considered 2 vs 1.
return 1;
}
public OnPlayerSpawn(playerid)
{
LastAttacker[playerid] = INVALID_PLAYER_ID;
return 1;
}
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
if(CheckIfDifferentAttacker(playerid, issuerid) == 1)
{
new Float:health, Float:armour;
GetPlayerHealth(playerid, health);
GetPlayerArmour(playerid, armour);
// With this I'm getting the health and armour that the victim had BEFORE taking damage.
SetPlayerHealth(playerid, health);
SetPlayerArmour(playerid, armour);
// And now I restore those previous health and armour values, so damage will be null.
SetPlayerArmedWeapon(issuerid, 0);
// This will make the attacker stop shooting.
new victimname[MAX_PLAYER_NAME + 1], attackername[MAX_PLAYER_NAME + 1], string[128];
GetPlayerName( playerid, victimname, sizeof(victimname) );
GetPlayerName( LastAttacker[playerid], attackername, sizeof(attackername) );
format(string, sizeof(string), "~r~You can't hurt %s because he's being attacked by %s", victimname, attackername);
GameTextForPlayer(issuerid, string, 2000, 4);
}
return 1;
}
Re: Fair Fight anti 2vs1, 3vs1 etc. -
CaptainMactavish - 26.09.2012
That's the challenge, survive when you have four muppets stuck in the ass. That really takes out the fun to the game.
Re: Fair Fight anti 2vs1, 3vs1 etc. -
Niko_boy - 26.09.2012
i got another of this script :P , i was failing a bit in sorting out a array for damage meter :P
this might help me out
ty for it
Re: Fair Fight anti 2vs1, 3vs1 etc. -
a.z.a.r - 05.01.2013
finally no abusing about 2 vs1...
Re: Fair Fight anti 2vs1, 3vs1 etc. -
Jawz - 28.06.2013
not bad.
Re: Fair Fight anti 2vs1, 3vs1 etc. -
AldoT - 29.06.2013
nice
Re: Fair Fight anti 2vs1, 3vs1 etc. -
Pottus - 29.06.2013
Whats wrong with 2v1, 3v1, 4v1 ?
Respuesta: Re: Fair Fight anti 2vs1, 3vs1 etc. -
Gryphus One - 30.06.2013
Thanks for the comments. This script is a bit old though.
Re: Fair Fight anti 2vs1, 3vs1 etc. -
Sojo12 - 27.01.2014
Yes but still its good.
Respuesta: Fair Fight anti 2vs1, 3vs1 etc. -
Gryphus One - 27.01.2014
Maybe I should update this script to sa-mp 0.3z now that it brings the new callback OnPlayerWeaponShot