Scripting/Squirrel/Functions/ReadIniNumber: Difference between revisions

From Vice City Multiplayer
Jump to navigation Jump to search
Caution icon
This wiki is using an old backup from 2020
Some information may be old/missing
(Created page with "__NOTOC__ This function reads a float value from an .ini file. == Syntax == <code>float ReadIniNumber( string filename, string section, string var )</code> == Arguments ==...")
 
No edit summary
 
(2 intermediate revisions by one other user not shown)
Line 15: Line 15:
This example will teleport the player to a previously saved location when they type '/c gotoloc LocationName'.
This example will teleport the player to a previously saved location when they type '/c gotoloc LocationName'.


<code lang="squirrel">
<code lang ="squirrel">
function onPlayerCommand( player, command, text )
function onPlayerCommand( player, command, text )
{
{
Line 21: Line 21:
           y = ReadIniNumber( "Locations.ini", text, "y" ),
           y = ReadIniNumber( "Locations.ini", text, "y" ),
           z = ReadIniNumber( "Locations.ini", text, "z" );
           z = ReadIniNumber( "Locations.ini", text, "z" );
     if ( x )
     if ( x )
     {
     {
           local pos = Vector( x, y, z );
           local pos = Vector( x, y, z );
           player.Pos = 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 );
}
}
Line 41: Line 38:


{{Scripting/Squirrel/Functions/INI Functions}}
{{Scripting/Squirrel/Functions/INI Functions}}
[[Category:Scripting/Squirrel/Functions/INI_Functions]]

Latest revision as of 18:16, 30 January 2017

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

Syntax

float ReadIniNumber( 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 '/c gotoloc LocationName'.

function onPlayerCommand( player, command, text ) {

    local x = ReadIniNumber( "Locations.ini", text, "x" ),
          y = ReadIniNumber( "Locations.ini", text, "y" ),
          z = ReadIniNumber( "Locations.ini", text, "z" );
    if ( x )
    {
         local pos = Vector( x, y, z );
         player.Pos = pos;
         MessagePlayer( "Teleporting to " + text + "...", player );
    }
    else MessagePlayer( "Location " + text + " not found.", player );

}

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