Lua API¶
The Lua back end is based on LuaJit 2.0.5.
Functions¶
cos¶
function cos(angle)
Returns cosine of angle (radians).
Parameters
- angle: float
Returns
- cosine: float
sin¶
function sin(angle)
Returns sine of angle (radians).
Parameters
- angle: float
Returns
- sine: float
sqrt¶
function sqrt(value)
Returns square root of value.
Parameters
- value: float
Returns
- result: float
atan2¶
function atan2(y, x)
Returns atan2 of y, x.
Parameters
- y: float
- x: float
Returns
- result: float
TwRenderQuad¶
function TwRenderQuad(x, y, width, height)
Draws a quad.
Parameters
- x: float
- y: float
- width: float
- height: float
Returns
- None
TwRenderQuadCentered¶
function TwRenderQuadCentered(x, y, width, height)
Draws a quad centered.
Parameters
- x: float
- y: float
- width: float
- height: float
Returns
- None
TwRenderSetColorU32¶
function TwRenderSetColorU32(color)
0x7F0000FF is half transparent red.Parameters
- color: int
Returns
- None
TwRenderSetColorF4¶
function TwRenderSetColorF4(r, g, b, a)
Parameters
- r: float (0.0 - 1.0)
- g: float (0.0 - 1.0)
- b: float (0.0 - 1.0)
- a: float (0.0 - 1.0)
Returns
- None
TwRenderSetTexture¶
function TwRenderSetTexture(texture_id)
TwRenderSetTexture(TwGetModTexture("duck_butt"));Parameters
- texture_id: int
Returns
- None
TwRenderSetQuadSubSet¶
function TwRenderSetQuadSubSet(x1, y1, x2, y2)
0, 0, 1, 1 is default.Parameters
- x1: float
- y1: float
- x2: float
- y2: float
Returns
- None
TwRenderSetQuadRotation¶
function TwRenderSetQuadRotation(angle)
Parameters
- angle: float (radians)
Returns
- None
TwRenderSetTeeSkin¶
function TwRenderSetTeeSkin(skin)
Parameters
- skin
var skin = {
textures: [
texid_body,
texid_marking,
texid_decoration,
texid_hands,
texid_feet,
texid_eyes
],
colors: [
color_body,
color_marking,
color_decoration,
color_hands,
color_feet,
color_eyes
]
};
var color = {r: 1, g: 1, b: 1, a: 1};Returns
- None
TwRenderSetFreeform¶
function TwRenderSetFreeform(array_vertices)
0,0, 1,0, 1,1, 0,1.Parameters
- array_vertices: float[]
Returns
- None
TwRenderSetDrawSpace¶
function TwRenderSetDrawSpace(draw_space_id)
TwRenderSetDrawSpace(Teeworlds.DRAW_SPACE_HUD).Parameters
- draw_space_id: int
Returns
- None
TwRenderDrawTeeBodyAndFeet¶
function TwRenderDrawTeeBodyAndFeet(tee)
Parameters
- tee:
var tee = {
size: float,
angle: float,
pos_x: float,
pos_y: float,
is_walking: bool,
is_grounded: bool,
got_air_jump: bool,
emote: int,
};
Returns
- None
TwRenderDrawTeeHand¶
function TwRenderDrawTeeHand(tee)
Parameters
- tee:
var hand = {
size: float,
angle_dir: float,
angle_off: float,
pos_x: float,
pos_y: float,
off_x: float,
off_y: float,
};
Returns
- None
TwRenderDrawFreeform¶
function TwRenderDrawFreeform(x, y)
Parameters
- x: float
- y: float
Returns
- None
TwRenderDrawText¶
function TwRenderDrawText(text)
TwRenderDrawText({
text = "This a text",
font_size = 10,
line_width = -1,
pos = {10, 20},
color = {1, 0, 1, 1}, // rgba (0.0 - 1.0)
clip = {100, 25, 200, 100}, // x y width height
});
Parameters
- text:
local text = {
text: string,
font_size: float,
line_width: float,
pos: float[2],
color: float[4],
clip: float[4],
};
Returns
- None
TwGetBaseTexture¶
function TwGetBaseTexture(image_id)
TwGetBaseTexture(Teeworlds.IMAGE_GAME)Parameters
- image_id: int
Returns
- texture_id: int
TwGetSpriteSubSet¶
function TwGetSpriteSubSet(sprite_id)
Parameters
- sprite_id: int
Returns
- subset:
local subset = {
x1: float,
y1: float,
x2: float,
y2: float,
};
TwGetSpriteScale¶
function TwGetSpriteScale(sprite_id)
Parameters
- sprite_id: int
Returns
- scale: {w: float, w: float}
TwGetWeaponSpec¶
function TwGetWeaponSpec(weapon_id)
Parameters
- weapon_id: int
Returns
- TODO
TwGetModTexture¶
function TwGetModTexture(image_name)
TwGetModTexture("duck_burger")Parameters
- image_name: string
Returns
- texture_id: int
TwGetClientSkinInfo¶
function TwGetClientSkinInfo(client_id)
Parameters
- client_id: int
Returns
- skin
local skin = {
textures = {
texid_body: int,
texid_marking: int,
texid_decoration: int,
texid_hands: int,
texid_feet: int,
texid_eyes: int
},
colors = {
color_body: {r, g, b ,a},
color_marking: {r, g, b ,a},
color_decoration: {r, g, b ,a},
color_hands: {r, g, b ,a},
color_feet: {r, g, b ,a},
color_eyes
}
}
TwGetClientCharacterCores¶
function TwGetClientCharacterCores()
Parameters
- None
Returns
- cores
var cores = [
{
tick: int,
vel_x: float,
vel_y: float,
angle: float,
direction: int,
jumped: int,
hooked_player: int,
hook_state: int,
hook_tick: int,
hook_x: float,
hook_y: float,
hook_dx: float,
hook_dy: float,
pos_x: float,
pos_y: float,
},
...
];
TwGetStandardSkinInfo¶
function TwGetStandardSkinInfo()
Parameters
- None
Returns
- skin
var skin = {
textures: [
texid_body: int,
texid_marking: int,
texid_decoration: int,
texid_hands: int,
texid_feet: int,
texid_eyes: int
],
colors: [
color_body: {r, g, b ,a},
color_marking: {r, g, b ,a},
color_decoration: {r, g, b ,a},
color_hands: {r, g, b ,a},
color_feet: {r, g, b ,a},
color_eyes
]
};
TwGetSkinPartTexture¶
function TwGetSkinPartTexture(part_id, part_name)
TwGetSkinPartTexture(Teeworlds.SKINPART_BODY, "zombie")Parameters
- part_id: int
- part_name: string
Returns
- texture_id: int
TwGetCursorPosition¶
function TwGetCursorPosition()
Parameters
- None
Returns
- cursor_pos: { x: float, y: float }
TwGetUiScreenRect¶
function TwGetUiScreenRect()
Parameters
- None
Returns
- rect: { x: float, y: float, w: float, h: float }
TwGetScreenSize¶
function TwGetScreenSize()
Parameters
- None
Returns
- size: { w: float, h: float }
TwGetCamera¶
function TwGetCamera()
Parameters
- None
Returns
- camera: { x: float, y: float, zoom: float }
TwGetUiMousePos¶
function TwGetUiMousePos()
Parameters
- None
Returns
- pos: { x: float, y: float }
TwGetPixelScale¶
function TwGetPixelScale()
const pixelScale = TwGetPixelScale();
var wdith = widthInPixel * pixelScale.x;
TwRenderQuad(0, 0, width, 50);
Parameters
- None
Returns
- scale: { x: float, y: float }
TwPhysGetCores¶
function TwPhysGetCores()
Parameters
- None
Returns
- cores:
local cores = {
{
x: float,
y: float,
},
...
}
TwPhysGetJoints¶
function TwPhysGetJoints()
Parameters
- None
Returns
- joints:
local joints = {
{
core1_id: int or nil,
core2_id: int or nil,
},
...
}
TwPhysSetTileCollisionFlags¶
function TwPhysSetTileCollisionFlags(tile_x, tile_y, flags)
TwMapSetTileCollisionFlags(tx, ty, 0); // airParameters
- tile_x: int
- tile_y: int
- flags: int
Returns
- None
TwDirectionFromAngle¶
function TwDirectionFromAngle(angle)
Parameters
- angle: float
Returns
- dir: { x: float, y: float }
TwSetHudPartsShown¶
function TwSetHudPartsShown(hud)
var hud = {
health: 0,
armor: 0,
ammo: 1,
time: 0,
killfeed: 1,
score: 1,
chat: 1,
scoreboard: 1,
weapon_cursor: 1,
};
TwSetHudPartsShown(hud);
Parameters
- hud
var hud = {
health: bool,
armor: bool,
ammo: bool,
time: bool,
killfeed: bool,
score: bool,
chat: bool,
scoreboard: bool,
weapon_cursor: bool,
};
Returns
- None
TwNetSendPacket¶
function TwNetSendPacket(packet)
local packet = {
net_id = 1478,
force_send_now = 0,
i32_blockID = 1,
i32_flags = 5,
float_pos_x = 180,
float_pos_y = 20,
float_vel_x = 0,
float_vel_y = 0,
float_width = 1000,
float_height = 200,
}
- i32
- u32
- float
- str* (str32_something is a 32 length string)
Parameters
- packet: user edited object based on:
local packet = {
net_id: int,
force_send_now: int (0 or 1),
...
}
Returns
- None
TwNetPacketUnpack¶
function TwNetPacketUnpack(packet, template)
local block = TwNetPacketUnpack(packet, {
"i32_blockID",
"i32_flags",
"float_pos_x",
"float_pos_y",
"float_vel_x",
"float_vel_y",
"float_width",
"float_height"
}
local block = {
blockID: int,
flags: int,
pos_x: float,
pos_y: float,
vel_x: float,
vel_y: float,
width: float,
height:float,
}
- i32
- u32
- float
- str* (str32_something is a 32 length string)
Parameters
- packet: Packet from OnMessage(packet)
- template: user object
Returns
- unpacked: object
TwAddWeapon¶
function TwAddWeapon(weapon)
Parameters
- weapon
var weapon = {
id: int,
tex_weapon: int, // can be null
tex_cursor: int, // can be null
weapon_x: float,
weapon_y: float,
hand_x,: float,
hand_y,: float,
hand_angle,: float,
recoil,: float,
};
Returns
- None
TwPlaySoundAt¶
function TwPlaySoundAt(sound_name, x, y)
Parameters
- sound_name: string
- x: float
- y: float
Returns
- None
TwPlaySoundGlobal¶
function TwPlaySoundGlobal(sound_name)
Parameters
- sound_name: string
Returns
- None
TwPlayMusic¶
function TwPlayMusic(sound_name)
Parameters
- sound_name: string
Returns
- None
TwRandomInt¶
function TwRandomInt(min, max)
TwRandomInt(0, 1000000)/1000000.0Parameters
- min: int
- max: int
Returns
- rand_int: int
TwCalculateTextSize¶
function TwCalculateTextSize(text)
local size = TwCalculateTextSize({
text: "Some text",
font_size: 13,
line_width: 240
}
Parameters
- text:
local text = {
str: string,
font_size: float,
line_width: float
}
Returns
- size: { x: float, y: float }