[Include] Players Library (callbacks, functions, and addons)
#1

Players Library
Not any advance library; Just for free guys!
This library is pretty simple and straight forward but will come in great use if you see the capabilities of this. There are 4 branches of this libraries namely:
  • playerfuncs.inc
  • playercalls.inc
  • playerstates.inc
  • playerstats.inc
Each include/branch is standalone, so you may grab and use the one you require. The code is clean and user friendly. You have many features and callbacks and functions to use.

Advantages
  • Faster outputing
  • Wide range of callbacks
  • Wide range of functions
  • Player walking style settings
  • Player update blocking (return 0 in callbaks)
  • Short but effective code
  • Standalone branches
  • All in one version also available!
  • Anti-Fake kill system with callback: OnPlayerFakeKill
  • Time updater is quiet useful. You can use just one callback to update all player stuff and one callback for server as well.
List View
Functions
Quote:
//playerfuncs.inc
native GivePlayerScore(playerid, score);
native SetPlayerMoney(playerid, money);
native RemovePlayerWeapoon(playerid, weaponid);
native SetPlayerFacingPoint(playerid, Float:x, Float:y);
native IsPlayerFacingPoint(playerid, Float:x, Float:y, Float:range = 10.0);
native SetPlayerFacingPlayer(playerid, targetid);
native IsPlayerFacingPlayer(playerid, targetid, Float:range = 10.0);
native IsPlayerBehindPlayer(playerid, targetid, Float:range = 10.0);
native GetPlayerWeaponAmmo(playerid, weaponid);
native SetPlayerWeaponAmmo(playerid, weaponid, ammo);
native SetPlayerWalkingStyle(playerid, style);
native GetPlayerWalkingStyle(playerid);
native GetPlayerSkillLevel(playerid, skill);

//playercalls.inc
native IsPlayerPaused(playerid);
native GetPlayerPausedTime(playerid);

//playerstates.inc
native IsPlayerSpawned(playerid);
native IsPlayerSpectating(playerid);
native IsPlayerDriver(playerid);
native IsPlayerInClassSelection(playerid);
native IsPlayerDead(playerid);

//playerstats.inc
native GetPlayerKills(playerid);
native GetPlayerDeaths(playerid);
native GetPlayerSpree(playerid);
native GetPlayerConnectedTime(playerid, &hours, &minutes, &seconds);
native GetPlayerHeadshots(playerid);
native GetPlayerWeaponShots(playerid);
native GetPlayerWeaponHits(playerid);

Callbacks
Quote:
//playerfuncs.inc
public public OnPlayerWalk(playerid, style)

//playercalls.inc
public OnPlayerPosChange(playerid, Float:newx, Float:newy, Float:newz, Float:oldx, Float:oldy, Float:oldz);
public OnPlayerFacingAngleChange(playerid, Float:newangle, Float:oldangle);
public OnPlayerWeaponChange(playerid, newweapon, oldweapon);
public OnPlayerHealthChange(playerid, Float:newhealth, Float:oldhealth);
public OnPlayerArmourChange(playerid, Float:newarmour, Float:oldarmour);
public OnPlayerVirtualWorldChange(playerid, newworld, oldworld);
public OnPlayerSkinChange(playerid, newskin, oldskin);
public OnPlayerPingChange(playerid, newping, oldping);
public OnPlayerAmmoChange(playerid, weaponid, newammo, oldammo);
public OnPlayerKillPlayer(playerid, killerid, weaponid);
public OnPlayerPause(playerid);
public OnPlayerUnpause(playerid, time);
public OnPlayerFakeKill(playerid, count);
public OnPlayerMoneyChange(playerid, newmoney, oldmoney);
public OnPlayerScoreChange(playerid, newscore, oldscore);

//playerstates.inc
//no callbacks

//playerstats.inc
public OnPlayerHeadshot(playerid, issuerid, weaponid)

