Need help with any SMBX game-related issues? Ask your questions here.
Moderator: Userbase Moderators
|
|
|
|
-
dragon3025
- Bot

- Posts: 55
- Joined: Fri Aug 07, 2015 5:02 pm
Postby dragon3025 » Tue Aug 16, 2016 7:17 pm
I only need it to effect a single level in my episode. So do I place the healthpoint.lua file in my level folder, then make a lunadll.lua file in the same level folder, then in the lunadll.lua file I put in:
|
|
|
|
|
|
|
|
|
-
dragon3025
- Bot

- Posts: 55
- Joined: Fri Aug 07, 2015 5:02 pm
Postby dragon3025 » Tue Aug 16, 2016 7:32 pm
It didn't work, so I must be doing it wrong. I kept the healthpoint.lua in the level folder (that's still needed right?).
I changed the code lunadll.lua to:
Code: Select all API.load(healthpoint.lua)
HealthPoint.setNPCDamage(168, 1, 1)
HealthPoint.setNPCDamage(168, 4, 0)
HealthPoint.setNPCHealth(168, 5)
For API.load("healthpoint") I tried it with and without qoutation marks and with and without .lua at the end.
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9891
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Tue Aug 16, 2016 7:37 pm
oh my bad you need to do
local HealthPoint = API.load("healthpoint")
unsure about the capital letters in the quotation mark.
|
|
|
|
|
|
|
|
|
-
dragon3025
- Bot

- Posts: 55
- Joined: Fri Aug 07, 2015 5:02 pm
Postby dragon3025 » Tue Aug 16, 2016 8:25 pm
Enjl wrote:oh my bad you need to do
local HealthPoint = API.load("healthpoint")
unsure about the capital letters in the quotation mark.
That didn't work either. I also tried following this link: http://www.smbxgame.com/forums/v ... 69&t=12546 and doing the same way:
Code: Select all local HealthPoint = loadAPI("healthpoint")
HealthPoint.setNPCDamage(168, 1, 1)
HealthPoint.setNPCDamage(168, 4, 0)
HealthPoint.setNPCHealth(168, 5)
But that didn't work either
|
|
|
|
|
|
|
|
|
-
PixelPest
- Link

- Posts: 7111
- Joined: Sun Jul 12, 2015 5:38 pm
- Flair: Tamer of Boom Booms
-
Contact:
Postby PixelPest » Tue Aug 16, 2016 8:35 pm
You'll want to use API.load() and make sure that the capitalization of healthcount (in the string) matches that of your file
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9891
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Tue Aug 16, 2016 8:40 pm
what error is it giving you? Make sure your file is called lunadll.lua, not lunadll.lua.txt. Also make sure your .lvl is one folder above the lunadll.lua.
|
|
|
|
|
|
|
|
|
-
dragon3025
- Bot

- Posts: 55
- Joined: Fri Aug 07, 2015 5:02 pm
Postby dragon3025 » Tue Aug 16, 2016 8:55 pm
Enjl wrote:what error is it giving you? Make sure your file is called lunadll.lua, not lunadll.lua.txt. Also make sure your .lvl is one folder above the lunadll.lua.
Okay so I have it set up this way:
Code: Select all local HealthPoint = API.load("healthpoint")
HealthPoint.setNPCDamage(168, 1, 1)
HealthPoint.setNPCDamage(168, 4, 0)
HealthPoint.setNPCHealth(168, 5)
and I checked and it matches the capitalization, and all of the files lua files and not txt files. I'm not sure where to place the files, I have a both of the files inside: SMBX 2.0 Open Beta-Release 2\worlds\sandbox\test (they're both in the level folder and not the world folder). The test.lvl file is in the world folder.
I got this error:
...2.0 Open Beta-Release 2\worlds\sandbox\test\lunadll.lua:1 attempt to index
global 'API' (a nil value)
|
|
|
|
|
|
|
|
|
-
underFlo
- Wart

- Posts: 4456
- Joined: Mon Jul 14, 2014 10:44 am
- Flair: sup im lesbiab
- Pronouns: They/She
-
Contact:
Postby underFlo » Tue Aug 16, 2016 9:00 pm
Your LunaLua is outdated.
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9891
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Tue Aug 16, 2016 9:01 pm
your lunalua is outdated. Try loadSharedAPI because updating 2.0's lua is a pain and not worth it with the next beta coming soon
|
|
|
|
|
|
|
|
|
-
underFlo
- Wart

