### Lua Player Command Example Source: https://www.cs2d.com/help.php?luacat=all&luacmd=reqcld Example of how to use the 'player' command in Lua. This command is distinct from 'reqcld'. ```lua player(id,"reqcld") ``` -------------------------------- ### Basic ai_goto Lua Command Example Source: https://www.cs2d.com/help.php?luacat=all&luacmd=ai_goto This is a basic example of how to call the `ai_goto` command. It requires player ID, target X, and target Y coordinates. ```Lua ai_goto(id,x,y) ``` -------------------------------- ### Set Weapon by Simplified Name (Example 2) Source: https://www.cs2d.com/help.php?cat=all&cmd=setweapon Another example of setting a weapon using a simplified name. The player must already own the weapon. ```plaintext setweapon 1 fiveseven // simplified name ``` -------------------------------- ### Example of ai_goto Usage in CS2D Source: https://www.cs2d.com/help.php?luacat=all&luacmd=ai_goto This is an example of how the `ai_goto` command might be called within a Lua script, demonstrating the need for variables to hold player ID and target coordinates. ```Lua ai_goto("..id.." "..x.." "..y.." "..w..") ``` -------------------------------- ### AI Goto Command Example (String Concatenation) Source: https://www.cs2d.com/help.php?luacmd=ai_goto An example of calling the `ai_goto` command using string concatenation, as might be done in a console or a context where variables are not directly passed. Note that this is less efficient in pure Lua. ```lua ai_goto("..id.." .." ..x.." .." ..y.." .." ..w..') ``` -------------------------------- ### Example RCon Command Usage Source: https://www.cs2d.com/help.php?cat=all&cmd=rcon Demonstrates how to send a command to the server using RCon. Note that everything after 'rcon' on the same line is sent to the server. ```text rcon sv_fow 0; say "fog disabled" ``` -------------------------------- ### Get Player Ammo Example Source: https://www.cs2d.com/help.php?luacat=player&luacmd=playerammo This snippet demonstrates how to use the playerammo command within a Lua script. It checks if a player's chat message is 'ammo', then retrieves their current weapon type and uses playerammo to get the loaded and spare ammunition, finally displaying this information. ```lua addhook("say","getammo") function getammo(pID, chatMsg) if chatMsg == "ammo" then local weaponType = player(pID, "weapontype") local ammoIn,ammo = playerammo(pID, weaponType) msg(player(pID, "name") .. " ammo: " .. ammoIn .. "|" .. ammo) end end ``` -------------------------------- ### Example of Dynamic Command String Construction Source: https://www.cs2d.com/help.php?hook=parse&hookcat=basic Demonstrates how to construct command strings dynamically. Avoid concatenating empty strings, as it's an unnecessary operation. Ensure variables like 'sid' are defined before use. ```lua cmds = { [slap] = {prse = "slap "..sid..""}, } parse(cmds[slap].prse.."") ``` -------------------------------- ### Create and Modify Image Properties Source: https://www.cs2d.com/help.php?luacat=all&luacmd=imagescale Demonstrates creating an image, setting its color, blend mode, alpha, scale, and position. Use this to dynamically alter image appearance and size. ```lua 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) ``` -------------------------------- ### Basic HTTP GET Request Source: https://www.cs2d.com/help.php?luacat=basic&luacmd=reqhttp Initiates an HTTP GET request to a specified URL and path. The response is handled asynchronously via the httpdata-hook. The first parameter should be the domain or IP without the protocol. ```lua local request = reqhttp("localhost", "/json_data") ``` -------------------------------- ### ai_goto Lua Command with Walk Parameter Source: https://www.cs2d.com/help.php?luacat=all&luacmd=ai_goto This example shows how to use the optional walk parameter in the `ai_goto` command. Setting the last parameter to 1 makes the AI walk instead of run. ```Lua ai_goto(id,x,y,1) ```