All pastes #1618834 Raw Edit

YUP.pwn

public cpp v1 · immutable
#1618834 ·published 2009-10-14 08:37 UTC
rendered paste body
#include <a_samp>#include <YUP>#define FOREACH_NO_BOTS#include <foreach>/* ========================================================================== *                         _____.___.____ _____________                         \__  |   |    |   \______   \                          /   |   |    |   /|     ___/                          \____   |    |  / |    |                          / ______|______/  |____|                          \/        \_/  |  _  _ _  | |._  _| _._|_ _   |_) _ ._ o._ |_  _ ._ _.| _         | __|_(/__>_>  |_||_)(_|(_| |_(/_  |  (/_|  ||_)| |(/_| (_||_> * ========================================================================== *                Update script by Alex "Y_Less" Cole - version 0.4                               - Main filterscript * ========================================================================== *//* ========================================================================== *	Adjust things under this line * ========================================================================== */// Uncomment the functions you want to use// They are mostly all disabled by default for speed#define DETECT_PAUSE//#define ON_PLAYER_AMMO_CHANGE//#define ON_PLAYER_WEAPON_CHANGE//#define ON_PLAYER_HEALTH_CHANGE//#define ON_PLAYER_ARMOUR_CHANGE//#define ON_PLAYER_MONEY_CHANGE//#define ON_PLAYER_WEAPON_SLOT_CHANGE// By default let people view the menu for no more than 60 seconds#define DEFAULT_THRESHOLD (60000)/* ========================================================================== *	Don't adjust things under this line * ========================================================================== */#define MAX_AFK_TIME (250)#if !defined DETECT_PAUSE && !defined ON_PLAYER_HEALTH_CHANGE && !defined ON_PLAYER_ARMOUR_CHANGE && !defined ON_PLAYER_WEAPON_CHANGE && !defined ON_PLAYER_AMMO_CHANGE && !defined ON_PLAYER_MONEY_CHANGE && !defined ON_PLAYER_WEAPON_SLOT_CHANGE && !defined DETECT_SPEED	#error Filterscript does nothing - Please uncomment one of the lines at the top#endif#if defined DETECT_PAUSE	new		gLastUpdate[MAX_PLAYERS],		e_PAUSE_ACTION:gPauseAction = e_PAUSE_ACTION_KICK | e_PAUSE_ACTION_MESSAGE,		e_STATE:gState[MAX_PLAYERS] = {e_STATE_NONE, ...},		gMessage[128] = "You have been detected as paused",		gThreshold = DEFAULT_THRESHOLD;#endif#if defined ON_PLAYER_AMMO_CHANGE	new		gPlayerAmmo[MAX_PLAYERS];#endif#if defined ON_PLAYER_WEAPON_CHANGE	new		gPlayerWeapon[MAX_PLAYERS];#endif#if defined ON_PLAYER_HEALTH_CHANGE	new		Float:gPlayerHealth[MAX_PLAYERS];#endif#if defined ON_PLAYER_ARMOUR_CHANGE	new		Float:gPlayerArmour[MAX_PLAYERS];#endif#if defined ON_PLAYER_MONEY_CHANGE	new		gPlayerMoney[MAX_PLAYERS];#endif#if defined ON_PLAYER_WEAPON_SLOT_CHANGE	new		gPlayerWeapons[MAX_PLAYERS][13];#endif#if defined DETECT_PAUSE	forward KickUpdate();	forward _YUP_SetPauseMessage(const str[]);	forward _YUP_SetPauseAction(e_PAUSE_ACTION:action);	forward e_STATE:_YUP_GetPlayerState(playerid);	forward _YUP_SetActionThreshold(milliseconds);#endifpublic OnFilterScriptInit(){	print(" ");	print(" * ========================================================================== *");	print("                         _____.___.____ _____________");	print("                         \\__  |   |    |   \\______   \\");	print("                          /   |   |    |   /|     ___/");	print("                          \\____   |    |  / |    |");	print("                          / ______|______/  |____|");	print("                          \\/");	print(" ");	print("        \\_/  |  _  _ _  | |._  _| _._|_ _   |_) _ ._ o._ |_  _ ._ _.| _");	print("         | __|_(/__>_>  |_||_)(_|(_| |_(/_  |  (/_|  ||_)| |(/_| (_||_>");	print(" ");	print(" * ========================================================================== *");	print("                Update script by Alex \"Y_Less\" Cole - version 0.4");	print(" * ========================================================================== *");	print(" ");	#if defined DETECT_PAUSE		SetTimer("KickUpdate", MAX_AFK_TIME / 2, 1);	#endif	return 1;}public OnPlayerUpdate(playerid){	#if defined DETECT_PAUSE		// When you first connect you don't send much, don't kick players for this		switch (gState[playerid])		{			case e_STATE_UPDATING:			{				// Get the time of a player's last update				gLastUpdate[playerid] = GetTickCount();			}			case e_STATE_PAUSED:			{				CallRemoteFunction("OnPlayerUnpause", "i", playerid);				gLastUpdate[playerid] = GetTickCount();				gState[playerid] = e_STATE_UPDATING;			}			case e_STATE_SPEC:			{				gLastUpdate[playerid] = GetTickCount();				gState[playerid] = e_STATE_UPDATING;			}		}	#endif	#if defined ON_PLAYER_HEALTH_CHANGE || defined ON_PLAYER_ARMOUR_CHANGE || defined ON_PLAYER_WEAPON_SLOT_CHANGE		new			Float:tempf;	#endif	#if defined ON_PLAYER_WEAPON_CHANGE || defined ON_PLAYER_AMMO_CHANGE || defined ON_PLAYER_MONEY_CHANGE || defined ON_PLAYER_WEAPON_SLOT_CHANGE		new			temp;	#endif	#if defined ON_PLAYER_WEAPON_CHANGE		temp = GetPlayerWeapon(playerid);		if (temp != gPlayerWeapon[playerid])		{			CallRemoteFunction("OnPlayerWeaponChange", "iii", playerid, gPlayerWeapon[playerid], temp);			gPlayerWeapon[playerid] = temp;		}		#if defined ON_PLAYER_AMMO_CHANGE			else			{		#endif	#endif	#if defined ON_PLAYER_AMMO_CHANGE				temp = GetPlayerAmmo(playerid);				if (temp != gPlayerAmmo[playerid])				{					CallRemoteFunction("OnPlayerAmmoChange", "iii", playerid, gPlayerAmmo[playerid], temp);					gPlayerAmmo[playerid] = temp;				}		#if defined ON_PLAYER_WEAPON_CHANGE			}		#endif	#endif	#if defined ON_PLAYER_HEALTH_CHANGE		GetPlayerHealth(playerid, tempf);		if (tempf != gPlayerHealth[playerid])		{			CallRemoteFunction("OnPlayerHealthChange", "iff", playerid, gPlayerHealth[playerid], tempf);			gPlayerHealth[playerid] = tempf;		}	#endif	#if defined ON_PLAYER_ARMOUR_CHANGE		GetPlayerArmour(playerid, tempf);		if (tempf != gPlayerArmour[playerid])		{			CallRemoteFunction("OnPlayerArmourChange", "iff", playerid, gPlayerArmour[playerid], tempf);			gPlayerArmour[playerid] = tempf;		}	#endif	#if defined ON_PLAYER_MONEY_CHANGE		temp = GetPlayerMoney(playerid);		if (temp != gPlayerMoney[playerid])		{			CallRemoteFunction("OnPlayerMoneyChange", "iii", playerid, gPlayerMoney[playerid], temp);			gPlayerMoney[playerid] = temp;		}	#endif	#if defined ON_PLAYER_WEAPON_SLOT_CHANGE		GetPlayerWeaponData(playerid, 0, temp, _:tempf);		if (temp != gPlayerWeapons[playerid][0])		{			CallRemoteFunction("OnPlayerWeaponSlotChange", "iiii", playerid, 0, gPlayerWeapons[playerid][0], temp);			gPlayerWeapons[playerid][0] = temp;		}		GetPlayerWeaponData(playerid, 1, temp, _:tempf);		if (temp != gPlayerWeapons[playerid][1])		{			CallRemoteFunction("OnPlayerWeaponSlotChange", "iiii", playerid, 1, gPlayerWeapons[playerid][1], temp);			gPlayerWeapons[playerid][1] = temp;		}		GetPlayerWeaponData(playerid, 2, temp, _:tempf);		if (temp != gPlayerWeapons[playerid][2])		{			CallRemoteFunction("OnPlayerWeaponSlotChange", "iiii", playerid, 2, gPlayerWeapons[playerid][2], temp);			gPlayerWeapons[playerid][2] = temp;		}		GetPlayerWeaponData(playerid, 3, temp, _:tempf);		if (temp != gPlayerWeapons[playerid][3])		{			CallRemoteFunction("OnPlayerWeaponSlotChange", "iiii", playerid, 3, gPlayerWeapons[playerid][3], temp);			gPlayerWeapons[playerid][3] = temp;		}		GetPlayerWeaponData(playerid, 4, temp, _:tempf);		if (temp != gPlayerWeapons[playerid][4])		{			CallRemoteFunction("OnPlayerWeaponSlotChange", "iiii", playerid, 4, gPlayerWeapons[playerid][4], temp);			gPlayerWeapons[playerid][4] = temp;		}		GetPlayerWeaponData(playerid, 5, temp, _:tempf);		if (temp != gPlayerWeapons[playerid][5])		{			CallRemoteFunction("OnPlayerWeaponSlotChange", "iiii", playerid, 5, gPlayerWeapons[playerid][5], temp);			gPlayerWeapons[playerid][5] = temp;		}		GetPlayerWeaponData(playerid, 6, temp, _:tempf);		if (temp != gPlayerWeapons[playerid][6])		{			CallRemoteFunction("OnPlayerWeaponSlotChange", "iiii", playerid, 6, gPlayerWeapons[playerid][6], temp);			gPlayerWeapons[playerid][6] = temp;		}		GetPlayerWeaponData(playerid, 7, temp, _:tempf);		if (temp != gPlayerWeapons[playerid][7])		{			CallRemoteFunction("OnPlayerWeaponSlotChange", "iiii", playerid, 7, gPlayerWeapons[playerid][7], temp);			gPlayerWeapons[playerid][7] = temp;		}		GetPlayerWeaponData(playerid, 8, temp, _:tempf);		if (temp != gPlayerWeapons[playerid][8])		{			CallRemoteFunction("OnPlayerWeaponSlotChange", "iiii", playerid, 8, gPlayerWeapons[playerid][8], temp);			gPlayerWeapons[playerid][8] = temp;		}		GetPlayerWeaponData(playerid, 9, temp, _:tempf);		if (temp != gPlayerWeapons[playerid][9])		{			CallRemoteFunction("OnPlayerWeaponSlotChange", "iiii", playerid, 9, gPlayerWeapons[playerid][9], temp);			gPlayerWeapons[playerid][9] = temp;		}		GetPlayerWeaponData(playerid, 10, temp, _:tempf);		if (temp != gPlayerWeapons[playerid][10])		{			CallRemoteFunction("OnPlayerWeaponSlotChange", "iiii", playerid, 10, gPlayerWeapons[playerid][10], temp);			gPlayerWeapons[playerid][10] = temp;		}		GetPlayerWeaponData(playerid, 11, temp, _:tempf);		if (temp != gPlayerWeapons[playerid][11])		{			CallRemoteFunction("OnPlayerWeaponSlotChange", "iiii", playerid, 11, gPlayerWeapons[playerid][11], temp);			gPlayerWeapons[playerid][11] = temp;		}		GetPlayerWeaponData(playerid, 12, temp, _:tempf);		if (temp != gPlayerWeapons[playerid][12])		{			CallRemoteFunction("OnPlayerWeaponSlotChange", "iiii", playerid, 12, gPlayerWeapons[playerid][12], temp);			gPlayerWeapons[playerid][12] = temp;		}	#endif	return 1;}public OnPlayerConnect(playerid){	#if defined DETECT_PAUSE		// Give new players some leway		gState[playerid] = e_STATE_CONNECTED;	#endif	#if defined ON_PLAYER_AMMO_CHANGE		gPlayerAmmo[playerid] = 0;	#endif	#if defined ON_PLAYER_WEAPON_CHANGE		gPlayerWeapon[playerid] = 0;	#endif	#if defined ON_PLAYER_HEALTH_CHANGE		gPlayerHealth[playerid] = 100.0;	#endif	#if defined ON_PLAYER_ARMOUR_CHANGE		gPlayerArmour[playerid] = 0.0;	#endif	#if defined ON_PLAYER_MONEY_CHANGE		gPlayerMoney[playerid] = 0;	#endif	#if defined ON_PLAYER_WEAPON_SLOT_CHANGE		new			slot[13];		gPlayerWeapons[playerid] = slot;	#endif	return 1;}#if defined DETECT_PAUSE	public OnPlayerDeath(playerid, killerid, reason)	{		gState[playerid] = e_STATE_CONNECTED;		return 1;		#pragma unused killerid, reason	}		public OnPlayerSpawn(playerid)	{		gLastUpdate[playerid] = GetTickCount();		gState[playerid] = e_STATE_SPAWNED;		return 1;	}		public _YUP_SetPauseMessage(const str[])	{		gMessage[0] = 0;		if (str[0] != 1)		{			strcat(gMessage, str);		}	}		public _YUP_SetPauseAction(e_PAUSE_ACTION:action)	{		gPauseAction = action;	}		public e_STATE:_YUP_GetPlayerState(playerid)	{		if (playerid < 0 || playerid >= MAX_PLAYERS)		{			return e_STATE_NONE;		}		return gState[playerid];	}		public _YUP_SetActionThreshold(milliseconds)	{		gThreshold = milliseconds;	}		public OnPlayerDisconnect(playerid, reason)	{		gState[playerid] = e_STATE_NONE;		return 1;	}		public KickUpdate()	{		// Get the last valid time		new			time = GetTickCount(),			threshold = time - gThreshold,			spawned = time - 2000;		time -= MAX_AFK_TIME;		// Loop through all players		foreach (Player, i)		{			switch (gState[i])			{				case e_STATE_UPDATING:				{					if (GetPlayerState(i) == PLAYER_STATE_SPECTATING)					{						gState[i] = e_STATE_SPEC;					}					else if (time >= gLastUpdate[i])					{						CallRemoteFunction("OnPlayerPause", "i", i);						gState[i] = e_STATE_PAUSED;					}				}				case e_STATE_SPAWNED:				{					// There's a slight lag after you spawn till the updates					// come through - fit that here by ignoring it.					if (spawned >= gLastUpdate[i])					{						gState[i] = e_STATE_UPDATING;					}				}				case e_STATE_PAUSED:				{					if (threshold >= gLastUpdate[i])					{						if (gPauseAction & e_PAUSE_ACTION_MESSAGE && gMessage[0])						{							SendClientMessage(i, 0xFF0000AA, gMessage);						}						if (gPauseAction & e_PAUSE_ACTION_ALERT)						{							CallRemoteFunction("OnPlayerExpire", "i", i);						}						if (gPauseAction & e_PAUSE_ACTION_LOG)						{							printf("Player %d is paused", i);						}						if (gPauseAction & e_PAUSE_ACTION_NOTIFY)						{							new								str[21];							format(str, sizeof (str), "Player %d is paused", i);							foreach (Player, playerid)							{								// Call the custom admin callback.  Did have								// clever code which had registered callbacks,								// but this method is simpler to use - it also								// means the callback can be in any script								// (just be careful when you use other people's								// scripts that it hasn't been hijacked).								if (CallRemoteFunction("YUP_AdminHandler", "i", playerid) || IsPlayerAdmin(playerid))								{									SendClientMessage(playerid, 0xFF0000AA, str);								}							}						}						if (gPauseAction & e_PAUSE_ACTION_KICK)						{							Kick(i);						}						else if (gPauseAction & e_PAUSE_ACTION_BAN)						{							Ban(i);						}						gState[i] = e_STATE_EXPIRED;					}				}			}		}	}#endif