Page 52 of 76

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 03, 2017 4:13 am
by Quantumenace
Devan2002: There is the event function onNPCKill(Event eventObj, NPC killedNPC, number killReason) that runs when an NPC is killed. The function arguments are arbitrarily named variables that are automatically assigned the relevant value and can be referenced.

Example:

Code: Select all

function onNPCKill(e, killedNPC, killtype)
    if killedNPC.id == 210 then
        .............................
    end
end

MosaicMario: You have two functions named onTick and that won't work. (and in addition your second one is spelled with a capital O and won't be used as an event anyway.)

Either put the content in the same onTick, or put it in separate functions that are both called in onTick().

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 03, 2017 9:56 am
by TDK
Is there any way to make a block chase you throughout the entire level?
I tried it with chasing koopa para-troopa, but it goes off-screen and disappear.

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 03, 2017 11:05 am
by PersonNamedUser
IT. NEVER. ENDS.
Now what's wrong with it?
Image

Code: Select all

local haveBoosted = false;
local haveBoostedDown = false;

function onLoop()
	if player:mem(0x146, FIELD_WORD) == 2 then
		HaveBoosted = false;
		HaveBoostedDown = false;
	end
end

function onStart()
     Level.loadPlayerHitBoxes(4, 1, "toad-1.ini")
	 Level.loadPlayerHitBoxes(4, 2, "toad-2.ini")
	 Level.loadPlayerHitBoxes(4, 3, "toad-3.ini")
	 Level.loadPlayerHitBoxes(4, 4, "toad-4.ini")
	 Level.loadPlayerHitBoxes(4, 5, "toad-5.ini")
	 Level.loadPlayerHitBoxes(4, 6, "toad-6.ini")
     Level.loadPlayerHitBoxes(4, 7, "toad-7.ini")
end

function onTick()
		if player:mem(0x146, FIELD_WORD == 0) and (player:mem(0xF4, FIELD_WORD) == true) and player.rightKeyPressing then 
		if haveBoosted == false then
		player.speedX = -5
		Audio.playSFX("dash.wav")
		do haveBoosted = true;
		end
		elseif player:mem(0x146, FIELD_WORD == 0) and (player:mem(0xF4, FIELD_WORD) == true) and player.leftKeyPressing then 
		if haveBoosted == false then
		player.speedX = 5
		Audio.playSFX("dash.wav")
		do haveBoosted = true;
		end
		elseif player:mem(0x146, FIELD_WORD == 0) and (player:mem(0xF4, FIELD_WORD) == true) and player.downKeyPressing then 
		if haveBoostedDown == false then
		player.speedY = 5
		Audio.playSFX("dash.wav")
		do haveBoostedDown = true;
		do haveBoosted = true;
						end
					end
				end
			end
		end
	end
end

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 03, 2017 12:38 pm
by TDK
MosaicMario wrote:IT. NEVER. ENDS.
Now what's wrong with it?
Image

Code: Select all

local haveBoosted = false;
local haveBoostedDown = false;

function onLoop()
	if player:mem(0x146, FIELD_WORD) == 2 then
		HaveBoosted = false;
		HaveBoostedDown = false;
	end
end

function onStart()
     Level.loadPlayerHitBoxes(4, 1, "toad-1.ini")
	 Level.loadPlayerHitBoxes(4, 2, "toad-2.ini")
	 Level.loadPlayerHitBoxes(4, 3, "toad-3.ini")
	 Level.loadPlayerHitBoxes(4, 4, "toad-4.ini")
	 Level.loadPlayerHitBoxes(4, 5, "toad-5.ini")
	 Level.loadPlayerHitBoxes(4, 6, "toad-6.ini")
     Level.loadPlayerHitBoxes(4, 7, "toad-7.ini")
end

function onTick()
		if player:mem(0x146, FIELD_WORD == 0) and (player:mem(0xF4, FIELD_WORD) == true) and player.rightKeyPressing then 
		if haveBoosted == false then
		player.speedX = -5
		Audio.playSFX("dash.wav")
		do haveBoosted = true;
		end
		elseif player:mem(0x146, FIELD_WORD == 0) and (player:mem(0xF4, FIELD_WORD) == true) and player.leftKeyPressing then 
		if haveBoosted == false then
		player.speedX = 5
		Audio.playSFX("dash.wav")
		do haveBoosted = true;
		end
		elseif player:mem(0x146, FIELD_WORD == 0) and (player:mem(0xF4, FIELD_WORD) == true) and player.downKeyPressing then 
		if haveBoostedDown == false then
		player.speedY = 5
		Audio.playSFX("dash.wav")
		do haveBoostedDown = true;
		do haveBoosted = true;
						end
					end
				end
			end
		end
	end
