[Include] functions.inc - Adds new natives for scripters.
#1

New SA-MP Functions

v 0.2 | Last Update - 29/12/17


Introduction

This Include adds wide range of SA-MP functions which gives other script developer extra control over their player.
These functions aren't rocket science code. Just adds some functions which new coders might find difficult to write.

Current Functions

Код:
1. IsPlayerAiming(playerid, weaponid); - returns true if a player is aiming. (Includes zoom-in weapons.)
2. IsPlayerSwimming(playerid); - returns true if a player is swimming. (Regardless of the water body.)
3. IsPlayerSkydiving(playerid); - returns true if a player is skydiving.
4. IsPlayerParachuting(playerid); - returns true if a player is parachuting.
5. IsPlayerPassengerAiming(playerid); - returns true if a player is aiming a weapon as passenger of vehicle.
6. IsPlayerInKitchen(playerid); - returns true if player is in Kitchen. (Default Interiors.)
7. IsPlayerNearVending(playerid, type); - returns true if player is near Vending Machine. (Default locations.)
8. IsPlayerNearPump(playerid); - returns true if a player is near Fuel Pump. (Default Locations.)
8. IsPlayerCarSurfing(playerid) - returns true if player is car surfing.
9. IsPlayerNearPlayer(playerid, targetid, float:radius) - returns true if player is near another player in given radius.
10. IsPlayerNearVehicle(playerid, vehicleid, float:radius) - returns true if player is near specified vehicle in given radius.
11. IsPlayerNearDynamicObject(playerid, objectid, float:radius) - returns true if player is near specified dynamic object id in given radius
12. IsPlayerRidingTrain(playerid); - returns true if player is riding a train.
13. IsPlayerSpawned(playerid); - returns true if player is spawned.
Credits

Код:
Ritzy - Author
|Stuntman| And Southclaws - Helped a lot
Emmet_ - Vending Machine Array
OneDay - Optimization
SA-MP Team (Past, and Present) - For SA-MP
Download is at my Github.

Note: You're free to use this however you please in your script. But, please don't reupload without my permission.

There might be some bugs. Please report them.

Suggestions for functions are welcome!
Reply
#2

Nice, some functions are interesting.
Reply
#3

They are not natives only plugins add natives. and this is wrong: 0<=plaerid<=MAX_PLAYERS

why not:

PHP код:

