Skip to content

Conversation

@daniel-w0
Copy link
Contributor

Instead of using sendLua for everything, I've implemented a basic event system so the server & client can both send and receive events from each other.

Here's some example code, if you press the button on the client, it will trigger an event on the server which will then send data back and add some text to the UI.

Server

hooks.register("setData", "setData", function(clientID, data)
    print("setData: " .. data)
    local player = connections[clientID]
    player:triggerEvent("setData", "Hello World")
end)

Client

local M = {}

local imgui = ui_imgui
local message = nil

local function onUpdate()
    if imgui.Begin("KissMP Events") then
        if message then
            imgui.Text(message)
        end
        if imgui.Button("Send Event") then
            network.trigger_event("setData", "Hello World")
        end
    end
end

if network then
    network.register_event("setData", function(data)
        log("D", "eventTest", "setData event called with data: " .. data)
        message = data
    end)
else
    log("E", "eventTest", "network is nil")
end

M.onUpdate = onUpdate

return M

Note: I had issues with KissMP mounting the test mod so just manually enable it and reload it (via "extensions.reload(modName)" )once you get in the server.

@daniel-w0 daniel-w0 changed the title Events Lua Events Feb 3, 2023
@932j
Copy link

932j commented Dec 14, 2025

sorry for interupting but, nobody is joining on beamng 0.28.2. am using KissMP with that exact version of beamng i here ill show you:
image

@932j
Copy link

932j commented Dec 14, 2025

Is there a known issue with KissMP and BeamNG v0.28.2? Or is there something else I should check?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants