Squirrel/Server/Functions/Ini/ReadIniFloat
From Liberty Unleashed Wiki
(Difference between revisions)
m (Squirrel/Functions/Ini/ReadIniFloat moved to Squirrel/Server/Functions/Ini/ReadIniFloat: Server-side function only) |
|||
(One intermediate revision by one user not shown) | |||
Line 1: | Line 1: | ||
− | + | {{Squirrel/Title|ReadIniFloat}} | |
+ | {{RequiresModule|lu_ini|Modules/Squirrel/lu_ini}} | ||
This function reads a float value from an .ini file. | This function reads a float value from an .ini file. | ||
Line 16: | Line 17: | ||
<code lang="squirrel"> | <code lang="squirrel"> | ||
− | function | + | function onPlayerCommand( player, command, text ) |
{ | { | ||
local x = ReadIniFloat( "Locations.ini", text, "x" ), | local x = ReadIniFloat( "Locations.ini", text, "x" ), | ||
Line 22: | Line 23: | ||
z = ReadIniFloat( "Locations.ini", text, "z" ); | z = ReadIniFloat( "Locations.ini", text, "z" ); | ||
− | if ( x ) | + | if ( x && y && z ) |
{ | { | ||
local pos = Vector( x, y, z ); | local pos = Vector( x, y, z ); | ||
− | + | player.Pos = pos; | |
− | MessagePlayer( "Teleporting to " +text+ "...", player ); | + | MessagePlayer( "Teleporting to " + text + "...", player ); |
} | } | ||
− | else MessagePlayer( "Location " +text+ " not found.", player ); | + | else MessagePlayer( "Location " + text + " not found.", player ); |
} | } | ||
</code> | </code> | ||
Line 36: | Line 37: | ||
=== Notes === | === Notes === | ||
− | The functions [[Squirrel/Functions/ | + | The functions [[Squirrel/Server/Functions/Players/Pos|Player.Pos]], [[Squirrel/Server/Functions/Messages/MessagePlayer|MessagePlayer]] and call [[Squirrel/Server/Events/Player/onPlayerCommand|onPlayerCommand]] were also used in in this example. More info about them in corresponding pages. |
== Related Functions == | == Related Functions == | ||
− | {{Squirrel/Functions/Ini}} | + | {{Squirrel/Server/Functions/Ini}} |
Latest revision as of 10:27, 11 October 2010
Note: This function requires the external module lu_ini.
This function reads a float value from an .ini file.
[edit] Syntax
float ReadIniFloat( string filename, string section, string var )
[edit] Arguments
- filename This is the name of the file
- section The section that contains the value you want to read
- var The name of the variable
[edit] Example
This example will teleport the player to a previously saved location when they type '/gotoloc LocationName'.
function onPlayerCommand( player, command, text ) { local x = ReadIniFloat( "Locations.ini", text, "x" ), y = ReadIniFloat( "Locations.ini", text, "y" ), z = ReadIniFloat( "Locations.ini", text, "z" ); if ( x && y && z ) { local pos = Vector( x, y, z ); player.Pos = pos; MessagePlayer( "Teleporting to " + text + "...", player ); } else MessagePlayer( "Location " + text + " not found.", player ); }
[edit] Notes
The functions Player.Pos, MessagePlayer and call onPlayerCommand were also used in in this example. More info about them in corresponding pages.
[edit] Related Functions
These functions are provided by the official module lu_ini.