This is the place for discussion and support for LunaLua and related modifications and libraries.
Moderator: Userbase Moderators
Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
|
|
|
|
-
Gaming-Dojo
- Monty Mole

- Posts: 124
- Joined: Mon Jan 25, 2016 9:20 am
- Pronouns: he/him
-
Contact:
Postby Gaming-Dojo » Tue Jun 06, 2017 8:15 am
Hi Guys.
As someone made a boomerang script that works according to his own statement only for Mario, I decided to modify it to make it work for all players which was pretty easy for Mario and Luigi and not necessary for Toad who already has the boomerang by default.For Peach, however, the code doesn't work but doesn't produce an error so the syntax isn't the problem.That's the code I've produced so far:
Code: Select all local BoomerangLock = 0
function onTick()
if player.powerup == PLAYER_HAMMER then
if BoomerangLock == 0 then
if(player.runKeyPressing) then
for k,v in pairs(NPC.get(171,-1)) do
v.id = 292
v.width = 32
v.height = 32
v:mem(0x110,FIELD_DFLOAT,1)
if BoomerangLock == 0 then
if player:mem(0x106,FIELD_WORD) ~= -1 then
BoomerangLock = 0
v.x = v.x + 2
v.speedX = 25
v.speedY = -10
else
v.x = v.x - 2
v.speedX = -25
v.speedY = -10
BoomerangLock = 0
end
else
local BoomerangCheck = NPC.get(292,-1)
if table.getn(BoomerangCheck) == 0 then
BoomerangLock = 0
else
player:mem(0x160,FIELD_WORD,2)
function onTick()
if player.character == CHARACTER_PEACH then
for _, n in pairs(NPC.get(291, -1)) do --for all PlayerBombs in all sections
n.id = 292 --turn PlayerBombs into boomerangs
n.height = 32
n.width = 32
end
end
end
end
end
end
end
end
end
end
So if you have an idea of why this code doessn't function, please help me.
Thanks in advance, yoshiegg
|
|
|
|
|
|
|
|
|
-
The0x539
- Eerie

- Posts: 751
- Joined: Fri Jan 22, 2016 8:02 pm
Postby The0x539 » Tue Jun 06, 2017 9:25 am
That's...uh...
Not how you use ends.
This is how your code gets interpreted:
Code: Select all local BoomerangLock = 0
function onTick()
if player.powerup == PLAYER_HAMMER then
if BoomerangLock == 0 then
if(player.runKeyPressing) then
for k,v in pairs(NPC.get(171,-1)) do
v.id = 292
v.width = 32
v.height = 32
v:mem(0x110,FIELD_DFLOAT,1)
if BoomerangLock == 0 then
if player:mem(0x106,FIELD_WORD) ~= -1 then
BoomerangLock = 0
v.x = v.x + 2
v.speedX = 25
v.speedY = -10
else
v.x = v.x - 2
v.speedX = -25
v.speedY = -10
BoomerangLock = 0
end
else
local BoomerangCheck = NPC.get(292,-1)
if table.getn(BoomerangCheck) == 0 then
BoomerangLock = 0
else
player:mem(0x160,FIELD_WORD,2)
function onTick()
if player.character == CHARACTER_PEACH then
for _, n in pairs(NPC.get(291, -1)) do --for all PlayerBombs in all sections
n.id = 292 --turn PlayerBombs into boomerangs
n.height = 32
n.width = 32
end
end
end
end
end
end
end
end
end
end
Besides the weird scoping, you're redefining onTick. Stick all the code into a single definition of the event or it won't work the way I imagine you're expecting it to.
|
|
|
|
|
|
|
|
|
-
Gaming-Dojo
- Monty Mole

- Posts: 124
- Joined: Mon Jan 25, 2016 9:20 am
- Pronouns: he/him
-
Contact:
Postby Gaming-Dojo » Tue Jun 06, 2017 4:23 pm
Like how?
Bc leaving out the second function on tick () has no effect and connecting the two for k,v in pairs with an and throws an unexpected symbol near and error.So I have no idea what you mean.
|
|
|
|
|
|
|
|
|
-
The0x539
- Eerie

