[Include] Useful Public Call Back's
#1

A small .INC, including 4 new publics for your GM, you can turn off, all the publics in the include.

Name: UPCB
Size: 4kb
Creater: SuB_ZeRo0_ (Me)
Download: http://www.megaupload.com/?d=1F1BJ16G


Public's:

OnPlayerHealthChange(playerid,Float:NewHealth,Floa t:OldHealth);
OnPlayerArmourChange(playerid,Float:NewArmour,Floa t:OldArmour);
OnPlayerPosChange(playerid,Float:NewX,Float:OldX,F loat:NewY,Float:OldY,Float:NewZ,Float:OldZ);
OnPlayerDrunkLevelChange(playerid,NewDrunkLevel,Ol dDrunkLevel);


What i do?

Put #include <UPCB> (In the top)
And the publics: (Like that)
pawn Code:
public OnPlayerHealthChange(playerid,Float:NewHealth,Float:OldHealth)
{
         return 1;
}
__________________________________________________ ___________________________________

Any questions, ask me.
Please, don't remove the credits.

Sorry for my bad English.
Reply
#2

4kb on megaupload? You're kidding me right.

That's 0.1 second to download and 45 seconds waiting.
Reply
#3

Quote:
Originally Posted by Hiddos
View Post
4kb on megaupload? You're kidding me right.

That's 0.1 second to download and 45 seconds waiting.
You can register a free account(not premium) like I did,and it will be 25 seconds =P

@Topic: I browsed inside a little,it seems pretty useful but I think you need to add some more callbacks/function for it to be more useful,overall seems nice.
Reply
#4

OnPlayerPosChange, this callback would be called a TON for one player, not mention if there were multiple people online.
Reply
#5

UPCB.inc
Code:
#include <a_samp>

#if defined _UPCB_included
	#endinput
#endif
#define _UPCB_included
#pragma library UPCB

//=======[ PUBLICS ]======= [ 1-ON / 0=OFF ]
#define PublicHealth 1
#define PublicArmour 1
#define PublicPos 1
#define PublicBebida 1
//------------------------------------------

//Variaveis
new Float:VidaA[MAX_PLAYERS],Float:ColeteA[MAX_PLAYERS],Bebida[MAX_PLAYERS],Vivo[MAX_PLAYERS],Float:PosX[MAX_PLAYERS],Float:PosY[MAX_PLAYERS],Float:PosZ[MAX_PLAYERS];

//Forwards
forward OnPlayerHealthChange(playerid,Float:NewHealth,Float:OldHealth);
forward OnPlayerArmourChange(playerid,Float:NewArmour,Float:OldArmour);
forward OnPlayerPosChange(playerid,Float:NewX,Float:OldX,Float:NewY,Float:OldY,Float:NewZ,Float:OldZ);
forward OnPlayerDrunkLevelChange(playerid,NewDrunkLevel,OldDrunkLevel);

stock AtivarUPCB()
{
    if(PublicHealth==1) {SetTimer("TimerVida",1000,true);}
	if(PublicArmour==1) {SetTimer("TimerColete",1000,true);}
	if(PublicPos==1) {SetTimer("TimerPos",1000,true);}
	if(PublicBebida==1) {SetTimer("TimerBebida",1000,true);}
	return 1;
}

public OnPlayerSpawn(playerid) {SetTimerEx("IsVivo",1500,false,"i",playerid);}
public OnPlayerDeath(playerid) {Vivo[playerid]=0;}
public OnPlayerDisconnect(playerid) {Vivo[playerid]=0;}

forward IsVivo(playerid);
public IsVivo(playerid) {Vivo[playerid]=1;}

forward TimerVida();
public TimerVida()
{
	for(new s=0;s<=MAX_PLAYERS;s++) {
	    if(IsPlayerConnected(s)) {
	        new Float:Vida;GetPlayerHealth(s,Vida);
	        if(floatcmp(VidaA[s],Vida)&&Vivo[s]==1) {
				CallRemoteFunction("OnPlayerHealthChange","iff",s,VidaA[s],Vida);
				GetPlayerHealth(s,VidaA[s]);
			}
		}
	}
	return 1;
}
forward TimerColete();
public TimerColete()
{
	for(new s=0;s<=MAX_PLAYERS;s++) {
	    if(IsPlayerConnected(s)) {
	        new Float:Armor;GetPlayerArmour(s,Armor);
	        if(floatcmp(ColeteA[s],Armor)&&Vivo[s]==1) {
				CallRemoteFunction("OnPlayerArmourChange","iff",s,ColeteA[s],Armor);
				GetPlayerArmour(s,ColeteA[s]);
			}
		}
	}
	return 1;
}
forward TimerPos();
public TimerPos()
{
	for(new s=0;s<=MAX_PLAYERS;s++) {
	    if(IsPlayerConnected(s)) {
	        new Float:PosXN,Float:PosYN,Float:PosZN;GetPlayerPos(s,PosXN,PosYN,PosZN);
	        if(floatcmp(PosX[s],PosXN)&&Vivo[s]==1) {
				CallRemoteFunction("OnPlayerPosChange","ifff",s,PosX[s],PosXN,PosY[s],PosYN,PosZ[s],PosZN);
				GetPlayerPos(s,PosX[s],PosY[s],PosZ[s]);
				return 1;
			}
			if(floatcmp(PosY[s],PosYN)&&Vivo[s]==1) {
				CallRemoteFunction("OnPlayerPosChange","ifff",s,PosX[s],PosXN,PosY[s],PosYN,PosZ[s],PosZN);
				GetPlayerPos(s,PosX[s],PosY[s],PosZ[s]);
				return 1;
			}
			if(floatcmp(PosZ[s],PosZN)&&Vivo[s]==1) {
				CallRemoteFunction("OnPlayerPosChange","ifff",s,PosX[s],PosXN,PosY[s],PosYN,PosZ[s],PosZN);
				GetPlayerPos(s,PosX[s],PosY[s],PosZ[s]);
				return 1;
			}
		}
	}
	return 1;
}
forward TimerBebida();
public TimerBebida()
{
	for(new s=0;s<=MAX_PLAYERS;s++) {
	    if(IsPlayerConnected(s)) {
	        new bebida=GetPlayerDrunkLevel(s);
	        if((Bebida[s]!=bebida)&&Vivo[s]==1) {
				CallRemoteFunction("OnPlayerDrunkLevelChange","idd",s,Bebida[s],bebida);
				Bebida[s]=GetPlayerDrunkLevel(s);
			}
		}
	}
	return 1;
}
Reply
#6

Onplayerposchange could be useful for AFK scripts :O
Reply
#7

Question.. What's the difference between OnPlayerUpdate and this timer thingy.. And what is faster?
Reply
#8

Quote:
Originally Posted by RobinOwnz
View Post
Question.. What's the difference between OnPlayerUpdate and this timer thingy.. And what is faster?
OnPlayerUpdate = Gets called to many times a minute, for each person.

Custom timer = Much slower, less CPU usage.
Reply
#9

Does this script use multiple timers? If so, then that's bad. All of these could be done in one timer.
Reply
#10

Quote:
Originally Posted by Grim_
View Post
Does this script use multiple timers? If so, then that's bad. All of these could be done in one timer.
You can disable or change the time of the timer, modifying the include.

That is why I do so many timers.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)