nut.char.create - brianhang/nutscript2 GitHub Wiki

Description

success, reason = nut.char.create(info, callback, context)

This server function uses the given character information to insert a new character into the database and create a Character object that can be used afterwards.

Parameters

Name Description
info A table of information about the character. The keys should correspond to character variables set up with nut.char.registerVar.
callback An optional function that runs once the character is made. The only parameter for the callback is the new Character object. This object may be nil if the character could not be inserted.
context An optional table to provide some arbitrary information for character creation. This is passed along to the hooks mentioned below.

Side Effects

Errors

  • info is not a table
  • info contains a character variable that has not been set up with nut.char.registerVar

Returns

Name Description
success A boolean for whether or not the character is valid.
reason If success is false, this is the string containing the reason why.

Example

-- Some variables for the character.
local info = {
    name = "John Doe",
    desc = "A regular person.",
    model = "models/player/police.mdl",
    job = TEAM_CITIZEN,
    money = 0
}

-- Create the character with the information above.
nut.char.create(info, function(character)
    -- Welcome the character once made.
    if (character) then
        character:setData("regular", true)
        character:setData("person", true)

        print("Welcome to the world, "..character:getName().."!")
    else
        print(nut.db.lastError)
    end
end)