- Posts: 751
- Joined: Fri Jan 22, 2016 8:02 pm
Postby The0x539 » Tue Jun 06, 2017 5:06 pm
yoshiegg wrote:Bc leaving out the second function on tick () has no effect
Nonono, put the code from the second one into the first one.
yoshiegg wrote:connecting the two for k,v in pairs with an and

|
|
|
|
|
|
|
|
|
-
Gaming-Dojo
- Monty Mole

- Posts: 124
- Joined: Mon Jan 25, 2016 9:20 am
- Pronouns: he/him
-
Contact:
Postby Gaming-Dojo » Wed Jun 07, 2017 7:13 am
So now I've tried to follow your advice and updated my code to this:
Code: Select all local BoomerangLock = 0
function onLoop()
if player.powerup == PLAYER_HAMMER then
if BoomerangLock == 0 then
if(player.runKeyPressing) then
for k,v in pairs(NPC.get(171,-1)) do
v.id = 292
v.width = 32
v.height = 32
v:mem(0x110,FIELD_DFLOAT,1)
if player.character == CHARACTER_PEACH then
for _, n in pairs(NPC.get(291, -1)) do --for all PlayerBombs in all sections
n.id = 292 --turn PlayerBombs into boomerangs
n.height = 32
n.width = 32
n:mem(0x110,FIELD_DFLOAT,1)
if BoomerangLock == 0 then
if player:mem(0x106,FIELD_WORD) ~= -1 then
BoomerangLock = 0
v.x = v.x + 2
v.speedX = 25
v.speedY = -10
else
v.x = v.x - 2
v.speedX = -25
v.speedY = -10
BoomerangLock = 0
end
else
local BoomerangCheck = NPC.get(292,-1)
if table.getn(BoomerangCheck) == 0 then
BoomerangLock = 0
else
player:mem(0x160,FIELD_WORD,2)
end
end
end
end
end
end
end
end
end
However, Peach still throws bombs.So please tell me: am I on the right track as I put the code from my second function into the first imo.
|
|
|
|
|
|
|
|
|
-
The0x539
- Eerie

- Posts: 751
- Joined: Fri Jan 22, 2016 8:02 pm
Postby The0x539 » Wed Jun 07, 2017 7:49 am
Why are you running the Peach-specific code for each existing hammer? Why are your ends still placed at the end of the file, rather than at the end of the scope they're meant to close? Why did you switch to onLoop?
|
|
|
|
|
|
|
|
|
-
Gaming-Dojo
- Monty Mole

- Posts: 124
- Joined: Mon Jan 25, 2016 9:20 am
- Pronouns: he/him
-
Contact:
Postby Gaming-Dojo » Wed Jun 07, 2017 10:33 am
On Loop: I had something from snorunt pyros tutorials in mind that on loop would be best to use.
Scopes: Oh, now I know what you meant.thank you.
Edit: Now I tried to find out when each function and if-statement has to be closed and tried to fix my scopes like that.As I just modified the code and it also had the ends placed at the ensd of the file I'm not sure if everything's right so it would be nice if you could tell me that.
And that's my code by now:
Code: Select all local BoomerangLock = 0
function Tick()
if player.powerup == PLAYER_HAMMER then
if BoomerangLock == 0 then
if(player.runKeyPressing) then
for k,v in pairs(NPC.get(171,-1)) do
v.id = 292
v.width = 32
v.height = 32
v:mem(0x110,FIELD_DFLOAT,1)
end
end
end
if player.character == CHARACTER_PEACH then
for _, n in pairs(NPC.get(291, -1)) do --for all PlayerBombs in all sections
n.id = 292 --turn PlayerBombs into boomerangs
n.height = 32
n.width = 32
n:mem(0x110,FIELD_DFLOAT,1)
end
if BoomerangLock == 0 then
if player:mem(0x106,FIELD_WORD) ~= -1 then
BoomerangLock = 0
v.x = v.x + 2
v.speedX = 25
v.speedY = -10
end
else
v.x = v.x - 2
v.speedX = -25
v.speedY = -10
BoomerangLock = 0
end
end
else
local BoomerangCheck = NPC.get(292,-1)
if table.getn(BoomerangCheck) == 0 then
BoomerangLock = 0
else
player:mem(0x160,FIELD_WORD,2)
end
end
Last edited by Gaming-Dojo on Wed Jun 07, 2017 11:35 am, edited 1 time in total.
|
|
|
|
|
|
|
|
|
-
The0x539
- Eerie

