PDA

View Full Version : Useful Functions and Callbacks Re-release


Larcius
07/04/2008, 08:26 PM
Hi scripters,

maybe you also recognized that the "Useful Functions/Callbacks" from Sacky doesn't work. So I took the initiative and edited the whole uf.inc file.
it took me a week to renew the functions and callbacks. i edited many functions and callbacks, which had small bugs, and i added many functions and callbacks of my own.
i also added a few callbacks by DracoBlue and Rafelder.
i asked Sacky for permission, but he didn't answered me so i hope he doesn't mind that i re-release the collection of useful functions and callbacks, which were once gathered by him.
It also includes the functions of dutils.inc by DracoBlue, because running both in 2 files didn't work.


Download it:

http://upl.vs-hs.com/info_imgs/a79f0fc58c1ad55697fd67e97dc1bfa2.jpg (http://upl.vs-hs.com/d/a79f0fc58c1ad55697fd67e97dc1bfa2)


Installation:


download the ZIP-file and extract the uf.inc to \pawno\include\ (or wherever the a_samp.inc is)
insert #include <uf> at the bottom of your a_samp.inc (really at the bottom, not just under the others #include ...)
insert in your script #include <a_samp> (probably already done)
insert into public OnGameModeInit() the command GameModeInit(), e.g.:
public OnGameModeInit()
{
GameModeInit();
// and then your script...

Notation:
There some extension functions, like TogglePlayerControllable2(), which were quite the same as the original function, like TogglePlayerControllable(), with the difference that some other functions does NOT work if you don't use the extansion.
Because I needed the callback OnVehicleSpawn(vehicleid) you have to use OnVehicleSpawn2(vehicleid,dynamic) (dynamic means, the vehicle was spawned to a new userdefined spawnpoint, so you can ignore it, if you didn't use the function SetVehicleSpawnPos().

On entering a vehicle the name of it will appear for 3 seconds at the right bottom of your screen.



I've started writing articles for each command, here you can look for the functions and callbacks: http://streetplaya.hopto.org/SAMP_Wiki/wiki.sa-mp.com/wiki/Category_useful_Functions.html.
Till I've finished this you can search in the uf.inc-file for the command (commands begin with "stock ").
If anybody still find a bug please report it to me (PM (http://forum.sa-mp.com/index.php?action=pm;sa=send;u=30874) or larcius.pc@web.de)

P.S.: Please post your new commands and callbacks here, so I can insert them into the uf.inc

_________________________________________________
Thanks to all people, who published their functions and callbacks:
Alex "Y_Less" Cole
Jan "DracoBlue" Schütze
Gabriel "Larcius" Cordes
Rafelder
Mike
Slick
Allan
SidViciousII
Darkrealm
El Presy
Spectre
mabako
Sacky
Boss
Toxic
dyraXon
yellowblood
50p
rapidZ
Tratulla
Kamazy
Simon
yom
Betamaster
Peter
kool
Hellomy

yom
10/04/2008, 05:47 PM
Are you sure you tested it?

I don't think

stock GetPlayerId(playername[])
{
return return GetPlayerID(partofname[],0);
}

will work..


Why do you return a distance like 999999999999999.0 if invalid distance? Invalid distance should be a negative number, like -1.0.
And 999999999999999.0 is not even a valid float, as well as 999999999999999 is not a valid number.

Larcius
10/04/2008, 09:36 PM
let me explain you why i decided to return BIG_FLOAT instead of -1.0:
if you want to know if for example player 2 is at most 200.0 metres away from you (playerid=0)

if(GetDistanceBetweenPlayers(0,2)<=200.0)
{
SendClientMessage(0, 0xFFFFFFFF, "player 2 is at most 200.0 m away from you");
}


now think about the case, that player 2 i not connected. in this case it returns BIG_FLOAT.
so we have:

if(999999999999999.0<=200.0) //that's not true, so we won't get the message
{
SendClientMessage(0, 0xFFFFFFFF, "player 2 is at most 200.0 m away from you");
}


if the function would return -1.0 we would have:

if(-1.0<=200.0) //that's true, so we will get the message, although player 2 is not connected
{
SendClientMessage(0, 0xFFFFFFFF, "player 2 is at most 200.0 m away from you");
}

of course we could add something like this

if(GetDistanceBetweenPlayers(0,2)<=200.0 && GetDistanceBetweenPlayers(0,2)!=-1.0)
{
//and so on
}

but in my opinion its easier to return BIG_FLOAT, so others don't have to add " && GetDistanceBetweenPlayers(0,2)!=-1.0" to each if-condition.
why are BIG_FLOAT and BIG_INT not valid float and integer? are they too big?
if so please tell me max_float and max_int

the other thing you mentioned: yes, i didn't recognized that, but i already updated the file with only one return.
there could still be a few small bugs, because i can't check 4288 lines without making any mistakes (errare humanum est!!!).

best wishes
larcius

yom
14/04/2008, 09:56 PM
Yes, BIG_FLOAT and BIG_INT are too big, use printf("%f %d", BIG_FLOAT, BIG_INT); to see what's wrong. The values shouldn't be bigger than the value of cellmax.

For testing, remove all 'stock' prefixes and be sure to test all functions you provide :)

Also, there are tons of useful functions from the topic of the same name, maybe you should include some of them ?

Larcius
15/04/2008, 09:26 AM
thanks for the infinity float. i edited this and defined INF_FLOAT, which will be returned.

const Float:INF_FLOAT=Float:0x7F800000;
// and in the function:
return INF_FLOAT;



can i define INF_INT like this:

#define INF_INT 0x7F800000


to yom:
i know there many functions at the topic, which i wanted to add. but as i can see there are only a few persons, who downloaded the uf.inc so i don't do so much work for maybe 10 persons.
i just removed all stock for testing and i all i got are "warning 203: symbol is never used: ...", so everything should work.

Larcius
15/04/2008, 10:04 AM
yes, ok, so it is not possible to define an infinity integer?
i understand the difference between Float:... and float(...);
Float will just declare a var to an Float-var and float(...) will convert a var to an float-var

Konrads
15/04/2008, 10:29 AM
Hmm Nice 1 but still...


MR.KONRADS

hoodline
28/04/2008, 10:49 PM
i know its a old topic but i have a question

you said on wiki at this page http://wiki.sa-mp.com/wiki/AddStaticPickup2


It strongly recommend to use AddStaticPickup2 instead of AddStaticPickup!


why?

they look the same to me

Larcius
29/04/2008, 05:51 PM
using AddStaticPickup() instead of AddStaticPickup2() do not save the coords and other datas. that means these functions won't work:


IsPickupConnected(pickupid);
GetPickups();

//these callbacks won't work, too

public OnPlayerPickupItem(playerid,pickupid,modelid,type) ;
public OnPickupRespawn(pickupid,modelid);


use CreatePickup2() and DestroyPickup2() instead of the old functions.

AiVAMAN
15/05/2009, 02:52 PM
1 Prob, when I am trying to compile with SA-MP 0.2X I get a rid of errors and warnings:

C:\Users\Alive\Desktop\alive's server\pawno\include\uf.inc(442) : error 017: undefined symbol "MAX_PLAYERS"
C:\Users\Alive\Desktop\alive's server\pawno\include\uf.inc(482) : error 017: undefined symbol "MAX_PLAYERS"
C:\Users\Alive\Desktop\alive's server\pawno\include\uf.inc(484) : error 017: undefined symbol "MAX_PLAYERS"
C:\Users\Alive\Desktop\alive's server\pawno\include\uf.inc(484) : error 009: invalid array size (negative, zero or out of bounds)
C:\Users\Alive\Desktop\alive's server\pawno\include\uf.inc(485) : error 017: undefined symbol "MAX_PLAYERS"
C:\Users\Alive\Desktop\alive's server\pawno\include\uf.inc(486) : error 017: undefined symbol "MAX_PLAYERS"
C:\Users\Alive\Desktop\alive's server\pawno\include\uf.inc(488) : error 017: undefined symbol "MAX_VEHICLES"
C:\Users\Alive\Desktop\alive's server\pawno\include\uf.inc(489) : error 017: undefined symbol "MAX_PLAYERS"
C:\Users\Alive\Desktop\alive's server\pawno\include\uf.inc(490) : error 017: undefined symbol "MAX_PLAYERS"
C:\Users\Alive\Desktop\alive's server\pawno\include\uf.inc(497) : error 017: undefined symbol "TextDrawCreate"
C:\Users\Alive\Desktop\alive's server\pawno\include\uf.inc(497) : warning 215: expression has no effect
C:\Users\Alive\Desktop\alive's server\pawno\include\uf.inc(497) : warning 215: expression has no effect
C:\Users\Alive\Desktop\alive's server\pawno\include\uf.inc(497) : warning 215: expression has no effect
C:\Users\Alive\Desktop\alive's server\pawno\include\uf.inc(497) : error 001: expected token: ";", but found ")"
C:\Users\Alive\Desktop\alive's server\pawno\include\uf.inc(497) : error 029: invalid expression, assumed zero
C:\Users\Alive\Desktop\alive's server\pawno\include\uf.inc(497) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


13 Errors.



Pleas, help me?

yom
15/05/2009, 03:55 PM
Put #include a_samp before #include uf

AiVAMAN
15/05/2009, 06:46 PM
Thanks, helped ;D

Winnetou
24/06/2010, 03:34 PM
Hi
I have some problems with this include:

C:\Program Files (x86)\GTA\GTA San Andreas 1\pawno\include\uf.inc(43) : warning 201: redefinition of constant/macro (symbol "MAX_PICKUPS")
C:\Program Files (x86)\GTA\GTA San Andreas 1\pawno\include\uf.inc(533) : warning 219: local variable "controllable" shadows a variable at a preceding level
C:\Program Files (x86)\GTA\GTA San Andreas 1\pawno\include\uf.inc(803) : error 035: argument type mismatch (argument 2)
C:\Program Files (x86)\GTA\GTA San Andreas 1\gamemodes\Simon1.pwn(83) : error 025: function heading differs from prototype
C:\Program Files (x86)\GTA\GTA San Andreas 1\gamemodes\Simon1.pwn(465) : error 035: argument type mismatch (argument 1)
C:\Program Files (x86)\GTA\GTA San Andreas 1\gamemodes\Simon1.pwn(612) : error 021: symbol already defined: "OnVehicleSpawn"
C:\Program Files (x86)\GTA\GTA San Andreas 1\gamemodes\Simon1.pwn(1323) : error 025: function heading differs from prototype
C:\Program Files (x86)\GTA\GTA San Andreas 1\gamemodes\Simon1.pwn(1324) : error 021: symbol already defined: "GetPlayerID"