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.listtable is updated. - The CharacterLoaded hook is called right before
callbackis ran.
Errors
- If
idis not anumber - If
idis 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)