Can't Manage to Make HTTP calls for a game mod
First of all, I must say I have no prior modding or Lua background. But, I wanted to create a mod for Baldur's Gate 3 by using BG3 Script Extender, which allows people to write Lua noscripts to interact with the game state.
So, I wanted to see if I could manage to write a Lua noscript that can communicate with SteelSeries Game Engine to manipulate my keyboard's lights, to react to game state (e.g. character health bar on function keys as green light).
With the help of ChatGPT I generated a simple Lua noscript for my use case, which utilizes `socket.http` library:
local http = require("socket.http")
-- Perform the GET request
local response_body, status_code, response_headers = http.request("https://jsonplaceholder.typicode.com/todos/1")
-- Print the response
print("Status Code:", status_code) -- Similar to `response.status`
print("Response Body:", response_body) -- Similar to `response.text()`
local function parse_json(json_str)
local result = {}
for key, value in json_str:gmatch('"([^"]+)":%s*("?.-["}]?)%s*[,%}]') do
-- Remove quotes from keys and values if present
key = key:gsub('"', '')
if value:match('^".*"$') then
value = value:sub(2, -2) -- Remove quotes for strings
elseif value == "true" then
value = true
elseif value == "false" then
value = false
elseif tonumber(value) then
value = tonumber(value)
end
result[key] = value
end
return result
end
-- Parse the JSON response
local data = parse_json(response_body)
-- Access the parsed data
print("Title:", data.noscript)
print("Completed:", data.completed)
The [jsonplaceholder.typicode.com](http://jsonplaceholder.typicode.com) link is only there to test if I can manage to make a call and get a result. I would then replace it with my local Game Engine server URL to communicate with the peripherals.
It seemed to work fine when I ran the Lua noscript using **Lua.exe**. However, after I packaged the noscript and added it as a mod to the game, the Script Extender threw an error:
Loading bootstrap noscript: Mods/SteelSeriesLights/ScriptExtender/Lua/BootstrapServer.lua
bg3se::ExtensionStateBase::LuaLoadGameFile(): Script file could not be opened: Mods/SteelSeriesLights/ScriptExtender/Lua/socket.http
bg3se::lua::State::LoadScript(): Failed to execute noscript: [string "SteelSeriesLights/Server/lights.lua"]:4: attempt to index a nil value (local 'http')
stack traceback:
SteelSeriesLights/Server/lights.lua:4: in main chunk
[C++ Code]: in field 'Include'
builtin://Libs/FileLoader.lua:34: in function <builtin://Libs/FileLoader.lua:6>
(...tail calls...)
SteelSeriesLights/BootstrapServer.lua:1: in main chunk
[C++ Code]: in field 'Include'
builtin://Libs/ModLoader.lua:68: in method 'LoadBootstrap'
builtin://BuiltinLibrary.lua:26: in function <builtin://BuiltinLibrary.lua:25>
From what I can understand, it is interpreting `local http = require("socket.http")` expression as a module file that I created next to my main noscript. To get around this, I checked if I could just put the whole [socket.http code](https://github.com/lunarmodules/luasocket/blob/master/src/http.lua) within the noscript itself, but it also seems to have other dependencies.
Coming from a JavaScript background, I expected to be able to call a method like **fetch** that is built-in to the language, but so far I failed to accomplish my task.
If you could direct me toward any documentation or topic about Lua that might help me understand how to make it work, I would highly appreciate it\^\^
https://redd.it/1h52czt
@r_lua
First of all, I must say I have no prior modding or Lua background. But, I wanted to create a mod for Baldur's Gate 3 by using BG3 Script Extender, which allows people to write Lua noscripts to interact with the game state.
So, I wanted to see if I could manage to write a Lua noscript that can communicate with SteelSeries Game Engine to manipulate my keyboard's lights, to react to game state (e.g. character health bar on function keys as green light).
With the help of ChatGPT I generated a simple Lua noscript for my use case, which utilizes `socket.http` library:
local http = require("socket.http")
-- Perform the GET request
local response_body, status_code, response_headers = http.request("https://jsonplaceholder.typicode.com/todos/1")
-- Print the response
print("Status Code:", status_code) -- Similar to `response.status`
print("Response Body:", response_body) -- Similar to `response.text()`
local function parse_json(json_str)
local result = {}
for key, value in json_str:gmatch('"([^"]+)":%s*("?.-["}]?)%s*[,%}]') do
-- Remove quotes from keys and values if present
key = key:gsub('"', '')
if value:match('^".*"$') then
value = value:sub(2, -2) -- Remove quotes for strings
elseif value == "true" then
value = true
elseif value == "false" then
value = false
elseif tonumber(value) then
value = tonumber(value)
end
result[key] = value
end
return result
end
-- Parse the JSON response
local data = parse_json(response_body)
-- Access the parsed data
print("Title:", data.noscript)
print("Completed:", data.completed)
The [jsonplaceholder.typicode.com](http://jsonplaceholder.typicode.com) link is only there to test if I can manage to make a call and get a result. I would then replace it with my local Game Engine server URL to communicate with the peripherals.
It seemed to work fine when I ran the Lua noscript using **Lua.exe**. However, after I packaged the noscript and added it as a mod to the game, the Script Extender threw an error:
Loading bootstrap noscript: Mods/SteelSeriesLights/ScriptExtender/Lua/BootstrapServer.lua
bg3se::ExtensionStateBase::LuaLoadGameFile(): Script file could not be opened: Mods/SteelSeriesLights/ScriptExtender/Lua/socket.http
bg3se::lua::State::LoadScript(): Failed to execute noscript: [string "SteelSeriesLights/Server/lights.lua"]:4: attempt to index a nil value (local 'http')
stack traceback:
SteelSeriesLights/Server/lights.lua:4: in main chunk
[C++ Code]: in field 'Include'
builtin://Libs/FileLoader.lua:34: in function <builtin://Libs/FileLoader.lua:6>
(...tail calls...)
SteelSeriesLights/BootstrapServer.lua:1: in main chunk
[C++ Code]: in field 'Include'
builtin://Libs/ModLoader.lua:68: in method 'LoadBootstrap'
builtin://BuiltinLibrary.lua:26: in function <builtin://BuiltinLibrary.lua:25>
From what I can understand, it is interpreting `local http = require("socket.http")` expression as a module file that I created next to my main noscript. To get around this, I checked if I could just put the whole [socket.http code](https://github.com/lunarmodules/luasocket/blob/master/src/http.lua) within the noscript itself, but it also seems to have other dependencies.
Coming from a JavaScript background, I expected to be able to call a method like **fetch** that is built-in to the language, but so far I failed to accomplish my task.
If you could direct me toward any documentation or topic about Lua that might help me understand how to make it work, I would highly appreciate it\^\^
https://redd.it/1h52czt
@r_lua
How do i include a function from another lua?
I mean i know how to include a lua
But how do i use the functions of that lua?
like
local importantthing = require("importantthing")
How do i call a function from it?
https://redd.it/1h5mbkm
@r_lua
I mean i know how to include a lua
But how do i use the functions of that lua?
like
local importantthing = require("importantthing")
How do i call a function from it?
https://redd.it/1h5mbkm
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
AoC Lua Template
Hey all, not sure if anyone here is doing Advent of Code, but I created a lua template that some of you may find helpful: https://github.com/lcpichette/aoc-lua-template
Good luck, and happy holidays to all
https://redd.it/1h5y7w5
@r_lua
Hey all, not sure if anyone here is doing Advent of Code, but I created a lua template that some of you may find helpful: https://github.com/lcpichette/aoc-lua-template
Good luck, and happy holidays to all
https://redd.it/1h5y7w5
@r_lua
GitHub
GitHub - lcpichette/aoc-lua-template
Contribute to lcpichette/aoc-lua-template development by creating an account on GitHub.
FiveM Lua Help
Hello,
So basically purchased a FiveM noscript for esx and went to ask the creator for help on making the reward black money or dirty money instead of cash and he basically told me to screwoff. Kind of ignorant for such a small request BUT I do need some help on this code so that I am able to have it give players black money instead of clean money. Thanks in advance and for your time.
The code is as follows:
RegisterServerEvent('sh-boomerphone:sellItem', function(itemName, count, price)
local src = source
if framework == 'esx' then
local xPlayer = ESX.GetPlayerFromId(src);
if not xPlayer then return false end
if xPlayer.getInventoryItem(itemName)?.count >= count then
xPlayer.removeInventoryItem(itemName, count)
xPlayer.addMoney(price * count)
end
https://redd.it/1h5y70l
@r_lua
Hello,
So basically purchased a FiveM noscript for esx and went to ask the creator for help on making the reward black money or dirty money instead of cash and he basically told me to screwoff. Kind of ignorant for such a small request BUT I do need some help on this code so that I am able to have it give players black money instead of clean money. Thanks in advance and for your time.
The code is as follows:
RegisterServerEvent('sh-boomerphone:sellItem', function(itemName, count, price)
local src = source
if framework == 'esx' then
local xPlayer = ESX.GetPlayerFromId(src);
if not xPlayer then return false end
if xPlayer.getInventoryItem(itemName)?.count >= count then
xPlayer.removeInventoryItem(itemName, count)
xPlayer.addMoney(price * count)
end
https://redd.it/1h5y70l
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
How to learn to make a Lanczos/Magic Kernel GIF downscaler in Lua?
I already wrote a decoder that gets all the frames’ pixel color data
https://redd.it/1h61hqz
@r_lua
I already wrote a decoder that gets all the frames’ pixel color data
https://redd.it/1h61hqz
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
GitHub - james2doyle/raylib-luajit-generated: An attempt at Raylib LuaJit bindings that are generated from the raylib-parser API docs
https://github.com/james2doyle/raylib-luajit-generated
https://redd.it/1h6mi3v
@r_lua
https://github.com/james2doyle/raylib-luajit-generated
https://redd.it/1h6mi3v
@r_lua
GitHub
GitHub - james2doyle/raylib-luajit-generated: An attempt at Raylib LuaJit bindings that are generated from the raylib-parser API…
An attempt at Raylib LuaJit bindings that are generated from the raylib-parser API docs - james2doyle/raylib-luajit-generated
Why do people still use lua?
Luau outclasses any form of lua out currently with much nicer source code and overall better features + native makes it as fast as gcc c++ so why do people use this irrelevant language?
https://redd.it/1h6zrmf
@r_lua
Luau outclasses any form of lua out currently with much nicer source code and overall better features + native makes it as fast as gcc c++ so why do people use this irrelevant language?
https://redd.it/1h6zrmf
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
where do you learn lua for noscripting in games like roblox?
as the noscript says i wanna learn lua but idk how i should go about it or where i would learn it from
https://redd.it/1h7lt41
@r_lua
as the noscript says i wanna learn lua but idk how i should go about it or where i would learn it from
https://redd.it/1h7lt41
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
I am a roblox client or local sided developer and I want to make a client sided path finding service for a sword fighting ai that already has the moving part and attacking now I just wanted to add path finding so it's better any help?
So I've been working on a sword fighting bot on the client and I need some help read the noscript to see what I need help with.
https://redd.it/1h7r12l
@r_lua
So I've been working on a sword fighting bot on the client and I need some help read the noscript to see what I need help with.
https://redd.it/1h7r12l
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Lua Help
I dont know how to use lua and i want to learn, but there are no websites to learn lua
https://redd.it/1h7vbr7
@r_lua
I dont know how to use lua and i want to learn, but there are no websites to learn lua
https://redd.it/1h7vbr7
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Hercules - A Lua Obfuscator
Hercules is a Lua Obfuscator ive been working on for a bit, as a fun project. I was looking for people to review it, and give me some constructive criticism on what I can do better. Ive linked the GitHub Repository below.
https://github.com/zeusssz/hercules-obfuscator
https://redd.it/1h8561m
@r_lua
Hercules is a Lua Obfuscator ive been working on for a bit, as a fun project. I was looking for people to review it, and give me some constructive criticism on what I can do better. Ive linked the GitHub Repository below.
https://github.com/zeusssz/hercules-obfuscator
https://redd.it/1h8561m
@r_lua
GitHub
GitHub - zeusssz/hercules-obfuscator: A powerful Lua obfuscator designed to make your Lua code nearly impossible to reverse-engineer…
A powerful Lua obfuscator designed to make your Lua code nearly impossible to reverse-engineer, with multiple layers of advanced obfuscation techniques - zeusssz/hercules-obfuscator
Key swapping Lua Scripts for 9 keys (PRTSC - PGDN)
Key swapping Lua Scripts for 9 keys (PRTSC - PGDN) to be NumPad keys (1 - 9) instead.
don't think I ever use these keys unless for something very specific but it can change back with another profile.
Is there anyone who can write this seeing as I have no clue to write noscripts at all. Thanks in advance.
https://redd.it/1h8d9dg
@r_lua
Key swapping Lua Scripts for 9 keys (PRTSC - PGDN) to be NumPad keys (1 - 9) instead.
don't think I ever use these keys unless for something very specific but it can change back with another profile.
Is there anyone who can write this seeing as I have no clue to write noscripts at all. Thanks in advance.
https://redd.it/1h8d9dg
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
I can't get this example code from Logitech G HUB Lua API to run
function OnEvent(event, arg)
if (event == "M_PRESSED" and arg == 1 ) then
--M1 has been pressed
end
end
In the console it says loaded
https://redd.it/1h8jzsd
@r_lua
function OnEvent(event, arg)
if (event == "M_PRESSED" and arg == 1 ) then
--M1 has been pressed
end
end
In the console it says loaded
https://redd.it/1h8jzsd
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
I wanna start coding LUA, where do I start?
I wanna try to make video games!
https://redd.it/1h8msg0
@r_lua
I wanna try to make video games!
https://redd.it/1h8msg0
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
I'm new at noscripting | need help to fix
My Goal: When the Player touches the Part, then BrickColor should change into Red, but in the output is that: BrickColor is not a valid member of Model "Workspace.gy23" - Server - Script:5
and here is the code :
local GS = noscript.Parent
function Playerhit(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
Hit.Parent.BrickColor = "Red"
end
end
GS.Touched:Connect(Playerhit)
Pls help me to fix this code
https://redd.it/1h8rwzw
@r_lua
My Goal: When the Player touches the Part, then BrickColor should change into Red, but in the output is that: BrickColor is not a valid member of Model "Workspace.gy23" - Server - Script:5
and here is the code :
local GS = noscript.Parent
function Playerhit(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
Hit.Parent.BrickColor = "Red"
end
end
GS.Touched:Connect(Playerhit)
Pls help me to fix this code
https://redd.it/1h8rwzw
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Is there a way to use a function this way?
My case is very specific:
The api i use doesnt have a native checkbox, slider etc(gui) so i made one on my own, i ran out of locals to use
Is there any way to something like
if Controls"Something" then
otherlua.function
end
Seeing as my noscript on the other lua runs all the time? Is there any way to like call the entire noscript?
https://redd.it/1h926cb
@r_lua
My case is very specific:
The api i use doesnt have a native checkbox, slider etc(gui) so i made one on my own, i ran out of locals to use
Checkbox("Name", "Something", x, y)Is there any way to something like
if Controls"Something" then
otherlua.function
end
Seeing as my noscript on the other lua runs all the time? Is there any way to like call the entire noscript?
https://redd.it/1h926cb
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Learn Lua with EdgeTX api environment
Hi, I want to practice Lua writing EdgeTX noscripts for FPV drone telemetry. I have found a pretty decent documentation for edge tx and Lua . In order to acomplish my task I need to establish a communication with flight controller on my drone wich has betaflight firmware (see MSP communication) . There is a nice lua noscript for communication with betaflight (see here) but for me it is hard to understand how it comminicates with betaflight on byte level. Do you have any small easy to understand examples to dive into it ? Thank you
https://redd.it/1h94jfn
@r_lua
Hi, I want to practice Lua writing EdgeTX noscripts for FPV drone telemetry. I have found a pretty decent documentation for edge tx and Lua . In order to acomplish my task I need to establish a communication with flight controller on my drone wich has betaflight firmware (see MSP communication) . There is a nice lua noscript for communication with betaflight (see here) but for me it is hard to understand how it comminicates with betaflight on byte level. Do you have any small easy to understand examples to dive into it ? Thank you
https://redd.it/1h94jfn
@r_lua
luadoc.edgetx.org
EdgeTX LUA Reference Guide | LUA Reference Guide
I just created blood son of brainfuck and lua
https://github.com/karasaikinsin/Symbolic
https://redd.it/1h95h6k
@r_lua
https://github.com/karasaikinsin/Symbolic
https://redd.it/1h95h6k
@r_lua
GitHub
GitHub - karasaikinsin/Symbolic: Symbolic - program language based on lua. His distinguishing feature is no english/latin simbols…
Symbolic - program language based on lua. His distinguishing feature is no english/latin simbols only nums and other symbols - karasaikinsin/Symbolic
Is there a good way of generating 2D graphics without a game engine?
I want to create something like desmos but only for simple functions (ax\^2 + bx + c). I have created the function that finds the y values for many given x values so the function can be drawn. This is where I have encountered a problem, I don’t know how to generate such graphics. I have tried searching for something but all I found was game engine tutorials that incorporate Lua and not methods of displaying graphics without an engine, as for my application, I find it unnecessary.
https://redd.it/1h9omsv
@r_lua
I want to create something like desmos but only for simple functions (ax\^2 + bx + c). I have created the function that finds the y values for many given x values so the function can be drawn. This is where I have encountered a problem, I don’t know how to generate such graphics. I have tried searching for something but all I found was game engine tutorials that incorporate Lua and not methods of displaying graphics without an engine, as for my application, I find it unnecessary.
https://redd.it/1h9omsv
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Getting error info from custom error handler and xpcall
I’m using xpcall and want to know how to get error info from a custom error handler function.
If I use
I lose the error message itself but I get the trace.
If I use
I get the error message and the trace when I print err.
https://redd.it/1haee9w
@r_lua
I’m using xpcall and want to know how to get error info from a custom error handler function.
Function error_handler()
Print(debug.traceback)
EndIf I use
err, ok = xpcall(func, error_handler) I lose the error message itself but I get the trace.
If I use
err, ok = xpcall(func, debug.traceback)I get the error message and the trace when I print err.
https://redd.it/1haee9w
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community