25.09.2012, 22:47
(
Последний раз редактировалось Gryphus One; 06.11.2012 в 13:53.
)
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:
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;
}