DarkflameServer icon indicating copy to clipboard operation
DarkflameServer copied to clipboard

LUA Scripting Language

Open Wincent01 opened this issue 2 years ago • 0 comments

This LUA scripting implementation uses the sol header only C++ wrapper for the native LUA libraries.

The API does not follow the original LU scripting themes. Each instance of a script is in its own LUA-State, and has 'self' as a global. There are hooks to all the implemented CppScript methods, as well as a subset of the entity functionallity. Has to be expanded upon.

An admin can use /lua load <path-to-file.lua> to load a LUA file relative to the binary.

This is local work which has been sitting for awhile; thought someone might like to take a look at it.

Examples:

-- test.lua
-- To run: /lua load test.lua
local ENEMY_LOT = 14000
local OFFSET_X = 0
local OFFSET_Y = 5
local OFFSET_Z = 0

function init()
    local enemy = spawn{
        lot=ENEMY_LOT,
        position=self:GetPosition() + Vector3.new(OFFSET_X, OFFSET_Y, OFFSET_Z),
        rotation=self:GetRotation(),
    }

    addCallbackTimer(1, function()
        enemy:SetAIDisabled(true)
    end)

    enemy:SetVar("offsetX", OFFSET_X)
    enemy:SetVar("offsetY", OFFSET_Y)
    enemy:SetVar("offsetZ", OFFSET_Z)
    enemy:SetVar("spawner", self)

    enemy:SetFaction(-1)
    enemy:SetIsImmune(true)
    enemy:SetIsSmashable(false)

    enemy:LoadScript("test2.lua")
end

init()
-- test2.lua
function attackAOE()
    -- TODO!
end

function attack()
    attackAOE()
    
    self:PlayAnimation("attack2")
    self:Serialize()

    addCallbackTimer(10, attack)
end

attack()

Wincent01 avatar Apr 13 '22 18:04 Wincent01