Player Object

class pysamp.playerobject.PlayerObject(id: int, player_id: int)

Bases: object

Create, modify and remove Player Objects using this class.

Player Objects are almost same as normal objects, except for that they are only shown for the player they are created for.

Situations you can consider objects like these, are to preview things for a player, maybe while they are adjusting said thing. Could be used for custom gate systems, where you only want the player to see what they are working on. Or race in systems if you want to show an object for a player in a checkpoint or so.

If you are looking to attach an object to a player, have a look at pysamp.player.Player.set_attached_object()

In order to create a new player object, please use create().

Note

Please note that the global object limit still applies to player objects.

attach_to_vehicle(vehicle: Vehicle, offset_x: float, offset_y: float, offset_z: float, rotation_x: float, rotation_y: float, rotation_z: float) bool

Attach the player object to a vehicle.

Parameters
  • vehicle (Vehicle) – The vehicle to attach the player object to.

  • offset_x (float) – X-coordinate relative to car center.

  • offset_y (float) – Y-coordinate relative to car center.

  • offset_z (float) – Z-coordinate relative to car center.

  • rotation_x (float) – X-axis rotation of the object.

  • rotation_y (float) – Y-axis rotation of the object.

  • rotation_z (float) – Z-axis rotation of the object.

Returns

No return value.

Note

You need to create the object before attaching it. If you are calling this method after set_material_text() you most likely will lose the text. Call this method first, then call set_material_text() after to circumvent it.

classmethod create(player: Player, model_id: int, x: float, y: float, z: float, rotation_x: float, rotation_y: float, rotation_z: float, draw_distance: float) PlayerObject

Create a player object.

Parameters
  • player (Player) – The player that should have an object created.

  • model_id (int) – Which model of the object to create.

  • x (float) – The world x-coordinate to create the object at.

  • y (float) – The world y-coordinate to create the object at.

  • z (float) – The world z-coordinate to create the object at.

  • rotation_x (float) – X-axis rotation of the object.

  • rotation_y (float) – Y-axis rotation of the object.

  • rotation_z (float) – Z-axis rotation of the object.

  • draw_distance (optional float) – The distance at which the object should start being visible at.

Returns

An instance of PlayerObject.

destroy() bool

Destroys the player object.

This removes the object for the player, and it can no longer be interacted with.

Returns

No return value.

edit() bool

Put the player in edit mode to move/rotate the object.

Returns

No return value.

get_model() int

Get the current object model the player object is.

Returns

An integer representing the object model.

get_player() Player

Get the player who owns the player object.

Returns

An instance of :class:~`pysamp.player.Player`

get_position() Tuple[float, float, float]

Get the current coordinates for the player object.

Returns

A tuple with 3 floats; The x, y and z coordinate.

get_rotation() Tuple[float, float, float]

Get the current rotation values for the player object.

Returns

A tuple with 3 floats; The x, y and z rotation.

is_moving() bool

Check if the player object is currently moving.

Returns

A bool (True/False) depending on if it is moving or not.

is_valid() bool

Check if the player object is valid.

Returns

True/False depending on it if is valid or not.

move(x: float, y: float, z: float, speed: float, rotation_x: float = - 1000.0, rotation_y: float = - 1000.0, rotation_z: float = - 1000.0) int

Move and rotate the player object to given values.

Rotation values should be -1000 if you don’t want to modify the object rotation.

Parameters
  • x (float) – The new x-coordinate you want to move the object to.

  • y (float) – The new y-coordinate you want to move the object to.

  • z (float) – The new z-coordinate you want to move the object to.

  • speed (float) – The speed of the object moving from old to new pos.

  • rotation_x (float) – The new object x rotation to set.

  • rotation_y (float) – The new object y rotation to set.

  • rotation_z (float) – The new object z rotation to set.

Returns

The time in milliseconds it takes to move the object.

Note

The rotation will only work if you also move the object. If you do not give it new x,y,z, the rotation will not apply.

classmethod on_move(playerid: int, objectid: int)
set_material(material_index: int, model_id: int, txd_name: str, texture_name: str, material_color: int = 0) bool

Replace the texture of a player-object with the texture from another model in the game.

Note

Vertex lightning of the object will disappear if material color is changed.

Warning

You MUST use ARGB color format, not RGBA like used in client messages etc.

Parameters
  • material_index (int) – The material index on the object to change (0 to 15).

  • model_id (int) – The modelid on which replacement texture is located. Use 0 for alpha. Use -1 to change the material color without altering the existing texture.

  • txd_name (str) – The name of the txd file which contains the replacement texture (use “none” if not required).

  • texture_name (str) – The name of the texture to use as the replacement (use “none” if not required).

  • material_color (int) – The object color to set, as an integer or hex in ARGB format. Using 0 keeps the existing material color.

Returns

No return value.

set_material_text(text: str, material_index: int = 0, material_size: int = 90, font_face: str = 'Arial', font_size: int = 24, bold: bool = True, font_color: int = 4294967295, back_color: int = 0, text_alignment: int = 0) bool

Replace the texture of a player object with text.

Parameters
  • text (str) – The text to set. Max 2048 characters.

  • material_index (optional int) – The material index to replace with text. Default is 0. Valid values are 0-15.

  • material_size (optional int) – The size of the material. Default size is 256x128. See table below for all possible values.

  • font_face (optional str) – The font to use. Default is “Arial”.

  • font_size (optional int) – The size of the font. Default is 24.

  • bold (optional bool) – Whether the text should be bold or not.

  • font_color (optional int) – The color of the text. Default is white (-1).

  • back_color (optional int) – The background color. Default is transparent.

  • text_alignment (optional int) – The alignment of the text. Can be 0 (left), 1 (center) or 2 (right). Default value is 0.

Returns

No return value.

material_size’s for set_material_text().

Constant

Value as integer

OBJECT_MATERIAL_SIZE_32x32

10

OBJECT_MATERIAL_SIZE_64x32

20

OBJECT_MATERIAL_SIZE_64x64

30

OBJECT_MATERIAL_SIZE_128x32

40

OBJECT_MATERIAL_SIZE_128x64

50

OBJECT_MATERIAL_SIZE_128x128

60

OBJECT_MATERIAL_SIZE_256x32

70

OBJECT_MATERIAL_SIZE_256x64

80

OBJECT_MATERIAL_SIZE_256x128

90

OBJECT_MATERIAL_SIZE_256x256

100

OBJECT_MATERIAL_SIZE_512x64

110

OBJECT_MATERIAL_SIZE_512x128

120

OBJECT_MATERIAL_SIZE_512x256

130

OBJECT_MATERIAL_SIZE_512x512

140

set_no_camera_col() bool

Disable player object camera collision.

Returns

No return value.

set_position(x: float, y: float, z: float) bool

Set the world coordinates of the player object

Parameters
  • x (float) – The world x coordinate to set.

  • y (float) – The world y coordinate to set.

  • z (float) – The world z coordinate to set.

Returns

No return value.

set_rotation(rotation_x: float, rotation_y: float, rotation_z: float) bool

Set object rotation values.

Parameters
  • rotation_x (float) – The object x rotation to set.

  • rotation_y (float) – The object y rotation to set.

  • rotation_z (float) – The object z rotation to set.

Returns

No return value.

stop() bool

Stop a moving player object.

This method will only have an effect if you used move() first.

Returns

No return value.