Notes
  • Setting walking style is as simple as setting fighting style:
    pawn Code:
    public OnPlayerSpawn(playerid)
    {
        SetplayerWalkingStyle(playerid, WALKING_STYLE_DRUNK);
        return 1;
    }
  • You can run the branches separately or you may use all in one version: playerlib.inc
  • The defined walking styles list can be found in playerfuncs.inc or here:
    pawn Code:
    //walking styles
    #define WALKING_STYLE_DEFAULT     0
    #define WALKING_STYLE_CIVILIAN    1
    #define WALKING_STYLE_GANGSTA     2
    #define WALKING_STYLE_GANGSTA_2   3
    #define WALKING_STYLE_OLD         4
    #define WALKING_STYLE_FAT_OLD     5
    #define WALKING_STYLE_FAT         6
    #define WALKING_STYLE_LADY        7
    #define WALKING_STYLE_LADY_2      8
    #define WALKING_STYLE_WHORE       9
    #define WALKING_STYLE_WHORE_2     10
    #define WALKING_STYLE_DRUNK       11
    #define WALKING_STYLE_BLIND       12
    #define WALKING_STYLE_ARMED       13
  • The callbacks will block the updating of players if you return 0 in them. It will not process when you haven't defined a specific callback.

    Here is all the callback list:
    pawn Code:
    public OnPlayerPosChange(playerid, Float:newx, Float:newy, Float:newz, Float:oldx, Float:oldy, Float:oldz)
    {
        return 1;
    }

    public OnPlayerFacingAngleChange(playerid, Float:newangle, Float:oldangle)
    {
        return 1;
    }

    public OnPlayerWeaponChange(playerid, newweapon, oldweapon)
    {
        return 1;
    }

    public OnPlayerHealthChange(playerid, Float:newhealth, Float:oldhealth)
    {
        return 1;
    }

    public OnPlayerArmourChange(playerid, Float:newarmour, Float:oldarmour)
    {
        return 1;
    }

    public OnPlayerVirtualWorldChange(playerid, newworld, oldworld)
    {
        return 1;
    }

    public OnPlayerSkinChange(playerid, newskin, oldskin)
    {
        return 1;
    }

    public OnPlayerPingChange(playerid, newping, oldping)
    {
        return 1;
    }

    public OnPlayerAmmoChange(playerid, weaponid, newammo, oldammo)
    {
        return 1;
    }

    public OnPlayerKillPlayer(playerid, killerid, weaponid)
    {
        return 1;
    }

    public OnPlayerPause(playerid)
    {
        return 1;
    }

    public OnPlayerUnpause(playerid, time)
    {
        return 1;
    }

    public OnPlayerFakeKill(playerid, count)
    {
        return 1;
    }

    public OnPlayerMoneyChange(playerid, newmoney, oldmoney)
    {
        return 1;
    }

    public OnPlayerScoreChange(playerid, newscore, oldscore)
    {
        return 1;
    }

    public OnPlayerWalk(playerid, style)
    {
        return 1;
    }

    public OnPlayerHeadshot(playerid, issuerid, weaponid)
    {
        return 1;
    }
  • You can block player activity or updating by returning 0 in every callback. For example you have god mode:
    pawn Code:
    public OnPlayerHealthChange(playerid, Float:newhealth, Float:oldhealth)
    {
        if(GodMode[playerid])//if the player has GOD mode ON
        {
            SetPlayerHealth(playerid, 10000.0);
        }
        return 1;
    }
  • If you are making a headshot system, do all the stuff under OnPlayerHeadshot, the script already has done the coding for you(not much though).
  • GetPlayerPausedTime only shows a valid value when the player is paused or AFK. Its value is reset to 0 when the player unpauses his/her game. You can get the paused time from the callback OnPlayerUnpause(playerid, time). The param time is the paused time.
  • No ammo changing technique for snipers (NO RELOAD):
    pawn Code:
    public OnPlayerAmmoChange(playerid, weaponid, newammo, oldammo)
    {
        if(weaponid == 34) return 0;
        return 1;
    }
  • You can disable anti fake kill by commenting
    pawn Code:
    #define ANTI_FAKE_KILL //comment this if you don't want anti fake kill system
Downloads
GITHUB Page

Pastebin - playerfuncs.inc
Pastebin - playercalls.inc
Pastebin - playerstate.inc
Pastebin - playerstats.inc

Changelog
R3 - 13 May, 2015
  • Fixed some bugs in playerfuncs.inc
  • Fixed some bugs in playercalls.inc
  • Added a better method of hooking (funcidx) (thanks Lordzy)
  • Added 2 new callbacks:
    pawn Code:
    public OnPlayerMoneyChange(playerid, newmoney, oldmoney);
    public OnPlayerScoreChange(playerid, newscore, oldscore);
  • Renewed OnPlayerAmmoChange; now detects ammo change completely from internal script or from player!
