nut.char.load - brianhang/nutscript2 GitHub Wiki

Description

nut.char.load(id, callback)

This server function loads a character from the database from a given character ID. The loaded character is then stored in nut.char.list for future use.

Parameters

Name Description
id A number ID for the desired character.
callback An optional function that is called when the character has been loaded. The only parameter is the Character object if loaded, nil otherwise.

Side Effects

  • The database is queried for the desired character.
  • The nut.char.list table is updated.
  • The CharacterLoaded hook is called right before callback is ran.

Errors

  • If id is not a number
  • If id is negative

Example

-- Find all police characters.
nut.db.select("characters", {"id"}, "faction = 'police'", function(result)
    if (result) then
        -- Loop through each character.
        for i = 1, #result do
            nut.char.load(result[i], function(character)
                if (character) then
                    -- Give each police character a piece of candy.
                    character:getInv():add("candy")
                end
            end)
        end
    end
end)