- Posts: 751
- Joined: Fri Jan 22, 2016 8:02 pm
Postby The0x539 » Wed Jun 07, 2017 10:58 am
yoshiegg wrote:On Loop: I had something from snorunt pyros tutorials in mind that on loop would be best to use.
Nope, the tutorial's just old.
|
|
|
|
|
|
|
|
|
-
Gaming-Dojo
- Monty Mole

- Posts: 124
- Joined: Mon Jan 25, 2016 9:20 am
- Pronouns: he/him
-
Contact:
Postby Gaming-Dojo » Wed Jun 07, 2017 2:43 pm
Thanks for the help.Now my code works and I was even able to make a boomerang Link script with very few effort.
For everyone interested I'll release all 3 APIs in a seperate topic the next days.
|
|
|
|
|
|
|
|
|
-
TDK
- Phanto

- Posts: 1440
- Joined: Wed Nov 11, 2015 12:26 pm
- Flair: Retired
Postby TDK » Wed Jun 07, 2017 2:44 pm
yoshiegg wrote:Thanks for the help.Now my code works and I was even able to make a boomerang Link script with very few effort.
For everyone interested I'll release all 3 APIs in a seperate topic the next days.
What's the other 2 for?
|
|
|
|
|
|
|
|
|
-
Gaming-Dojo
- Monty Mole

- Posts: 124
- Joined: Mon Jan 25, 2016 9:20 am
- Pronouns: he/him
-
Contact:
Postby Gaming-Dojo » Wed Jun 07, 2017 2:54 pm
One for Mario and Luigi, one for Peach and one for Link.I decided to make seperate APIs as I want to keep the lunaworld.lua file of the episode short and clean and because my code didn't work several times when I had the code of the Bros and the one for Peach together in my lunaworld so I thought having them all in one api wouldn't work either.
The Boomerang Script can be used to replace fire- and iceballs easily as well.Just change the id in the for k,v in pairs:NPC.get(171,-1) to the id of the fire- or iceballs.
|
|
|
|
|
|
|
|
|
-
PixelPest
- Link

- Posts: 7111
- Joined: Sun Jul 12, 2015 5:38 pm
- Flair: Tamer of Boom Booms
-
Contact:
Postby PixelPest » Wed Jun 07, 2017 6:16 pm
That's a really bad idea. Release it as one
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Phanto

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Thu Jun 08, 2017 2:39 am
yoshiegg wrote:
The Boomerang Script can be used to replace fire- and iceballs easily as well.Just change the id in the for k,v in pairs:NPC.get(171,-1) to the id of the fire- or iceballs.
Could you not just use a table of IDs to replace, rather than making 3 basically identical APIs?
Honestly, making multiple copies of extremely similar code is a terrible idea. You could always check the player's character before running certain sections of it, but keep it as one file.
|
|
|
|
|
|
|
|
|
-
Gaming-Dojo
- Monty Mole