stock bool
:IsPlayerPassengerAiming(playerid)
{    
    return 
GetPlayerCameraMode(playerid) == 55 && 22 <= GetPlayerWeapon(playerid) <= 38 && GetPlayerState(playerid) == PLAYER_STATE_PASSENGER;

Reply
#4

Quote:
Originally Posted by OneDay
Посмотреть сообщение
They are not natives only plugins add natives. and this is wrong: 0<=plaerid<=MAX_PLAYERS

why not:

PHP код:

stock bool
:IsPlayerPassengerAiming(playerid)
{    
    return 
GetPlayerCameraMode(playerid) == 55 && 22 <= GetPlayerWeapon(playerid) <= 38 && GetPlayerState(playerid) == PLAYER_STATE_PASSENGER;

What's wrong with the current method, though?

Anyway I don't think natives are just added by plugins.

I'm also not sure why this is wrong -
Код:
 0<=playerid<=MAX_PLAYERS
Reply
#5

Quote:
Originally Posted by Ritzy
Посмотреть сообщение
What's wrong with the current method, though?
Yours:

PHP код:
    proc    IsPlayerPassengerAiming1
    
line 5
    
;$lcl playerid c
    
line 6
    
break    ; c
    
;$lcl wep fffffffc
    stack fffffffc
    push
.s c
    
;$par
    push
.c 4
    sysreq
.c 0    GetPlayerWeapon
    stack 8
    stor
.s.pri fffffffc
    
;$exp
    
line 7
    
break    ; 40
    
;$lcl camera fffffff8
    stack fffffffc
    push
.s c
    
;$par
    push
.c 4
    sysreq
.c 1    GetPlayerCameraMode
    stack 8
    stor
.s.pri fffffff8
    
;$exp
    
line 8
    
break    ; 74
    
;$lcl pState fffffff4
    stack fffffffc
    push
.s c
    
;$par
    push
.c 4
    sysreq
.c 2    GetPlayerState
    stack 8
    stor
.s.pri fffffff4
    
;$exp
    
line a
    
break    ; a8
    load
.s.pri fffffff8
    eq
.c.pri 37
    jzer 1
    
const.pri 16
    load
.s.alt fffffffc
    sleq
    push
.pri
    
const.pri 26
    sgeq
    pop
.alt
    
and
    
jzer 1
    load
.s.pri fffffff4
    eq
.c.pri 3
    jzer 1
    
const.pri 1
    jump 2
l.1
    zero
.pri
l.2
    jzer 0
    
;$exp
    
line b
    
break    ; 12c
    
const.pri 1
    stack c
    retn
l.0        
144
    
line d
    
break    ; 144
    zero
.pri
    stack c
    retn 
My:

PHP код:
    proc    IsPlayerPassengerAiming2
    
line 11
    
;$lcl playerid c
    
line 12
    
break    ; 15c
    push
.s c
    
;$par
    push
.c 4
    sysreq
.c 1    GetPlayerCameraMode
    stack 8
    eq
.c.pri 37
    jzer 3
    push
.s c
    
;$par
    push
.c 4
    sysreq
.c 0    GetPlayerWeapon
    stack 8
    
const.alt 16
    xchg
    sleq
    push
.pri
    
const.pri 26
    sgeq
    pop
.alt
    
and
    
jzer 3
    push
.s c
    
;$par
    push
.c 4
    sysreq
.c 2    GetPlayerState
    stack 8
    eq
.c.pri 3
    jzer 3
    
const.pri 1
    jump 4
l.3
    zero
.pri
l.4
    retn 
Quote:
Originally Posted by Ritzy
Посмотреть сообщение
Anyway I don't think natives are just added by plugins.
Yes:

PHP код:
native IsPlayerPassengerAiming(playerid); 
Код:
Script[gamemodes/aiming.amx]: Run time error 19: "File or function is not found"
Quote:
Originally Posted by Ritzy
Посмотреть сообщение
I'm also not sure why this is wrong -
Код:
 0<=playerid<=MAX_PLAYERS
"< MAX_PLAYERS"
Reply
#6

Quote:
Originally Posted by PatrickGTR
Посмотреть сообщение
It would prompt OB. because the indeces of MAX_PLAYERS in array is 0 to 499 or w/e the value of MAX_PLAYERS take away one, so a valid check would just using < less than, not <= less than or equals

pawn Код:
0 <= playerid < MAX_PLAYERS
EDIT: OneDay beat me to it, damn!
Alright thanks, didn't knew that.
Reply
#7

Just as OneDay says, you're not truly creating native functions. As the PAWN Language Guide says:

Код:
The only means that a pawn program has to manipulate objects in the host application is by calling subroutines, so called “native functions”, that the host application provides.
Plugins allow you to register "subroutines" to the host application (the samp server). A PAWN script cannot create native functions. It needs native functions that the host application provides to it.
Reply
#8

Quote:
Originally Posted by ThePhenix
Посмотреть сообщение
Just as OneDay says, you're not truly creating native functions. As the PAWN Language Guide says:

Код:
The only means that a pawn program has to manipulate objects in the host application is by calling subroutines, so called “native functions”, that the host application provides.
Plugins allow you to register "subroutines" to the host application (the samp server). A PAWN script cannot create native functions on its own. It needs native functions that the host application provides to it.
Yes, thanks. Fixed the title.
Reply
#9

PAWN has short-circuiting. Your code calls 3 functions then checks. My code calls 1 function then checks then may not call another.
Reply
#10

Quote:
Originally Posted by OneDay
Посмотреть сообщение
PAWN has short-circuiting. Your code calls 3 functions then checks. My code calls 1 function then checks then may not call another.
Thanks for that, Optimized the code.
Thanks again.
Reply
#11

useful good job +rep.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)