All pastes #1556278 Raw Edit

YUP.pwn

public cpp v1 · immutable
#1556278 ·published 2009-09-06 17:23 UTC
rendered paste body
#include <a_samp>#include <YUP>/* ========================================================================== *                         _____.___.____ _____________                         \__  |   |    |   \______   \                          /   |   |    |   /|     ___/                          \____   |    |  / |    |                          / ______|______/  |____|                          \/        \_/  |  _  _ _  | |._  _| _._|_ _   |_) _ ._ 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 DETECT_SPEED#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 kicked for being out the game",		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_SPEED	new		Float:gLastX[MAX_PLAYERS],		Float:gLastY[MAX_PLAYERS],		Float:gLastZ[MAX_PLAYERS],		Float:gCurX[MAX_PLAYERS],		Float:gCurY[MAX_PLAYERS],		Float:gCurZ[MAX_PLAYERS],		gLastTick[MAX_PLAYERS],		gCurTick[MAX_PLAYERS];#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);#endif#if defined DETECT_SPEED	forward _YUP_GetPlayerVehicleSpeed(playerid);#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.3");	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);				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 || defined DETECT_SPEED		#if defined DETECT_SPEED			new				temp = GetPlayerVehicleID(playerid);		#else			new				temp;		#endif	#endif	#if defined DETECT_SPEED		if (temp)		{			gLastTick[playerid] = gCurTick[playerid];			gLastX[playerid] = gCurX[playerid];			gLastY[playerid] = gCurY[playerid];			gLastZ[playerid] = gCurZ[playerid];			GetVehiclePos(temp, gCurX[playerid], gCurY[playerid], gCurZ[playerid]);			// Don't do the maths here, too complex and slow			#if defined DETECT_PAUSE				gCurTick[playerid] = gLastUpdate[playerid];			#else				gCurTick[playerid] = GetTickCount();			#endif		}	#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_SPEED	public _YUP_GetPlayerVehicleSpeed(playerid)	{		if (!IsPlayerInAnyVehicle(playerid))		{			return _:0.0;		}		new			Float:x = gLastX[playerid] - gCurX[playerid],			Float:y = gLastY[playerid] - gCurY[playerid],			Float:z = gLastZ[playerid] - gCurZ[playerid];		return _:(floatsqroot((x * x) + (y * y) + (z * z)) / (gCurTick[playerid] - gLastTick[playerid]));			}#endif#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,			pause = time - 2000;		time -= MAX_AFK_TIME;		// Loop through all players		for (new i = 0; i < MAX_PLAYERS; i++)		{			switch (gState[i])			{				case cellmin .. -1:				{					// Spectating				}				case e_STATE_UPDATING:				{					if (time >= gLastUpdate[i])					{						CallRemoteFunction("OnPlayerPause", "i", i);						gState[i] = e_STATE_PAUSED;					}				}				case e_STATE_SPAWNED:				{					if (pause >= 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_KICK)						{							Kick(i);						}						else if (gPauseAction & e_PAUSE_ACTION_BAN)						{							Ban(i);						}						gState[i] = e_STATE_EXPIRED;					}				}			}		}	}#endif