- Posts: 124
- Joined: Mon Jan 25, 2016 9:20 am
- Pronouns: he/him
-
Contact:
Postby Gaming-Dojo » Thu Jun 08, 2017 5:51 am
Afaik, replacing multiple ids isn't possible with the npc.get that I use and sadly, I really am no expert when it get's to dealing with tables at all.But if you could give me a simple hint that would be nice.
Btw, by your comments, I realized that realizing thiss first version that I just finished yesterday isn't the best plan.Rather I should try to simplify the code and get it into one api.Over that, Link's code still spawns the default npc for some time before it turns into the boomerang even though I use onTickEnd like you recommended in another topic which fixed that issue for the other players.
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Phanto

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Thu Jun 08, 2017 7:08 am
Absolutely you can use more than one ID. I don't know where you got the notion that you can't. Just include a tablr of IDs instead of a single one.
|
|
|
|
|
|
|
|
|
-
timocomsmbx2345
- Foo

- Posts: 853
- Joined: Sat Feb 06, 2016 1:44 pm
-
Contact:
Postby timocomsmbx2345 » Thu Jun 08, 2017 8:43 am
PixelPest wrote:That's a really bad idea. Release it as one
do you mean release it at once?
|
|
|
|
|
|
|
|
|
-
Mable
- Luigi

- Posts: 5806
- Joined: Sat Dec 21, 2013 4:23 am
-
Contact:
Postby Mable » Thu Jun 08, 2017 8:53 am
timocomsmbx2345 wrote:PixelPest wrote:That's a really bad idea. Release it as one
do you mean release it at once?
I think Pixelpest meant to release it as one api for all chars and not a single one for every char.
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9877
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Thu Jun 08, 2017 8:53 am
timocomsmbx2345 wrote:PixelPest wrote:That's a really bad idea. Release it as one
do you mean release it at once?
Given the context being that he put it into three instead of one api,
no.
|
|
|
|
|
|
|
|
|
-
Gaming-Dojo
- Monty Mole

- Posts: 124
- Joined: Mon Jan 25, 2016 9:20 am
- Pronouns: he/him
-
Contact:
Postby Gaming-Dojo » Thu Jun 08, 2017 1:24 pm
Update: I now put it into one api and it works mostly fine:
Mario, Luigi and Link always throw their boomerangs as they should.Peach however stops throwing boomerangs and changes them for bombs when I collect another hammer suit in another section.(If I collect one in the section I started in, I don't know what happens as I haven't tested this yet.
Here's my newest code: Code: Select all local boomerang = {}
local BoomerangLock = 0
function boomerang.onInitAPI()
registerEvent(boomerang, "onTickEnd", "onTickEnd", false)
end
function boomerang.onTickEnd()
if player.powerup == PLAYER_HAMMER then
if BoomerangLock == 0 then
if(player.runKeyPressing) then
for k,v in pairs(NPC.get({170,266,291},-1)) do
v.id = 292
v.width = 32
v.height = 32
v:mem(0x110,FIELD_DFLOAT,1)
if BoomerangLock == 0 then
if player:mem(0x106,FIELD_WORD) ~= -1 then
BoomerangLock = 1
v.x = v.x + 2
v.speedX = 25
v.speedY = -10
else
v.x = v.x - 2
v.speedX = -25
v.speedY = -10
BoomerangLock = 1
end
end
end
end
else
local BoomerangCheck = NPC.get(292,-1)
if table.getn(BoomerangCheck) == 0 then
BoomerangLock = 0
else
player:mem(0x160,FIELD_WORD,2)
end
end
end
end
return boomerang
So does anyone of you know, why a hammer suit powerup being collected keeps Peach from throwing boomerangs?
And thanks for the hint, Hoe.Setting more ids is easy with these brackets {}.
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Phanto

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Thu Jun 08, 2017 2:11 pm
yoshiegg wrote:Update: I now put it into one api and it works mostly fine:
I would recommend using npc:transform(newid); rather than npc.id = newid;. The transform function deals with the width and height issues, as well as other potential problems that occur from just setting the id directly.
As for why Peach bombs don't work, I'm not sure.
|
|
|
|
|
Return to “LunaLua”
Users browsing this forum: No registered users and 0 guests
|