Page 1 of 2

Change projectiles?

Posted: Fri Jul 22, 2016 11:27 pm
by loop
How do I change what a NPC spawns, like Birdo's eggs turning into turnips? :|

Re: Change projectiles?

Posted: Sat Jul 23, 2016 12:25 am
by Radiance
You can't change it since it's the projectile designated for that NPC. Unless customizing the NPC graphic and codes. And I think you could use LunaLua for that.
Sorry, I thought it's in H&S forum.

Re: Change projectiles?

Posted: Sat Jul 23, 2016 6:58 am
by PixelPest
Change its ID in a for loop

Re: Change projectiles?

Posted: Sat Jul 23, 2016 10:53 am
by loop
PixelPest wrote:Change its ID in a for loop
I am autistic, so I don't understand. :? Can you give an example? :roll:

Re: Change projectiles?

Posted: Sat Jul 23, 2016 11:07 am
by PixelPest
Jayce 777 wrote:
PixelPest wrote:Change its ID in a for loop
I am autistic, so I don't understand. :? Can you give an example? :roll:
I'm not going to write the code for you, but an example of a for loop is this:

Code: Select all

function onTick()
      for _, n in pairs(NPC.get(1, -1)) do --for all SMB3 Goombas in all sections
            n.speedX = 8; --change their speed along the x-axis to 8
      end
end 
As stated above in the comments, this would take the speed of all of the SMB3 Goombas (npc-1) in all of the sections and set their speed along the x-axis to 8. What you want to do is check for whatever NPC you want and change it to another instead of changing its speed, so you would do n.id = #; --> # is the ID you want to change it to

Re: Change projectiles?

Posted: Sat Jul 23, 2016 11:29 am
by loop
Thanks. I am a n00b at coding.

Re: Change projectiles?

Posted: Sat Jul 23, 2016 11:33 am
by Hoeloe
PixelPest wrote: As stated above in the comments, this would take the speed of all of the SMB3 Goombas (npc-1) in all of the sections and set their speed along the x-axis to 8. What you want to do is check for whatever NPC you want and change it to another instead of changing its speed, so you would do n.id = #; --> # is the ID you want to change it to
Actually it's not quite as simple as that. Changing the ID won't account for changing any of the data, so the graphic will likely appear incorrectly and the hitbox will be wrong.

It's simpler to kill the NPC and spawn a new one with the ID you want.

Re: Change projectiles?

Posted: Sat Jul 23, 2016 11:39 am
by PixelPest
Hoeloe wrote:
PixelPest wrote: As stated above in the comments, this would take the speed of all of the SMB3 Goombas (npc-1) in all of the sections and set their speed along the x-axis to 8. What you want to do is check for whatever NPC you want and change it to another instead of changing its speed, so you would do n.id = #; --> # is the ID you want to change it to
Actually it's not quite as simple as that. Changing the ID won't account for changing any of the data, so the graphic will likely appear incorrectly and the hitbox will be wrong.
I was waiting to see if that issue would come up and then go from there. Your other idea has its own set of issues too though

Re: Change projectiles?

Posted: Sat Jul 23, 2016 11:43 am
by Hoeloe
PixelPest wrote: I was waiting to see if that issue would come up and then go from there. Your other idea has its own set of issues too though
It absolutely will come up.

It does, but they're simpler to resolve as they just involve setting some values after spawning it.

Alternatively, I personally use a function I wrote that makes use of NPCConfig.lua to adjust the necessary values for changing the ID. I'm thinking of adding it to some standard libraries at some point.
Spoiler: show

Code: Select all

local function replaceNPC(npc,id)
	npc.id = id;
	local w = npcconfig[npc.id].width;
	local h = npcconfig[npc.id].height;
	npc:mem(0x90, FIELD_DFLOAT, w);
	npc:mem(0x88, FIELD_DFLOAT, h);
	if(npcconfig[npc.id].gfxwidth ~= 0) then
		w = npcconfig[npc.id].gfxwidth;
	end
	if(npcconfig[npc.id].gfxheight ~= 0) then
		h = npcconfig[npc.id].gfxheight;
	end
	npc:mem(0xB8, FIELD_DFLOAT, w);
	npc:mem(0xC0, FIELD_DFLOAT, h);
	npc:mem(0xE4, FIELD_WORD, 0);
end

Re: Change projectiles?

Posted: Sat Jul 23, 2016 2:12 pm
by loop
Would this work?

Code: Select all

function onLoop()
NPC.get(40,-1)
if NPC.id == 40 then
NPC.id == 210
:?

Re: Change projectiles?

Posted: Sat Jul 23, 2016 2:34 pm
by PixelPest
Jayce 777 wrote:Would this work?

Code: Select all

function onLoop()
NPC.get(40,-1)
if NPC.id == 40 then
NPC.id == 210
:?
No. Not even close really. You don't have a for loop so NPC.get() isn't doing anything, onLoop() should be onTick(), you don't need to test for NPC ID since you are only getting npc-40 from NPC.get(), and you aren't closing the lines with end anywhere

Re: Change projectiles?

Posted: Sat Jul 23, 2016 3:04 pm
by loop
:idea:

Code: Select all

function onTick()
      for _, n in pairs(NPC.get(40, -1)) do --for all Birdo Eggs in all sections
            NPC.id == 210 --turn Birdo Eggs into Rinkas
      end
end
How is this? :?

Re: Change projectiles?