end
There was a bracket in the wrong place in line 22, and there was a missing "end".

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 03, 2017 1:11 pm
by Emral
It won't work cause that's not how "do" works.
What are you trying to do with the "do"s? You set variables all over the place, so it can't be that.

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 03, 2017 2:56 pm
by Quantumenace
It's critical that you learn how to read error messages. It tells you what line in your lunadll.lua is causing the problem. "No matching overload" means that a function has been given the wrong types of arguments, in this case:

if player:mem(0x146, FIELD_WORD == 0)

Since you put "== 0" inside the parenthesis it takes "FIELD_WORD == 0" as a boolean, and that's an invalid argument for that function.

TheDinoKing wrote:Is there any way to make a block chase you throughout the entire level?
I tried it with chasing koopa para-troopa, but it goes off-screen and disappear.
Try setting the koopa's mem offset 0x12A to 180 or so every tick to stop it from despawning. You may also need to alter its y coordinate if it goes off the bottom of the screen and dies.

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 03, 2017 5:45 pm
by RhysOwens
How do you make it so LunaLua detects when you jump on a boss and it goes into it's shell form or whatever?
I also wanna know how to make it so Larry doesn't stop moving when he's firing his magic.

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 03, 2017 8:21 pm
by PersonNamedUser
So, after messing around a bit, i finally got the code to work probably! The only problem is that when you boost downward
the sound plays a billion times in row. Does anyone know how to fix this?
Here's the code:

Code: Select all

function onTick()
	if player:mem(0x146, FIELD_WORD) == 2 and Boosts < 1 or DownwardBoosts < 1 then
		if Boosts < 1 then Boosts = Boosts + 1;
		if DownwardBoosts < 1 then DownwardBoosts = DownwardBoosts + 1;
		end
	end
end
		if player:mem(0x146, FIELD_WORD) == 0 and player.altRunKeyPressing and player.rightKeyPressing then 
		if Boosts == 1 then
		player.speedX = 25
		Audio.playSFX("dash.wav")
		Boosts = 0;
		end
		elseif player:mem(0x146, FIELD_WORD) == 0 and player.altRunKeyPressing and player.leftKeyPressing then 
		if Boosts == 1 then
		player.speedX = -25
		Audio.playSFX("dash.wav")
		Boosts = 0;
		end
		elseif player:mem(0x146, FIELD_WORD) == 0 and player.altRunKeyPressing and player.downKeyPressing then 
		if DownwardBoosts == 1 then
		player.speedY = 25
		player.speedX = 0
		Audio.playSFX("dash.wav")
		DownwardBoosts = 0;
		Boosts = 0;
		end
	end
end

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 03, 2017 9:24 pm
by PixelPest
RhysOwens: You can check if #NPC.get(whatever Larry's shell ID is) > 0. You'd probably have to mess with AI fields for the second one.

MosaicMario: DownwardBoosts is being switched back and forth from 0 to 1 to 0 to 1 and each time it is 1 the sound is played

Re: Need help with lua? - LunaLua General Help

Posted: Tue Apr 04, 2017 3:16 am
by PersonNamedUser
I actually have another question, how would you make a ludwig replacement shoot projectiles faster than usual?

Re: Need help with lua? - LunaLua General Help

Posted: Tue Apr 04, 2017 6:38 am
by PixelPest
MosaicMario wrote:I actually have another question, how would you make a ludwig replacement shoot projectiles faster than usual?
Take a look at Ludwig's AI: http://wohlsoft.ru/pgewiki/SMBX_NPC_AI

Re: Need help with lua? - LunaLua General Help

Posted: Tue Apr 04, 2017 8:06 am
by RhysOwens
PixelPest wrote:RhysOwens: You can check if #NPC.get(whatever Larry's shell ID is) > 0. You'd probably have to mess with AI fields for the second one.

MosaicMario: DownwardBoosts is being switched back and forth from 0 to 1 to 0 to 1 and each time it is 1 the sound is played
Where do I put the NPC id?

