Squirrel/Server/Functions/Ini/ReadIniFloat

From Liberty Unleashed Wiki
(Difference between revisions)
Jump to: navigation, search
Line 16: Line 16:
  
 
<code lang="squirrel">
 
<code lang="squirrel">
function OnPlayerCommand( player, command, text )
+
function onPlayerCommand( player, command, text )
 
{
 
{
 
     local x = ReadIniFloat( "Locations.ini", text, "x" ),
 
     local x = ReadIniFloat( "Locations.ini", text, "x" ),
Line 22: Line 22:
 
           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 );
           SetPlayerPos( player, pos );
+
           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 36:
 
=== Notes ===
 
=== Notes ===
  
The functions [[Squirrel/Functions/Player/SetPlayerPos|SetPlayerPos]], [[Squirrel/Functions/Misc/MessagePlayer|MessagePlayer]] and call [[Squirrel/Events/Player/OnPlayerCommand|OnPlayerCommand]] were also used in in this example. More info about them in corresponding pages.
+
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}}

Revision as of 01:06, 27 November 2009

This function reads a float value from an .ini file.

Syntax

  1. float ReadIniFloat( string filename, string section, string var )

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

Example

This example will teleport the player to a previously saved location when they type '/gotoloc LocationName'.

  1.  
  2. function onPlayerCommand( player, command, text )
  3. {
  4. local x = ReadIniFloat( "Locations.ini", text, "x" ),
  5. y = ReadIniFloat( "Locations.ini", text, "y" ),
  6. z = ReadIniFloat( "Locations.ini", text, "z" );
  7.  
  8. if ( x && y && z )
  9. {
  10. local pos = Vector( x, y, z );
  11. player.Pos = pos;
  12.  
  13. MessagePlayer( "Teleporting to " + text + "...", player );
  14. }
  15.  
  16. else MessagePlayer( "Location " + text + " not found.", player );
  17. }
  18.  

Notes

The functions Player.Pos, MessagePlayer and call onPlayerCommand were also used in in this example. More info about them in corresponding pages.

Related Functions

These functions are provided by the official module lu_ini.

Personal tools
Namespaces

Variants
Actions
Navigation
scripting
Toolbox