R2 - 12 May, 2015
  • Added Anti-Fake kill system
R1 - 12 May, 2015
  • Initial release
Reply
#2

pawn Code:
public OnPlayerKillPlayer(playerid, killerid, weaponid)
{
    return 1;
}
https://sampwiki.blast.hk/wiki/OnPlayerDeath

lol
Reply
#3

Quote:
Originally Posted by Emmet_
View Post
pawn Code:
public OnPlayerKillPlayer(playerid, killerid, weaponid)
{
    return 1;
}
https://sampwiki.blast.hk/wiki/OnPlayerDeath

lol
Yeah, that a lol But just for those who dont make these checks:
pawn Code:
public OnPlayerDeath(playerid, killerid, reason)
{
    if( killerid != INVALID_PLAYER_ID &&
        playerid != INVALID_PLAYER_ID &&
        ! IsPlayerNPC(killerid) &&
        ! IsPlayerNPC(playerid))
    {
        reason = GetPlayerWeapon(killerid);
        if(! IsValidWeapon(reason)) reason = 0;

        CallLocalFunction("OnPlayerKillPlayer", "iii", playerid, killerid, reason);
    }
        return 1;
}
Reply
#4

Pretty good. I will use those callbacks
Reply
#5

Ah, okay. Nice btw. I have a suggestion, you can add a "fakekill" parameter to OnPlayerKillPlayer which will make it more useful.
Reply
#6

Quote:
Originally Posted by Emmet_
View Post
Ah, okay. Nice btw. I have a suggestion, you can add a "fakekill" parameter to OnPlayerKillPlayer which will make it more useful.
Sure brother.
Reply
#7

This are same like other SA-MP includes. ._. nothing changed at all.!
Reply
#8

Quote:
Originally Posted by Alex Magaсa
View Post
This are same like other SA-MP includes. ._. nothing changed at all.!
Link of those other relevant includes?

Update:
R2 - 12 May, 2015
  • Added Anti-Fake kill system
Reply
#9

Are the functions inline?

The script will be much faster without using this include.


Make these macros:
GetPlayerPausedTime(playerid)
IsPlayerPaused(playerid)
GivePlayerScore(playerid, score) - Set Player Score already has an internal IsPlayerConnected
SetPlayerMoney(playerid, money)
.
.
.

Update your ALS Hook Method

If a bullet was shot then the ammo will obviously change unless its a hacker.I don't see any use of OnPlayerAmmoChange.

IsPlayerBehindPlayer(playerid, targetid, Float:range = 10.0)
This won't work.

GetPlayerConnectedTime(playerid, &hours, &minutes, &seconds)
There is an equivalent function https://sampwiki.blast.hk/wiki/NetStats_GetConnectedTime

Anyway there are some useful functions in the include.
Good Work!!
Reply
#10

Quote:
Originally Posted by Yashas
View Post
Are the functions inline?
Why would they be? They are in a library.

Quote:
Originally Posted by Yashas
View Post
The script will be much faster without using this include.
False.


Quote:
Originally Posted by Yashas
View Post
Make these macros:
GetPlayerPausedTime(playerid)
IsPlayerPaused(playerid)
GivePlayerScore(playerid, score) - Set Player Score already has an internal IsPlayerConnected
SetPlayerMoney(playerid, money)
Two of those are already inside, one is already native, and the other is VERY simple.

Quote:
Originally Posted by Yashas
View Post
Update your ALS Hook Method
Why? It's fine.

Quote:
Originally Posted by Yashas
View Post
If a bullet was shot then the ammo will obviously change unless its a hacker.I don't see any use of OnPlayerAmmoChange.
There are other uses than anti-hack, this is NOT an anti-hack library.

Quote:
Originally Posted by Yashas
View Post
IsPlayerBehindPlayer(playerid, targetid, Float:range = 10.0)
This won't work.
Yes it will. Have you thought about testing?

Quote:
Originally Posted by Yashas
View Post
GetPlayerConnectedTime(playerid, &hours, &minutes, &seconds)
There is an equivalent function https://sampwiki.blast.hk/wiki/NetStats_GetConnectedTime
No, he made it easier to get the intervals (there are more newbs that need things like that).

Quote:
Originally Posted by Yashas
View Post
Anyway there are some useful functions in the include.
Good Work!!
Finally, something nice!

Rep++.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)