- Posts: 4456
- Joined: Mon Jul 14, 2014 10:44 am
- Flair: sup im lesbiab
- Pronouns: They/She
-
Contact:
Postby underFlo » Tue Aug 16, 2016 9:11 pm
Enjl wrote:your lunalua is outdated. Try loadSharedAPI because updating 2.0's lua is a pain and not worth it with the next beta coming soon
Oh right, forgot that method existed.
|
|
|
|
|
|
|
|
|
-
dragon3025
- Bot

- Posts: 55
- Joined: Fri Aug 07, 2015 5:02 pm
Postby dragon3025 » Tue Aug 16, 2016 9:23 pm
Enjl wrote:your lunalua is outdated. Try loadSharedAPI because updating 2.0's lua is a pain and not worth it with the next beta coming soon
Dang, I can't wait for the next beta then.
Well that almost worked. The hammers aren't hurting it, but jumping on it doesn't. It is the bully npc, so I'm sure that's why. I tried switching the ID to the ID of hammer bro, then I tested on a hammer bro and it worked completely (hammers didn't hurt it and it takes 5 jumps to kill it). I was actually making a Chargin chuck out of Bully and I gave it this npc-168.txt:
Code: Select all width=52
height=54
gfxwidth=52
gfxheight=54
frames=2
framestyle=1
framespeed=2
score=5
noyoshi=1
Either using lunalua or the npc txt file, I need to make it so jumping on chargin chuck damages it. I though that this part in my lunadll.lua would work, but it didn't since jumping does kill it:
Code: Select all HealthPoint.setNPCDamage(29, 1, 1)
EDIT: I just discovered other enemies now are taking more jumps to kill.
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9891
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Tue Aug 16, 2016 9:40 pm
Healthpoint is weird. It automatically gives properties to all NPCs. There's an onNPCKill event in lunalua which allows you to hook right into what happens BEFORE an npc dies and even cancel the death. I suggest looking into that, in conjunction with pnpc.lua to save npc-specific variables for HP
|
|
|
|
|
|
|
|
|
-
dragon3025
- Bot

- Posts: 55
- Joined: Fri Aug 07, 2015 5:02 pm
Postby dragon3025 » Tue Aug 16, 2016 10:21 pm
Enjl wrote:Healthpoint is weird. It automatically gives properties to all NPCs. There's an onNPCKill event in lunalua which allows you to hook right into what happens BEFORE an npc dies and even cancel the death. I suggest looking into that, in conjunction with pnpc.lua to save npc-specific variables for HP
So I'm creating a new variable for the npc which goes down every time I hit it, and if it hasn't reached 0, then I cancel the death?
I got this so far:
Code: Select all function onNPCKill(killObj, killedNPC, killReason)
if killedNPC.id == 168
if killReason == 3 then --Here's where'd I'd also test if the custom variable equals 0.
--Variable goes down by one here
else
Event.cancelled --Am I canceling the event correctly?
end
end
I looked through all the functions in pnpc and I can't tell which function allows me to give it a variable. I'm also not sure if my code cancels the event correctly.
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9891
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Wed Aug 17, 2016 4:33 am
You're missing a "then" in the ID check.
To cancel the event, use killObj.cancelled=true
Make sure to also allow death by reason 9 if you want despawning to be possible.
Alright onto pnpc.
Pnpc is an api which lets you wrap a specific npc object with
local w (or whatever you want it to be) = pnpc.wrap(npcObj) (in your case, killedNPC.
If the wrapper doesn't exist yet, it'll be initialised. If it exists, it will be returned.
w can access everything a npc can, but also has access to a few more things, most notable, pnpcObj.data
w.data is an empty table and this is where you can initialise your hp and keep track of it by creating a new variable in this table.
Sorry for the kinda hacky explanation. I'm a bit in a hurry >.< Hope that clears it up for you.
|
|
|
|
|
|
|
|
|
-
dragon3025
- Bot

- Posts: 55
- Joined: Fri Aug 07, 2015 5:02 pm
Postby dragon3025 » Wed Aug 17, 2016 4:29 pm
Enjl wrote:You're missing a "then" in the ID check.
To cancel the event, use killObj.cancelled=true
Make sure to also allow death by reason 9 if you want despawning to be possible.
Alright onto pnpc.
Pnpc is an api which lets you wrap a specific npc object with
local w (or whatever you want it to be) = pnpc.wrap(npcObj) (in your case, killedNPC.
If the wrapper doesn't exist yet, it'll be initialised. If it exists, it will be returned.
w can access everything a npc can, but also has access to a few more things, most notable, pnpcObj.data
w.data is an empty table and this is where you can initialise your hp and keep track of it by creating a new variable in this table.
Sorry for the kinda hacky explanation. I'm a bit in a hurry >.< Hope that clears it up for you.
Here's my code:
Code: Select all local w = pnpc.wrap(npcObj)
function onNPCKill(killObj, killedNPC, killReason)
if killedNPC.id == 168 then
if killReason == 9 then
if w < 2 then
w = w + 1
else
killObj.cancelled=true
end
end
end
end
I wasn't sure if you meant I should put pnpc.wrap(npcObj) or pnpc.wrap(killedNPC), so I tried them both, but both times I got this error:
2.0 Open Beta-Release 2\worlds\sandbox\test\lunadll.lua:1: attempt to index
global 'pnpc' (a nil value)
Also it looks like I'm initializing the variable w, do I put a w = 0 after that line to give it a value?
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9891
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Wed Aug 17, 2016 5:06 pm
pnpc is an API, just like healthPoint. You load it with
Code: Select all local pnpc = loadSharedAPI("pnpc")
Afterward you can wrap your NPC object (killedNPC) into a pnpc object with
w has all properties of killedNPC. There's w.x, w.height and you can also set memory offsets of the npc with w:mem().
The reason we're using pnpc is so that we can store the HP variable for each specific enemy and keep them consistent across ticks. That's what pnpc was made for and it's super handy.
But what you're interested in is the w.data table.
You can initialise a variable with:
Code: Select all if w.data.hp == nil then
w.data.hp = 0
end
|
|
|
|
|
|
|
|
|
-
dragon3025
- Bot

- Posts: 55
- Joined: Fri Aug 07, 2015 5:02 pm
Postby dragon3025 » Wed Aug 17, 2016 5:30 pm
Enjl wrote:pnpc is an API, just like healthPoint. You load it with
Code: Select all local pnpc = loadSharedAPI("pnpc")
Afterward you can wrap your NPC object (killedNPC) into a pnpc object with
w has all properties of killedNPC. There's w.x, w.height and you can also set memory offsets of the npc with w:mem().
The reason we're using pnpc is so that we can store the HP variable for each specific enemy and keep them consistent across ticks. That's what pnpc was made for and it's super handy.
But what you're interested in is the w.data table.
You can initialise a variable with:
Code: Select all if w.data.hp == nil then
w.data.hp = 0
end
I changed my code to:
Code: Select all local pnpc = loadSharedAPI("pnpc")
w = pnpc.wrap(killedNPC)
if w.data.hp == nil then
w.data.hp = 0
end
function onNPCKill(killObj, killedNPC, killReason)
if killedNPC.id == 168 then
if killReason == 9 then
if w.data.hp < 2 then
w.data.hp = w.data.hp + 1
else
killObj.cancelled=true
end
end
end
end
It said ...king\SMBX 2.0 Open Beta-Release 2\LuaScriptsLib\pnpc.lua:142: attempt to
index local 'npc' (a nil value)
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9891
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Wed Aug 17, 2016 5:42 pm
You have to wrap killedNPC and start doing stuff with it in a scope where it's actually defined. I suggest after the killedNPC.id check. Also I noticed that your HP only counts down on killReason 9 which is equivalent to despawn or being collected.
|
|
|
|
|
|
|
|
|
-
dragon3025
- Bot

- Posts: 55
- Joined: Fri Aug 07, 2015 5:02 pm
Postby dragon3025 » Wed Aug 17, 2016 6:32 pm
Enjl wrote:You have to wrap killedNPC and start doing stuff with it in a scope where it's actually defined. I suggest after the killedNPC.id check. Also I noticed that your HP only counts down on killReason 9 which is equivalent to despawn or being collected.
You posted eariler to make sure to also allow death by reason 9 if you want despawning to be possible. I was using 3 to make it so stomping on it 3 times kills it, did you mean use 9 along with 3? My code is now:
Code: Select all local pnpc = loadSharedAPI("pnpc")
function onNPCKill(killObj, killedNPC, killReason)
w = pnpc.wrap(killedNPC)
if w.data.hp == nil then
w.data.hp = 0
end
if killedNPC.id == 168 then
if killReason == 9 then
if w.data.hp < 2 then
w.data.hp = w.data.hp + 1
else
killObj.cancelled=true
end
end
end
end
I didn't get any errors, but I still couldn't kill it by jumping on it and hitting it with a hammer killed it in one hit.
|
|
|
|
|
Return to “Help and Support”
Users browsing this forum: No registered users and 1 guest
|