Posted: Sat Jul 23, 2016 3:06 pm
by PixelPest
Jayce 777 wrote::idea:

Code: Select all

function onTick()
      for _, n in pairs(NPC.get(40, -1)) do --for all Birdo Eggs in all sections
            NPC.id == 210 --turn Birdo Eggs into Rinkas
      end
end
How is this? :?
Close. You need to change NPC in NPC.id to n. NPC is the class but n is the instance you're referring to. You also don't have to change the comments. They don't do anything

Re: Change projectiles?

Posted: Sat Jul 23, 2016 3:13 pm
by loop

Code: Select all

function onTick()
      for _, n in pairs(NPC.get(40, -1)) do --for all Birdo Eggs in all sections
            NPC.id ==0,210 --turn Birdo Eggs into Rinkas
      end
end
I didn't understand, but I tried. :?

Re: Change projectiles?

Posted: Sat Jul 23, 2016 3:16 pm
by PixelPest
Jayce 777 wrote:

Code: Select all

function onTick()
      for _, n in pairs(NPC.get(40, -1)) do --for all Birdo Eggs in all sections
            NPC.id ==0,210 --turn Birdo Eggs into Rinkas
      end
end
I didn't understand, but I tried. :?
Read what I said again. It's probably the simplest instruction ever. This is totally wrong

Re: Change projectiles?

Posted: Sat Jul 23, 2016 3:21 pm
by loop
PixelPest wrote:
Jayce 777 wrote:

Code: Select all

function onTick()
      for _, n in pairs(NPC.get(40, -1)) do --for all Birdo Eggs in all sections
            NPC.id ==0,210 --turn Birdo Eggs into Rinkas
      end
end
I didn't understand, but I tried. :?
Read what I said again. It's probably the simplest instruction ever. This is totally wrong
Oops! :?

Code: Select all

function onTick()
      for _, n in pairs(NPC.get(40, -1)) do --for all Birdo Eggs in all sections
            NPC.id ==210,player.section --turn Birdo Eggs into Rinkas
      end
end
How is this? :?

Re: Change projectiles?

Posted: Sat Jul 23, 2016 3:24 pm
by PixelPest
Jayce 777 wrote:
PixelPest wrote:
Jayce 777 wrote:

Code: Select all

function onTick()
      for _, n in pairs(NPC.get(40, -1)) do --for all Birdo Eggs in all sections
            NPC.id ==0,210 --turn Birdo Eggs into Rinkas
      end
end
I didn't understand, but I tried. :?
Read what I said again. It's probably the simplest instruction ever. This is totally wrong
Oops! :?

Code: Select all

function onTick()
      for _, n in pairs(NPC.get(40, -1)) do --for all Birdo Eggs in all sections
            NPC.id ==210,player.section --turn Birdo Eggs into Rinkas
      end
end
How is this? :?
Again.
READ. WHAT. I. SAID.
When did I mention player.section. Never

Re: Change projectiles?

Posted: Sat Jul 23, 2016 3:35 pm
by loop
PixelPest wrote:
Jayce 777 wrote:
PixelPest wrote: Read what I said again. It's probably the simplest instruction ever. This is totally wrong
Oops! :?

Code: Select all

function onTick()
      for _, n in pairs(NPC.get(40, -1)) do --for all Birdo Eggs in all sections
            NPC.id ==210,player.section --turn Birdo Eggs into Rinkas
      end
end
How is this? :?
Again.
READ. WHAT. I. SAID.
When did I mention player.section. Never
Whoa, take it easy! I'll just research some codes.

Did research on the Red Birdo, and I came up with this:

Code: Select all

function onTick()
      for _, n in pairs(NPC.get(40, -1)) do --for all Birdo Eggs in all sections
            n.id ==210,player.section --turn Birdo Eggs into Rinkas
      end
end
 
I suck at coding.
Oops! forgot the end again!

Re: Change projectiles?

Posted: Sun Jul 24, 2016 5:21 pm
by Quantumenace
I'd recommend onTickEnd() because that runs after the egg is spawned but before the game draws it. Otherwise the egg will likely appear for a single frame. I'd also recommend altering the egg's npc txt so it doesn't damage the player; not sure it checks collision the frame it's spawned, but that would err on the safe side.

Re: Change projectiles?

Posted: Sun Jul 24, 2016 7:24 pm
by PixelPest
Jayce 777 wrote:
PixelPest wrote:
Jayce 777 wrote: Oops! :?

Code: Select all

function onTick()
      for _, n in pairs(NPC.get(40, -1)) do --for all Birdo Eggs in all sections
            NPC.id ==210,player.section --turn Birdo Eggs into Rinkas
      end
end
How is this? :?
Again.
READ. WHAT. I. SAID.
When did I mention player.section. Never
Whoa, take it easy! I'll just research some codes.

Did research on the Red Birdo, and I came up with this:

Code: Select all

function onTick()
      for _, n in pairs(NPC.get(40, -1)) do --for all Birdo Eggs in all sections
            n.id ==210,player.section --turn Birdo Eggs into Rinkas
      end
end
 
I suck at coding.
Oops! forgot the end again!
Okay. I'm going to try to not flip out, but you haven't followed my instructions over and over again and you have absolutely no idea what you're doing. You know absolutely nothing of the basics of coding and keep on just randomly throwing stuff out that will not work. == is used for comparisons and = for declaring. And please explain to me, why do you think player.section needs to be there?