player
This namespace provides methods that allow you to interact with your player.
Methods
player.getPosition()
player.getPosition()
Returns your position as a Vec3
Example:
local position = player.getPosition()
print(position:toString()
player.setPosition(position)
player.setPosition(position)
Only works in devmap.
position
- The position you want to set
Sets your position to the given Vec3
Example:
player.setPosition(player.getPosition():add(Vec3:new(0, 0, 1000))
-- Teleport up 1000 units
player.getVelocity()
player.getVelocity()
Returns your velocity as a Vec3.
Example:
local velocity = player.getVelocity()
print(velocity:toString())
player.setVelocity(velocity)
player.setVelocity(velocity)
Only works in devmap.
velocity
- The velocity you want to set
Sets your velocity to the given Vec3
Example:
player.setVelocity(Vec3:new(3000, 3000, 3000))
player.getView()
player.getView()
Returns your viewangles as a Vec3 in the following format
pitch
yaw
roll
Example:
local viewangles = player.getView()
print(tostring(viewangles.y) -- Prints your yaw angle
player.setView(viewAngles)
player.setView(viewAngles)
viewAngles
- A Vec3 with the angles you wish to set
Set your viewangles to the ones defined by the given Vec3
Example:
-- Spin left
function turn()
local view = player.View()
view.y = view.y + 1
player.setView(view)
end
engine.addEventListener("render", turn);
player.getDeltas()
player.getDeltas()
Returns your delta angles as a Vec3.
Example:
local deltas = player.getDeltas()
print(deltas:toString()) -- Your delta angles
player.getCrosshairWorldPosition()
player.getCrosshairWorldPosition()
Returns the position the player currently aims at.
Example:
local aimPosition = player.getCrosshairWorldPosition()
print("I am aiming at " .. aimPosition:toString())
player.get2DSpeed()
player.get2DSpeed()
Returns your current 2D speed.
Example:
local speed = player.get2DSpeed()
print("I am " .. speed .. " units fast")
player.getCurrentWeaponID()
player.getCurrentWeaponID()
Returns the weapon ID of your currently equipped weapon.
Example:
local weaponID = player.getCurrentWeaponID()
print(weaponID)
player.setCurrentWeaponID(id)
player.setCurrentWeaponID(id)
id
The id of the weapon you want to switch to
Switches weapon to the given weapon ID.
Example:
local position = player.getPosition()
print(position:toString())
player.getFPS()
player.getFPS()
Returns your current FPS.
Example:
local fps = player.getFPS()
print("Current fps: " .. fps)
player.setFPS(fps)
player.setFPS(fps)
fps
- The new fps to set
Sets your fps to the given value.
Example:
player.setFPS(250)
player.lookAtPosition(position)
player.lookAtPosition(position)
position
- A position as a Vec3 that you want to look at
Sets your viewangles so that you directly look at the given position
Example:
local closestPlayer = engine.getClosestPlayer()
-- Makes you look at the closest player
player.lookAtPosition(closestPlayer.origin)
player.moveTo(position)
player.moveTo(position)
position
- A position as a Vec3 that you want to move to.
Will move to the given position.
Example:
local closestPlayer = engine.getClosestPlayer()
-- Makes you move to closest player
player.moveTo(closestPlayer.origin)
player.getName()
player.getName()
Returns your name.
Example:
local name = player.getName()
print("My name is " .. name)
player.getMainhandWeaponID()
player.getMainhandWeaponID()
Returns the id of your main weapon.
Example:
local mainWeapon = player.getMainhandWeaponID()
player.setCurrentWeaponID(mainWeapon) -- Switch to main weapon
player.getRPGWeaponID()
player.getRPGWeaponID()
Returns the weapon id of your rpg.
Example:
local rpg = player.getRPGWeaponID()
player.setCurrentWeaponID(rpg) -- Switch to rpg
player.getWeaponDelay()
player.getWeaponDelay()
Returns the delay of your current weapon. The delay indicates how long the weapon is still unusable or in an animation. For example if you shoot the RPG without ADS then it takes time for the RPG to zoom in and eventually fire the rocket. The delay is a number in miliseconds
how much of that animation is left.
Example:
local delay = player.getWeaponDelay()
-- Turn around right before rpg shoots
if (delay < 20 and player.isUsingRPG()) then
local view = player.getView()
view.y = view.y + 180;
player.setView(view)
end
player.isConnectedToServer()
player.isConnectedToServer()
Returns true if you're connected to a remote server.
Example:
print("Connected: " .. tostring(player.isConnectedToServer()))
player.isOnLocalServer()
player.isOnLocalServer()
Returns true if you're on a local server.
Example:
print("on local server?: " .. tostring(player.isOnLocalServer()))
player.isSpectating()
player.isSpectating()
Returns true if you're spectating.
Example:
print("Spectating?: " .. tostring(player.isSpectating()))
player.isUsingRPG()
player.isUsingRPG()
Returns true if you're currently using a RPG.
Example:
-- Disallow rpg usage
if (player.isUsingRPG()) then
player.setCurrentWeaponID(player.getMainhandWeaponID())
end
player.willLeaveGroundThisFrame()
player.willLeaveGroundThisFrame()
Returns true if you will be considered in air this frame. This can either be the result of jumping or walking of a platform etc.
Example:
-- Jump at edges of platforms
if (player.willLeaveGroundThisFrame()) then
engine.getUserCmd().jump()
end
player.willTouchGroundThisFrame()
player.willTouchGroundThisFrame()
Returns true if you will land on ground this frame.
Example:
if (player.willTouchGroundThisFrame()) then
print("Landing on ground now")
end
player.willTouchGroundNextFrame()
player.willTouchGroundNextFrame()
Returns true if you will land on ground next frame.
Example:
if (player.willTouchGroundNextFrame()) then
print("Landing on ground next frame")
end
player.wasInAirLastFrame()
player.wasInAirLastFrame()
Returns true if you were in air last frame.
Example:
if (player.wasInAirLastFrame()) then
print("Was in air last frame (and still could be)")
end
player.didTouchGroundLastFrame()
player.didTouchGroundLastFrame()
Returns true if you landed on ground last frame.hi
Example:
-- Bhop
if (player.didTouchGroundLastFrame()) then
engine.getUserCmd().jump()
end
player.willBounceThisFrame()
player.willBounceThisFrame()
Returns if you will bounce this frame.
Example:
if (player.willBounceThisFrame())
print("I will bounce now")
end
player.willBounceNextFrame()
player.willBounceNextFrame()
Returns if you will bounce next frame.
Example:
if (player.willBounceNextFrame())
print("I will bounce next frame")
end
Last updated