ExecuteSQLUpdate: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
m (SetRegistryValue moved to SetRegistryQuery)

Revision as of 16:53, 22 September 2006

This template is no longer in use as it results in poor readability. This function sets a value in 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 setRegistryValue ( string key, [ string value ] )

Required Arguments

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

Optional Arguments

  • value: A string containing the value you wish to store in the registry. If this value is not passed, the registry key specified will be removed.

Returns

If a value is specified, returns true in all cases. If a value is not specified, returns true if the key specified existed (and has been removed), false if it did not exist.

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

-- Add a command handler called reset_max. This should in practice have some checks for a user's access level.
addCommandHandler ( "reset_max", "resetMaxPlayerCounter" )
function resetMaxPlayerCounter ( )
    setRegistryValue ( "maxPlayerCounter.mostPlayers" ) -- remove the registry key containing the max players record
end

See Also