Page 1 of 2
Boomerang
Posted: Tue Jun 06, 2017 8:15 am
by Gaming-Dojo
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
Re: Boomerang
Posted: Tue Jun 06, 2017 9:25 am
by The0x539
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.
Re: Boomerang
Posted: Tue Jun 06, 2017 4:23 pm
by Gaming-Dojo
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.
Re: Boomerang
Posted: Tue Jun 06, 2017 5:06 pm
by The0x539
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

Re: Boomerang
Posted: Wed Jun 07, 2017 7:13 am
by Gaming-Dojo
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.
Re: Boomerang
Posted: Wed Jun 07, 2017 7:49 am
by The0x539
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?
Re: Boomerang
Posted: Wed Jun 07, 2017 10:33 am
by Gaming-Dojo
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
Re: Boomerang
Posted: Wed Jun 07, 2017 10:58 am
by The0x539
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.
Re: Boomerang
Posted: Wed Jun 07, 2017 2:43 pm
by Gaming-Dojo
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.
Re: Boomerang
Posted: Wed Jun 07, 2017 2:44 pm
by TDK
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?
Re: Boomerang
Posted: Wed Jun 07, 2017 2:54 pm
by Gaming-Dojo
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.
Re: Boomerang
Posted: Wed Jun 07, 2017 6:16 pm
by PixelPest
That's a really bad idea. Release it as one
Re: Boomerang
Posted: Thu Jun 08, 2017 2:39 am
by Hoeloe
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.
Re: Boomerang
Posted: Thu Jun 08, 2017 5:51 am
by Gaming-Dojo
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.
Re: Boomerang
Posted: Thu Jun 08, 2017 7:08 am
by Hoeloe
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.
Re: Boomerang
Posted: Thu Jun 08, 2017 8:43 am
by timocomsmbx2345
PixelPest wrote:That's a really bad idea. Release it as one
do you mean release it at once?
Re: Boomerang
Posted: Thu Jun 08, 2017 8:53 am
by Mable
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.
Re: Boomerang
Posted: Thu Jun 08, 2017 8:53 am
by Emral
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.
Re: Boomerang
Posted: Thu Jun 08, 2017 1:24 pm
by Gaming-Dojo
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 {}.
Re: Boomerang
Posted: Thu Jun 08, 2017 2:11 pm
by Hoeloe
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.