Re: Need help with lua? - LunaLua General Help

Posted: Tue Apr 04, 2017 9:12 am
by PixelPest
Between the brackets where I wrote "whatever Larry's shell ID is"

Re: Need help with lua? - LunaLua General Help

Posted: Tue Apr 04, 2017 9:52 am
by PersonNamedUser
PixelPest wrote:
MosaicMario wrote:I actually have another question, how would you make a ludwig replacement shoot projectiles faster than usual?
Take a look at Ludwig's AI: http://wohlsoft.ru/pgewiki/SMBX_NPC_AI
thing is, i looked into it and tried putting this in:

Code: Select all

local tableOf***** = {}

function onLoop()
    tableOf***** = NPC.get(280, 16)
    for n=1, table.getn(tableOf*****) do
	    if (tableOf*****[n]:mem(0x148,FIELD_FLOAT) == 0) then
	        tableOf*****[n]:mem(0x148, FIELD_FLOAT, -2)
end
	if tableOf*****:mem(0x100, FIELD_DFLOAT) == 12 then
		tableOf*****:mem(0x100, FIELD_DFLOAT, 20)
		end
	end
end
But, all that comes up is an error message, i don't know what i'm doing wrong.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Apr 04, 2017 9:59 am
by PixelPest
If you have tableOf***** actually in your file that would probably do it. Also, as I've said before, don't just say "I have an error", actually give a line number and the error message. Also table.getn is deprecated. Replace that whole function with #. Furthermore, a better way to do it is just for _, v in pairs(tableOf*****) do. Then you can use v:mem. Also, it would also error near the end where you forgot to do tableOf*****[n]:mem and just did tableOf*****:mem

Re: Need help with lua? - LunaLua General Help

Posted: Tue Apr 04, 2017 10:39 am
by RhysOwens
I tried to make the Birdo Hit sound play when you jump on Larry and he goes into his shell form but this error shows up: ' expected near '39'.
This is the code I'm using right now.

Code: Select all

function onLoop()
     if #NPC.get(268) > 0
	     then Audio.playSFX(int 39)
	 end
end	

Re: Need help with lua? - LunaLua General Help

Posted: Tue Apr 04, 2017 11:14 am
by Quantumenace
RhysOwens wrote:I tried to make the Birdo Hit sound play when you jump on Larry and he goes into his shell form but this error shows up: ' expected near '39'.
This is the code I'm using right now.

Code: Select all

function onLoop()
     if #NPC.get(268) > 0
	     then Audio.playSFX(int 39)
	 end
end	
Don't say 'int' there, just use the number.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Apr 04, 2017 12:23 pm
by RhysOwens
Quantumenace wrote:
RhysOwens wrote:I tried to make the Birdo Hit sound play when you jump on Larry and he goes into his shell form but this error shows up: ' expected near '39'.
This is the code I'm using right now.

Code: Select all

function onLoop()
     if #NPC.get(268) > 0
	     then Audio.playSFX(int 39)
	 end
end	
Don't say 'int' there, just use the number.
It's working, but how do I make it so that it only plays once?

Re: Need help with lua? - LunaLua General Help

Posted: Tue Apr 04, 2017 12:50 pm
by Emral
RhysOwens wrote:
Quantumenace wrote:
RhysOwens wrote:I tried to make the Birdo Hit sound play when you jump on Larry and he goes into his shell form but this error shows up: ' expected near '39'.
This is the code I'm using right now.

Code: Select all

function onLoop()
     if #NPC.get(268) > 0
	     then Audio.playSFX(int 39)
	 end
end	
Don't say 'int' there, just use the number.
It's working, but how do I make it so that it only plays once?
Understand your code. Also use onTick, not onLoop.
Anyway, here's your code, translated to english:

In every frame the program runs (~65 times per second) do the following:
check if there has been at least a single npc of id 268 placed down
if so, play this sound effect
repeat next frame.

Simple solution: add a check for if the sound has already played.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Apr 04, 2017 1:02 pm
by RhysOwens
Enjl wrote:In every frame the program runs (~65 times per second) do the following:
check if there has been at least a single npc of id 268 placed down
if so, play this sound effect
repeat next frame.

Simple solution: add a check for if the sound has already played.
How though? I only know the basics of LunaLua.