[Include] perplayer.inc - collection of player-based functions (ForPlayer analogues)
#1

Per-player functions
(powered by Pawn.RakNet)
Description:
This library implements analogues of ordinary native ones like SetPlayerSkin or SetVehicleNumber, but with the possibility of applying them to one specific player, as you can do this, for example, using the existing CreateExplosion and CreateExplosionForPlayer functions. You could already see some of the functions in YSF and SKY plugins earlier (the functionality of which prompted me to create this include), but there are few of them and those plugins have a broader purpose of using that not everyone might need.

List of functions & documentation:
  • SetPlayerGravity(playerid, Float:gravity)
    HTML Code:
    Sets the gravity for a specific player.
    
    Parameters:
    * playerid - The ID of the player to set the gravity of.
    * gravity - The value that the gravity should be set to (between -50.0 and 50.0).
    
    Returns 1 on success or 0 if the specified player isn't connected or the gravity parameter is incorrect.
  • SetPlayerNameForPlayer(playerid, forplayerid, const name[])
    HTML Code:
    Sets the name of one player for another player.
    
    Parameters:
    * playerid - The ID of the player to set the name of.
    * forplayerid - The ID of the player who will see the name change of playerid.
    * name[] - The name to set. Must be 1-24 characters long and only contain valid characters (0-9, a-z, A-Z, [], (), $ @ . _ and =).
    
    Returns:
    1 if the name was successfully changed.
    0 if the name is already used by someone (including playerid) or the specified player(s) isn't connected.
    -1 if the name cannot be changed for other reasons (too long/short or has invalid characters).
  • SetPlayerSkillLevelForPlayer(playerid, forplayerid, skill, level)
    HTML Code:
    Sets the skill level of a certain weapon type of one player for another player.
    
    Parameters:
    * playerid - The ID of the player to set the weapon skill of.
    * forplayerid - The ID of the player who will see the weapon skill change of playerid.
    * skill - The ID of the weapon skill (not the ID of the weapon).
    * level - The skill level ranging from 0 to 999. A value that exceeds this range will be perceived as 999.
    
    Returns 1 on success or 0 if the specified player(s) isn't connected or the skill parameter is incorrect.
  • SetPlayerFightingStyleForPlayer(playerid, forplayerid, style)
    HTML Code:
    Sets the special fighting style of one player for another player.
    To use in-game, aim and press the 'secondary attack' key (ENTER by default).
    
    Parameters:
    * playerid - The ID of the player to set the fighting style of.
    * forplayerid - The ID of the player who will see the fighting style change of playerid.
    * style - The ID of the fighting style that should be set.
    
    Returns 1 on success or 0 if the specified player(s) isn't connected or the style parameter is incorrect.
  • SetPlayerTeamForPlayer(playerid, forplayerid, teamid)
    HTML Code:
    Sets the team of one player for another player.
    
    Parameters:
    * playerid - The ID of the player to set the team of.
    * forplayerid - The ID of the player who will see the team change of playerid.
    * teamid - The ID of the team to put the player in. Use NO_TEAM to remove any team.
    
    Returns 1 on success or 0 if the specified player(s) isn't connected.
  • SetPlayerSkinForPlayer(playerid, forplayerid, skinid)
    HTML Code:
    Sets the skin of one player for another player.
    
    Parameters:
    * playerid - The ID of the player to set the skin of.
    * forplayerid - The ID of the player who will see the skin change of playerid.
    * skinid - The ID of the skin the player should use.
    
    Returns 1 on success or 0 if the specified player(s) isn't connected.
  • ApplyAnimationForPlayer(playerid, forplayerid, const animlib[], const animname[], Float:fDelta, loop, lockx, locky, freeze, time)
    HTML Code:
    Apply an animation to one player for another player.
    
    Parameters:
    * playerid - The ID of the player to apply the animation to.
    * forplayerid - The ID of the player who will see the animation change of playerid.
    * animlib[] - The animation library from which to apply an animation.
    * animname[] - The name of the animation to apply, within the specified library.
    * fDelta - The speed to play the animation.
    * loop - Whether it will loop (1) or not (0).
    * lockx, locky - If set to 0, the player will be returned to his old X and Y coordinates once the animation is complete.
    * freeze - Setting this to 1 will freeze the player at the end of the animation.
    * time - Timer in milliseconds. For a never-ending loop it should be 0.
    
    Returns 1 on success or 0 if the specified player(s) isn't connected.
  • ClearAnimationsForPlayer(playerid, forplayerid)
    HTML Code:
    Clears all animations of one player for another player.
    
    Parameters:
    * playerid - The ID of the player to clear the animations of.
    * forplayerid - The ID of the player who will see the animation stop of playerid.
    
    Returns 1 on success or 0 if the specified player(s) isn't connected.
  • SetPlayerChatBubbleForPlayer(playerid, forplayerid, const text[], color, Float:drawdistance, expiretime)
    HTML Code:
    Creates a chat bubble (3D text) above one player's name tag for another player.
    
    Parameters:
    * playerid - The player which should have the chat bubble.
    * forplayerid - The ID of the player who will see the chat bubble above playerid.
    * text[] - The text to display.
    * color - The text color.
    * drawdistance - The distance from which forplayerid is able to see the chat bubble.
    * expiretime - The time in milliseconds the bubble should be displayed for.
    
    Returns 1 on success or 0 if the specified player(s) isn't connected.
  • SetAttachedObjectForPlayer(playerid, forplayerid, index, modelid, bone, Float:fOffsetX = 0.0, Float:fOffsetY = 0.0, Float:fOffsetZ = 0.0, Float:fRotX = 0.0, Float:fRotY = 0.0, Float:fRotZ = 0.0, Float:fScaleX = 1.0, Float:fScaleY = 1.0, Float:fScaleZ = 1.0, materialcolor1 = 0, materialcolor2 = 0)
    HTML Code:
    Attach an object to a specific bone on a player for another player.
    
    Parameters:
    * playerid - The ID of the player to attach the object to.
    * forplayerid - The ID of the player who will see the attached object to playerid.
    * index - The index (slot) to assign the object to (from 0 to 9).
    * modelid - The model to attach.
    * bone - The bone to attach the object to.
    * fOffsetX - X axis offset for the object position (0.0 by default).
    * fOffsetY - Y axis offset for the object position (0.0 by default).
    * fOffsetZ - Z axis offset for the object position (0.0 by default).
    * fRotX - X axis rotation of the object (0.0 by default).
    * fRotY - Y axis rotation of the object (0.0 by default).
    * fRotZ - Z axis rotation of the object (0.0 by default).
    * fScaleX - X axis scale of the object (1.0 by default).
    * fScaleY - Y axis scale of the object (1.0 by default).
    * fScaleZ - Z axis scale of the object (1.0 by default).
    * materialcolor1 - The first object color to set, as an integer or hex in ARGB color format (0 by default).
    * materialcolor2 - The second object color to set, as an integer or hex in ARGB color format (0 by default).
    
    Returns 1 on success or 0 if the specified player(s) isn't connected or the index parameter is incorrect.
  • RemoveAttachedObjectForPlayer(playerid, forplayerid, index)
    HTML Code:
    Removes an attached object from one player for another player.
    
    Parameters:
    * playerid - The ID of the player to remove the object from.
    * forplayerid - The ID of the player who will see the removal of the attached object from playerid.
    * index - The index (slot) of the object to remove (set with SetPlayerAttachedObject).
    
    Returns 1 on success or 0 if the specified player(s) isn't connected or the index parameter is incorrect.
  • ChangeVehicleColorForPlayer(playerid, vehicleid, color1, color2)
    HTML Code:
    Changes a vehicle's primary and secondary colors for a specific player.
    
    Parameters:
    * playerid - The ID of the player for whom you want to change the colors of the specified vehicle.
    * vehicleid - The ID of the vehicle to change the colors of.
    * color1 - The new vehicle's primary color ID.
    * color2 - The new vehicle's secondary color ID.
    
    Returns 1 on success or 0 if the specified player or vehicle doesn't exist.
  • ChangeVehiclePaintjobForPlayer(playerid, vehicleid, paintjobid)
    HTML Code:
    Changes a vehicle's paintjob for a specific player.
    
    Parameters:
    * playerid - The ID of the player for whom you want to change the paintjob of the specified vehicle.
    * vehicleid - The ID of the vehicle to change the paintjob of.
    * paintjobid - The ID of the paintjob to apply. Use 3 to remove a paintjob.
    
    Returns 1 on success or 0 if the specified player or vehicle doesn't exist.
  • AddVehicleComponentForPlayer(playerid, vehicleid, componentid)
    HTML Code:
    Adds a tuning component (modification) to a vehicle for a specific player.
    
    Parameters:
    * playerid - The ID of the player for whom you want to add the component to the specified vehicle.
    * vehicleid - The ID of the vehicle to add the component to.
    * componentid - The ID of the component to add to the vehicle.
    
    Returns 1 on success or 0 if the specified player or vehicle doesn't exist.
  • RemoveVehicleComponentForPlayer(playerid, vehicleid, componentid)
    HTML Code:
    Removes a tuning component from a vehicle for a specific player.
    
    Parameters:
    * playerid - The ID of the player for whom you want to remove the component from the specified vehicle.
    * vehicleid - The ID of the vehicle to remove the component from.
    * componentid - The ID of the component to remove.
    
    Returns 1 on success or 0 if the specified player or vehicle doesn't exist.
  • LinkVehicleToInteriorForPlayer(playerid, vehicleid, interiorid)
    HTML Code:
    Links a vehicle to an interior for a specific player.
    
    Parameters:
    * playerid - The ID of the player for whom you want to change the interior of the specified vehicle.
    * vehicleid - The ID of the vehicle to link to an interior.
    * interiorid - The interior ID to link it to.
    
    Returns 1 on success or 0 if the specified player or vehicle doesn't exist.
  • SetVehicleNumberPlateForPlayer(playerid, vehicleid, const numberplate[])
    HTML Code:
    Sets a vehicle number plate for a specific player.
    
    Parameters:
    * playerid - The ID of the player for whom you want to change the number plate of the specified vehicle.
    * vehicleid - The ID of the vehicle to set the number plate of.
    * numberplate[] - The text that should be displayed on the number plate.
    
    Returns 1 on success or 0 if the specified player or vehicle doesn't exist.
  • SetVehicleHealthForPlayer(playerid, vehicleid, Float:health)
    HTML Code:
    Sets a vehicle's health for a specific player.
    
    Parameters:
    * playerid - The ID of the player for whom you want to change the health of the specified vehicle.
    * vehicleid - The ID of the vehicle to set the health of.
    * health - The health, given as a float value.
    
    Returns 1 on success or 0 if the specified player or vehicle doesn't exist.
  • UpdateVehDamageStatusForPlayer(playerid, vehicleid, panels, doors, lights, tires)
    HTML Code:
    Sets the various visual damage statuses of a vehicle for a specific player.
    For example, popped tires, broken lights and damaged panels.
    
    Parameters:
    * playerid - The ID of the player for whom you want to change the damage status of the specified vehicle.
    * vehicleid - The ID of the vehicle to set the damage of.
    * panels - A set of bits containing the panel damage status.
    * doors - A set of bits containing the door damage status.
    * lights - A set of bits containing the light damage status.
    * tires - A set of bits containing the tire damage status.
    
    Returns 1 on success or 0 if the specified player or vehicle doesn't exist.
  • RepairVehicleForPlayer(playerid, vehicleid)
    HTML Code:
    Fully repairs a vehicle for a specific player, including visual damage (bumps, dents, scratches, popped tires).
    
    Parameters:
    * playerid - The ID of the player for whom you want to repair the specified vehicle.
    * vehicleid - The ID of the vehicle to repair.
    
    Returns 1 on success or 0 if the specified player or vehicle doesn't exist.
  • SetVehiclePosForPlayer(playerid, vehicleid, Float:x, Float:y, Float:z)
    HTML Code:
    Sets a vehicle's position for a specific player.
    
    Parameters:
    * playerid - The ID of the player for whom you want to change the position of the specified vehicle.
    * vehicleid - The ID of the vehicle that you want to set new position.
    * x - The X coordinate to position the vehicle at.
    * y - The Y coordinate to position the vehicle at.
    * z - The Z coordinate to position the vehicle at.
    
    Returns 1 on success or 0 if the specified player or vehicle doesn't exist.
  • SetVehicleZAngleForPlayer(playerid, vehicleid, Float:z_angle)
    HTML Code:
    Sets the Z rotation (yaw) of a vehicle for a specific player.
    
    Parameters:
    * playerid - The ID of the player for whom you want to change the Z angle of the specified vehicle.
    * vehicleid - The ID of the vehicle to set the rotation of.
    * z_angle - The Z angle to set.
    
    Returns 1 on success or 0 if the specified player or vehicle doesn't exist.
  • SetVehicleVelocityForPlayer(playerid, vehicleid, Float:X, Float:Y, Float:Z)
    HTML Code:
    Sets the X, Y and Z velocity of a vehicle for a specific player.
    
    Parameters:
    * playerid - The ID of the player for whom you want to change the velocity of the specified vehicle.
    * vehicleid - The ID of the vehicle to set the velocity of.
    * X - The velocity in the X direction.
    * Y - The velocity in the Y direction.
    * Z - The velocity in the Z direction.
    
    Returns 1 on success or 0 if the specified player or vehicle doesn't exist.
  • SetVehicleAngVelocityForPlayer(playerid, vehicleid, Float:X, Float:Y, Float:Z)
    HTML Code:
    Sets the angular X, Y and Z velocity of a vehicle for a specific player.
    
    Parameters:
    * playerid - The ID of the player for whom you want to change the angular velocity of the specified vehicle.
    * vehicleid - The ID of the vehicle to set the angular velocity of.
    * X - The amount of velocity in the angular X direction.
    * Y - The amount of velocity in the angular Y direction.
    * Z - The amount of velocity in the angular Z direction.
    
    Returns 1 on success or 0 if the specified player or vehicle doesn't exist.
  • AttachTrailerToVehicleForPlayer(playerid, trailerid, vehicleid)
    HTML Code:
    Attach a vehicle to another vehicle as a trailer for a specific player.
    
    Parameters:
    * playerid - The ID of the player for whom you want to attach the trailer to the specified vehicle.
    * trailerid - The ID of the vehicle that will be attached to vehicleid.
    * vehicleid - The ID of the vehicle to which trailerid will be attached.
    
    Returns 1 on success or 0 if the specified player or vehicle(s) doesn't exist.
  • DetachTrailerFromVehForPlayer(playerid, vehicleid)
    HTML Code:
    Detach the connection between a vehicle and its trailer for a specific player.
    
    Parameters:
    * playerid - The ID of the player for whom you want to detach the trailer from the specified vehicle.
    * vehicleid - The ID of the vehicle to detach the trailer from.
    
    Returns 1 on success or 0 if the specified player or vehicle(s) doesn't exist.
