ExecuteSQLSelect: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 17: Line 17:
This example keeps track of the largest number of players playing at once on the server and announces each time the record has been broken.
This example keeps track of the largest number of players playing at once on the server and announces each time the record has been broken.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- Trigger our function every time a player joins
addEventHandler ( "onPlayerJoin", getRootElement(), "maxPlayerCounter" )
addEventHandler ( "onPlayerJoin", getRootElement(), "maxPlayerCounter" )
function maxPlayerCounter ( )
function maxPlayerCounter ( )
     mostPlayers = getRegistryValue ( "maxPlayerCounter.mostPlayers" )
     mostPlayers = getRegistryValue ( "maxPlayerCounter.mostPlayers" ) -- get the previous record from the registry
     playerCount = getPlayerCount()
     playerCount = getPlayerCount() -- get the number of players now
     if ( mostPlayers == false or playerCount > mostPlayers )
     if ( mostPlayers == false or playerCount > mostPlayers ) -- see if there was a previous record and if there was, see if we've broken it
         outputChatBox ( "New player count record: " .. playerCount .. " players!" )
         outputChatBox ( "New player count record: " .. playerCount .. " players!" ) -- display a message in the chat box
         setRegistryValue ( "maxPlayerCounter.mostPlayers", playerCount )
         setRegistryValue ( "maxPlayerCounter.mostPlayers", playerCount ) -- store our new record
     end
     end
end
end

Revision as of 11:37, 8 September 2006

This template is no longer in use as it results in poor readability. This function retrieves a value from the server's registry. This is data that is stored across sessions and can be read by any script. This is useful if you want to easily store a setting for your script.

Syntax

string getRegistryValue ( string key )

Required Arguments

  • key: The key under which the data you wish to retrieve was stored

Returns

Returns a string containing the value stored or false if no value is stored under the specified key.

Example

This example keeps track of the largest number of players playing at once on the server and announces each time the record has been broken.

-- Trigger our function every time a player joins
addEventHandler ( "onPlayerJoin", getRootElement(), "maxPlayerCounter" )
function maxPlayerCounter ( )
    mostPlayers = getRegistryValue ( "maxPlayerCounter.mostPlayers" ) -- get the previous record from the registry
    playerCount = getPlayerCount() -- get the number of players now
    if ( mostPlayers == false or playerCount > mostPlayers ) -- see if there was a previous record and if there was, see if we've broken it
        outputChatBox ( "New player count record: " .. playerCount .. " players!" ) -- display a message in the chat box
        setRegistryValue ( "maxPlayerCounter.mostPlayers", playerCount ) -- store our new record
    end
end

See Also