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
No edit summary
No edit summary
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>
<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 );
}
}

Revision as of 05:17, 22 June 2016

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