Carnaxus Posted June 27, 2018 Share Posted June 27, 2018 Hello all! I have literally never touched a LUA script before Avorion, even with more than ten years of Garry's Mod under my belt. That said, I'm trying to create a ship system upgrade that will attach the debug script to the ship it's installed on, and then will remove it when uninstalled. Due to the fact that I have never done any LUA work before, I'm hoping someone can go over my script real quick and tell me if I've horribly broken things (or not). package.path = package.path .. ";data/scripts/systems/?.lua" package.path = package.path .. ";data/scripts/lib/?.lua" require ("basesystem") require ("utility") require ("randomext") -- optimization so that energy requirement doesn't have to be read every frame FixedEnergyRequirement = true function onInstalled(seed, rarity) do Entity():addScript("lib/entitydbg.lua") end function onUninstalled(seed, rarity) do Entity():removeScript("lib/entitydbg.lua") end function getName(seed, rarity) return "Debug Script Attachment" end function getIcon(seed, rarity) return "data/textures/icons/cubeforce.png" end function getEnergy(seed, rarity) return 1 end function getPrice(seed, rarity) return 1 end function getTooltipLines(seed, rarity) local texts = {} local perc, flat = getBonuses(seed, rarity) if perc ~= 0 then table.insert(texts, {ltext = "Cargo Hold"%_t, rtext = string.format("%+i%%", perc * 100), icon = "data/textures/icons/wooden-crate.png"}) end if flat ~= 0 then table.insert(texts, {ltext = "Cargo Hold"%_t, rtext = string.format("%+i", flat), icon = "data/textures/icons/wooden-crate.png"}) end return texts end function getDescriptionLines(seed, rarity) return { {ltext = "Naughty naughty!"%_t, lcolor = ColorRGB(1, 0.5, 0.5)} } end I copied the cargoextender.lua file and modified it rather than start from scratch. Hopefully that in and of itself won't break anything... Link to comment Share on other sites More sharing options...
Laserzwei Posted June 27, 2018 Share Posted June 27, 2018 You don't need "do" in front of your additions. I also recommend using Entity():addScriptOnce("lib/entitydbg.lua") Because having multiple instances of said script has no advantages. Link to comment Share on other sites More sharing options...
Carnaxus Posted June 27, 2018 Author Share Posted June 27, 2018 Ah. Well...as expected based on your feedback, in its current incarnation, it didn't work. The upgrades generated, but they were blank, and didn't have any effect. I'll make the changes you mentioned and see if it works. Thanks! Edit: Nope, still nothing. Link to comment Share on other sites More sharing options...
Laserzwei Posted June 27, 2018 Share Posted June 27, 2018 make sure to check both client- and serverlogfiles for any errors. Since even singleplayer has a build in server. Client: %Appdata%/Roaming/Avorion/clientlog<timestamp>.txt Server: %Appdata%/Roaming/Avorion/galaxies/<YourGalaxyName>/serverlog<timestamp>.txt The functions will be called on client and server side each. And since Entity():addScript/Once() is not avaiable on the clientside, there will be something about it in the clientlog. The solution is to surround the statement with if onSever() then --code end That however is not the error you are looking for. Link to comment Share on other sites More sharing options...
DracoNB Posted June 27, 2018 Share Posted June 27, 2018 make sure to check both client- and serverlogfiles for any errors. Since even singleplayer has a build in server. Client: %Appdata%/Roaming/Avorion/clientlog<timestamp>.txt Server: %Appdata%/Roaming/Avorion/galaxies/<YourGalaxyName>/serverlog<timestamp>.txt The functions will be called on client and server side each. And since Entity():addScript/Once() is not avaiable on the clientside, there will be something about it in the clientlog. The solution is to surround the statement with if onSever() then --code end That however is not the error you are looking for. Along with that, you'll need to have it call the server script if it runs client side with the invokeServerFunction("nameOfScript") Link to comment Share on other sites More sharing options...
Carnaxus Posted June 28, 2018 Author Share Posted June 28, 2018 I'm pretty sure this is also not the error anyone was expecting: 2018-06-27 20-35-27| Error while adding file data/scripts/systems/debug.lua: 2018-06-27 20-35-27| data/scripts/systems/debug.lua:21: ')' expected near '=' I've updated the code a bit, although I'm pretty sure I put the "if onServer() then" bit in the wrong place. Anyways, here's the latest: package.path = package.path .. ";data/scripts/systems/?.lua" package.path = package.path .. ";data/scripts/lib/?.lua" require ("basesystem") require ("utility") require ("randomext") -- optimization so that energy requirement doesn't have to be read every frame FixedEnergyRequirement = true if onServer() then function onInstalled(seed, rarity) Entity():addScriptOnce("lib/entitydbg.lua") end function onUninstalled(seed, rarity) Entity():removeScript("lib/entitydbg.lua") end function getName(seed, rarity) return ( (ltext = "Debug Script Attachment") ) end function getIcon(seed, rarity) return "data/textures/icons/cubeforce.png" end function getEnergy(seed, rarity) return 1 end function getPrice(seed, rarity) return 1 end function getTooltipLines(seed, rarity) return texts end function getDescriptionLines(seed, rarity) return { {ltext = "Naughty naughty!"%_t, lcolor = ColorRGB(1, 0.5, 0.5)} } end end (of "if" statement) Link to comment Share on other sites More sharing options...
Laserzwei Posted June 28, 2018 Share Posted June 28, 2018 why did you add the unneccessary brackets "(( ))" in the getName() function? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now