Commands/Lua

Reference for console commands, Lua hooks and Lua commands in CS2D.

CS2D Command CS2D Console Commands

Lua Hook Lua Hooks

Lua Command Lua Commands

Lua Command image

Categories

Parameters

  • "path"
  • x
  • y
  • mode
  • [player] (optional)

Info

Creates an image (dynamic object) on the map and returns the ID for that image.
The path is relative to the CS2D folder. The position is defined via x and y in pixels. mode defines how the image is displayed (see list below).
Use the optional player parameter if you want the image to be visible to a certain player only (it's visible to all players by default).

Possible modes:

  • Mode 0 - floor image (covered by players etc)

  • Mode 1 - top image (covering players)

  • Mode 2 - HUD image (covering everything, part of the interface, affected by mp_hudscale)

  • Mode 3 - super top image (covering everything on the map)

  • Mode 4 - background image (covering only the background)

  • Mode 101-132 - draw at player, covered by player (player id+100)

  • Mode 201-232 - draw at player, covering player (player id+200)

  • Mode 133-164 - draw at player, covering player and entity images (player id+132)


Meaning of x and y when drawing at player
When drawing an image at a player (mode 101-232), x and y are not used for the position (because it's defined by the player).
Instead x affects rotation and movement behavior related to the player. y affects fog of war visibility.

  • x<=0 - do not rotate image with player

  • x=1 - rotate image with player

  • x=2 - rotate and wiggle image with player

  • x=3 - rotate and wiggle image with player and move correctly with recoil

  • y<=0 - only draw if not covered by fog of war (always if fog of war is disabled)

  • y>0 - draw always


Masking tags
You can append a masking tag to the end of the path to change how the image is masked:

  • PATH<b> - black pixels (rgb 0,0,0 or HEX #000000) will become invisible in the specified image (Default mode. Another masking method might be used if the image has been loaded before with another method. Use the tag to enforce this masking mode)

  • PATH<m> - magenta pixels (rgb 255,0,255 or HEX #FF00FF) will become invisible in the specified image

  • PATH<a> - alpha values (opacity) will be set depending on the brightness of pixels (bright = opaque, dark = transparent)

  • PATH<n> - no masking. The image will be loaded and displayed as it is.


Built-in images/effects
You can use some built-in images by using one of the following values for the path parameter:

  • <tile:X> - a tile from the tileset that is used in the current map, with X being the ID of a tile, starting at 0 for the first tile in the tileset. Attention: Unlike all other Lua images the origin (rotation point/root coordinate) of tiles is not in their center but at their top left corner!

  • <flag:iso> - a small flag image (16x11 pixels) for the given country ISO-3166 ALPHA-2 code. e.g.: AE for United Arab Emirates, DE for Germany, US for United States etc.

  • <avatar:id> - the avatar for the player with this player ID. This will only display something if the player is logged in via Steam or U.S.G.N. and has an avatar there. Moreover avatar download needs to be enabled.

  • <light> - a light with a radius of 128 pixels (only visible with light engine enabled). Uses the color and alpha values of the image (imagecolor / imagealpha). Can be scaled using imagescale (x scale value is used to define a scale for the radius. y scale is ignored. Only a scale range from 0 to 2 is possible. This is a 0 to 256 pixels radius).


spritesheet structure

Spritesheets
You can use the path <spritesheet:PATH:FRAMEW:FRAMEH[:MODE]> to load a spritesheet (a set of images/frames stored in one single image file). PATH is the path to the image, FRAMEW and FRAMEH are the width and height of one frame (in pixels), MODE is an optional masking mode to be applied to the image (See masking mode tags above. Insert letter only!). Only one frame of the sheet will be displayed. By default the first one. You can change the displayed frame by using imageframe!

Note: Always save the returned ID in a variable - otherwise you are not able to remove or change the image!

Note: The game will automatically remove ALL images when a new round begins!

Note: Images which are created with this command are a special type of dynamic objects (object type 40). You can use the object command to get details of your images!

Attention: Using too many images can lead to lags and other problems!

Attention: Missing images are not always transferred over the internet and you can never be sure that all clients/players actually accept and see all those images! Use the file sys/servertransfer.lst to add custom images to the transfer list (this still doesn't ensure that everyone will receive those images but it will work in most cases)

Attention: The default file size limit for transfers is 250kb! Keep each image file size smaller than that, otherwise most clients won't see your images!

Attention: CS2D recycles image IDs. The same ID might be used again for another image after you remove an image!


Sample 1: An image which is visible for all players and part of the HUD (mode 2), covering the radar
image("gfx/hud_buildhelper.png",0,0,2)


Sample 2: Creating an image and changing its look and position/rotation
local id=image("gfx/sprites/flare2.bmp",0,0,2)
imagecolor(id,255,255,0)
imageblend(id,1)
imagealpha(id,0.5)
imagescale(id,2,3)
imagepos(id,30,30,45)


Sample 3: Creating a spritesheet and changing its frame
local id=image("<spritesheet:gfx/buildings.png:32:32:n>",1,0,201)
imageframe(id,3)