For the functions that have both playerid and forplayerid as their parameters you can specify for them either the same IDs or different player IDs, thus in the first case the changes will be visible only to the player to whom they are applied (and as a result, if it's possible, the player will synchronize them for others himself), while in the second case the changes applied to playerid will not be visible for him, as they are visible only to forplayerid.

Dependencies:
Pawn.RakNet plugin

Download:
v1.2: MediaFire Pastebin

Notes:
This library doesn't contain functions that can get any data for a specific player (Get<...>ForPlayer), since their implementation on Pawn would require the allocation of a really large amount of memory most of which wouldn't be used at all during the server work, which I found ineffective. So if someone wants to do this in plugin where it would be more appropriate - don't hesitate to take the code and change it as you like, I don't mind.

Changelog:
HTML Code:
v1.0
* Initial release

v1.1
* Fixed SetPlayerNameForPlayer function

v1.2
* Compatibility with the latest Pawn.RakNet plugin version
Bugs:
Not found at the moment. If you find strange behavior of any of the functions or other errors, report them in this thread.

Credits:
* KashCherry, BrunoBM16 - list of RPC IDs and parameters
* urShadow - some help with Pawn.RakNet
Reply
#2

Nice
Reply
#3

Very interesting.

I use the Pawn.RakNet plugin for a long time and this will certainly be helpful.
Reply
#4

More one for your include. I have a lot of functions like this made by me, it was made when I was studying Pawn.RakNet with BrunoBM16.
PHP Code:
stock ToggleWidescreenForPlayer(playeridbool:enable)
{
    if(!
IsPlayerConnected(playerid))
        return 
false;
    new 
BitStream:bs BS_New();
    
BS_WriteValue(
        
bs
        
PR_BOOLenable
    
);
    
BS_RPC(bsplayerid0x6F);
    
BS_Delete(bs);
    return 
true;

Reply
#5

Quote:
Originally Posted by Cycle
View Post
I can give you some functions.

I made an include with a lot of functions like this.

Below there's one.:
PHP Code:
stock ToggleWidescreenForPlayer(playeridbool:enable)
{
    if(!
IsPlayerConnected(playerid))
        return 
false;
    new 
BitStream:bs BS_New();
    
BS_WriteValue(
        
bs
        
PR_BOOLenable
    
);
    
BS_RPC(bsplayerid0x6F);
    
BS_Delete(bs);
    return 
true;

Thanks, but it seems that this function is unstable, therefore it's hidden and inaccessible in samp by default. As far as I remember, different players had black bars at the top and bottom of the screen, while others didn't have them and only the hood was hidden.
Reply
#6

Quote:
Originally Posted by OstGot
View Post
Thanks, but it seems that this function is unstable, therefore it's hidden and inaccessible in samp by default. As far as I remember, different players had black bars at the top and bottom of the screen, while others didn't have them and only the hood was hidden.
uhh, I didn't know about that. The functions I've done similar to yours have been around for a long time, and even I haven't updated them.
Reply
#7

Quote:
Originally Posted by OstGot
View Post
Thanks, but it seems that this function is unstable, therefore it's hidden and inaccessible in samp by default. As far as I remember, different players had black bars at the top and bottom of the screen, while others didn't have them and only the hood was hidden.
Hood is always hidden if i remember correctly and players have black tapes over the screen due to aspect ratio (widescreen settings). Basically if you have wrong resolution and/or widescreen settings then you get tape.
Reply
#8

Great work!
Reply
#9

v1.1
* Fixed SetPlayerNameForPlayer function
Reply
#10

v1.2
* Compatibility with the latest Pawn.RakNet plugin version
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)