Re: Need help with lua? - LunaLua General Help
Posted: Mon Jun 27, 2016 6:13 pm
I wish S1eths code was still available. Anyway, if we look past the problem that all npcs are assigned 3 health points by default by the HealthPoint API, it is also true that setNPCHealth cannot be called within the onLoop function. If you call it in the onLoad function it works well however, and healthPoint.setNPCHealth(1, 1) will make Goombas die after only one hit.S1eth wrote:It's not you. HealthPoint is bugged.Mario_and_Luigi_55 wrote:RhysOwens wrote:Has anyone forgotten about me?
I'm not really making levels with LunaLua right now.
I'm messing around with it and experimenting with it so I can get used to it.
The NPCs all take more hits even when I've set the ID to 1 NPC with HealthPoint.lua.
I have same problem.
First of all, when you load the API, it automatically sets all NPCs to 3 health. (the creator apparently thought that was a good idea...)
If you don't want that, you'd want to iterate over all NPC ids and call healthPoint.makeNPCNormal(id), but that doesn't work either.
healthPoint.makeNPCNormal is supposed to remove the entry for a specific NPC id from a table, but instead, it removes the value with the index of the npc id, and then pushes all other indexes in the table forward to fill in the gap.
It's pretty broken.
Here is a fix: http://hastebin.com/anerequxef.lua
Create a new text file inside your level folder. Copy and paste the hastebin text in there. Rename the file to HealthPoint.lua (remove the .txt extension)
Test it by having the following code in your lunadll.lua file for your level:
This makes a goomba (ID 1) take 3 hits to kill. All other enemies are unaffected.Code: Select all
local healthPoint = API.load("HealthPoint"); --healthPoint.healthbar = true; -- optional, use to activate healthbars above NPCs for _,id in pairs(healthPoint.allNPCs) do healthPoint.makeNPCNormal(id); end healthPoint.setNPCHealth(1, 3);
Hope this helps someone!