Page 37 of 76

Re: Need help with lua? - LunaLua General Help

Posted: Tue Oct 18, 2016 11:40 pm
by Yoshi021
Ghostly_Guy wrote:

Code: Select all

function onLoop()
	if player:mem(PC+0x154, FIELD_WORD) == 87 then
		player:mem(PC+0x154,FIELD_WORD) = 17;
	end
end
When you want to set an offset you do this
player:mem(0x154,FIELD_WORD,17)

Re: Need help with lua? - LunaLua General Help

Posted: Wed Oct 19, 2016 1:06 am
by Ghostly_Guy
Ghostly_Guy wrote:

Code: Select all

function onLoop()
	if player:mem(PC+0x154, FIELD_WORD) == 87 then
		player:mem(PC+0x154,FIELD_WORD) = 17;
	end
end
PixelPest wrote:It's not PC+0x154, just 0x154. Also use onTick() instead of onLoop(); the latter is deprecated
Yoshi021 wrote: When you want to set an offset you do this
player:mem(0x154,FIELD_WORD,17)
I made the edits, but I couldn't get the NPC to change.
My original idea was to let the player pick up the bowser fireballs, which would turn into bullet bills in their hands. This was a horrible idea, and I rethought it.
I looked around on this thread, and I found a way to change the NPC Bowser fires. Here's the new code, plagiarized straight from page 26:

Code: Select all

function onTick()
	local transform = NPC.get(87, -1)
	for k,v in pairs(transform) do
		v.id = 17
	end
end

Re: Need help with lua? - LunaLua General Help

Posted: Wed Oct 19, 2016 2:42 am
by Hoeloe
Ghostly_Guy wrote:

Code: Select all

function onTick()
	local transform = NPC.get(87, -1)
	for k,v in pairs(transform) do
		v.id = 17
	end
end
When transforming NPCs from one to another, it's safer to import the "classExpander" library using API.load, and then use:

Code: Select all

v:transform(17);
This will transform one NPC to another, but also account for inconsistencies that can occur.

Re: Need help with lua? - LunaLua General Help

Posted: Fri Oct 21, 2016 5:44 pm
by Amine Retro
what the heck are you talking about? my SMBX 2.0 is totally normal!
works perfectly, especially in the invasion 2 link ear rape! invasion 3!
screenshot of totally fine SMBX ver. 2.0
Image
see? fine!

Re: Need help with lua? - LunaLua General Help

Posted: Fri Oct 21, 2016 5:55 pm
by Emral
I love it!

Re: Need help with lua? - LunaLua General Help

Posted: Fri Oct 21, 2016 6:04 pm
by Amine Retro
i know right?
i really liked the invasion 3, it should be featured as a default SMBX episode.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Nov 12, 2016 12:41 pm
by Drachenbauer
Hello

If i trx to open the smbx.exe in the folder "LunaLUA_0.7.3-beta_smbxluna_sfx_mus_full" there comes two errors, that the files "MSVCP140.dll" and "VCRUNTIME140.dll" are missing.

What can i do to make it working?

Re: Need help with lua? - LunaLua General Help

Posted: Sat Nov 12, 2016 1:04 pm
by loop
Drachenbauer wrote:Hello

If i trx to open the smbx.exe in the folder "LunaLUA_0.7.3-beta_smbxluna_sfx_mus_full" there comes two errors, that the files "MSVCP140.dll" and "VCRUNTIME140.dll" are missing.

What can i do to make it working?
Run vcredist.exe.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Nov 12, 2016 1:41 pm
by Drachenbauer
now the smbx works.

now there cane an runtime error and it closed...

i tryed toopen a level, what´s placed in the "Worlds" folder (i copyed my own world there) of SMBX 2.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Nov 12, 2016 10:44 pm
by RPG_Magician
Trying to make my playable lose all momentum and dropping straight down when I do Down-Stab.

function onInputUpdate()

if(player.downKeyPressing) then
player.downKeyPressing = true;
player.leftKeyPressing = false;
player.rightKeyPressing = false;

end
end

Something something terrible code.
Yeah it's simple code. Also I'm trying to get the momentum to stop after sprinting. Any tips?

Re: Need help with lua? - LunaLua General Help

Posted: Sat Nov 12, 2016 11:50 pm
by Yoshi021
You can use player.speedY and player.speedX to change the player's speed.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Nov 13, 2016 6:33 am
by PixelPest
That code won't work because you're only cancelling button presses, which means that although the player can't gain any more momentum, they don't lose it either. Try:

Code: Select all

function onTick()
    if (player.downKeyPressing) and (player:mem(0x146, FIELD_WORD) ~= 2) and (player.character == 5) then --if Link is pressing down while in the air
        player.speedX = 0; --stop the player's horizontal motion
    end
end 

Re: Need help with lua? - LunaLua General Help

Posted: Mon Nov 14, 2016 12:07 am
by RPG_Magician
PixelPest wrote:That code won't work because you're only cancelling button presses, which means that although the player can't gain any more momentum, they don't lose it either. Try:

Code: Select all

function onTick()
    if (player.downKeyPressing) and (player:mem(0x146, FIELD_WORD) ~= 2) and (player.character == 5) then --if Link is pressing down while in the air
        player.speedX = 0; --stop the player's horizontal motion
    end
end 
Oh thank you! It works nicely, (I still have a long way to go with lunalua....)

Re: Need help with lua? - LunaLua General Help

Posted: Fri Nov 25, 2016 7:46 am
by Angelus
Is there any code which disables the run feature but maintain the grab/fireball ones? Because as far as I can tell these three abilities share the same key, so by disabling one I'll be disabling everything... I was able to do it but as said before, I just want to disable the run feature and nothing else. Is that even possible?

Re: Need help with lua? - LunaLua General Help

Posted: Fri Nov 25, 2016 7:58 am
by PixelPest
Yes. It would basically be something like this:

Code: Select all

function onTick()
    if player.speedX > 3 then
        player.speedX = 3;
    elseif player.speedX < -3 then
        player.speedX = -3;
    end
end
This should work most of the time. Exceptions would be moving layers and the conveyor belts. Also, different characters have different run speeds so the code above would likely only work for Mario.

Also, I'm not 100% sure that Mario's run speed is 3, however you can check by doing the following first before what I posted towards the top:

Code: Select all

function onTick()
    Text.print(player.speedX, 0, 0);
end 
Then just hold the right or left button (without the run button) and see what that speed is after it stops going up.

I might look at writing a better script later today that allows for different characters, moving layers, conveyor belts, etc. to work too

Re: Need help with lua? - LunaLua General Help

Posted: Fri Nov 25, 2016 8:47 am
by Angelus
That's great to know, thank you very much!

By the way, I've managed to find Peach's speed, which is 2.7900000214577. While Toad's speed is totally random, it keeps going back and forth but I believe it's something around 3.1.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Nov 26, 2016 7:22 am
by DeMuZ
Why do this code crash SMBX...

Code: Select all

while mask_X + 28 >= player.x - 96 or mask_X <= player.x + 128 do
	mask_X = rng.randomInt(-139230, -139998)
end
...but this code does not???

Code: Select all

while mask_X == player.x do
	mask_X = rng.randomInt(-139230, -139998)
end
PS. it's included into onTick() function.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Nov 26, 2016 8:23 am
by PixelPest
Please post the whole code (including the onTick() event and variables) and post exactly what the error message says

Re: Need help with lua? - LunaLua General Help

Posted: Sat Nov 26, 2016 8:29 am
by DeMuZ

Code: Select all

--APIs
	local colliders = API.load("colliders")
	local rng = API.load("rng")
	local encrypt = API.load("encrypt")
	
--boss1 variables
	local boss1_hp = 10
	local boss1_time = 0
	
--boss2 variables
	local boss2_hp = 10
	
--boss3 variables
	local boss3_hp = 10
	local boss3_time = 0
	local mask_X = 0
	local mask_Y = 0
	
--other variables
	local boss_cooldown = 0
	bossData = encrypt.Data(Data.DATA_WORLD,true)
	
	for x = 1, 2 do
		if bossData:get(tostring(x)) == nil then
			bossData:set(tostring(x), 0)
			bossData:save()
		end
	end
	
--block beaten bosses
	function onLoad()
		for	x = 1, 11 do
			if mem(0x00B251E0, FIELD_WORD) == x then
				triggerEvent("boss"..tostring(x).." - defeat")
			end
		end
	end
	
--boss1 main function
	function onLoopSection1()
		--if boss is still alive
		if boss1_hp > 0 then
			Text.print("HP: "..boss1_hp.."/10", 8, 8)
			goombaSpawner()
		end
		
		for k,v in pairs(NPC.get(71, -1)) do
			v.drawOnlyMask = false
			
			if boss1_hp < 1 then
				v:kill()
				
			elseif colliders.bounce(player, v) then
				if boss_cooldown == 0 then
					colliders.bounceResponse(player, 3)
					boss1_hp = boss1_hp - 1
					boss_cooldown = 65 * 2
					
				else
					player:harm()
				end
			
			elseif colliders.collide(player, v) then
				player:harm()
			end
				
			if boss_cooldown > 0 and boss1_hp > 0 and boss_cooldown % 20 > 9 then
				v.drawOnlyMask = true
			end
		end
		
		if boss_cooldown > 0 then
			boss_cooldown = boss_cooldown - 1
		end
	end

--boss1 spawner function
	function goombaSpawner()
		if boss1_time == 0 then
			goomba = NPC.spawn(1, rng.randomInt(-179744, -179488), -180616, player.section)
			boss1_time = 100
		end
		
		for k,v in pairs(NPC.get(1, -1)) do
			if v.speedY == 0 then
				if v.x < player.x - 8 and v.speedX < 0 then
					v.speedX = - v.speedX
					
				elseif v.x > player.x + 8 and v.speedX > 0 then
					v.speedX = - v.speedX
				end
			end
		end
		
		boss1_time = boss1_time - 1
	end

--boss2 main function
	function onLoopSection2()
		--if boss is still alive
		if boss2_hp > 0 then
			Text.print("HP: "..boss2_hp.."/10", 8, 8)
			chasingThwomp()
		end
		
		for k,v in pairs(NPC.get(180, 2)) do
			v.drawOnlyMask = false
			
			if boss2_hp < 1 then
				v:kill()
			
			elseif colliders.bounce(player, v) then
				if boss_cooldown == 0 and player:mem(0x50, FIELD_WORD) == -1 then
					colliders.bounceResponse(player, 3)
					
				else
					player:harm()
				end
			
			elseif colliders.collide(player, v) then
				player:harm()
			end
			
			--red bricks
			for k2,v2 in pairs(NPC.get(45, 2)) do
				if colliders.bounce(v, v2) then
					v2:kill()
					boss_cooldown = 65 * 2
					boss2_hp = boss2_hp - 1
				end
			end
			
			--bricks
			for k2,v3 in pairs(NPC.get(159, 2)) do
				if colliders.bounce(v, v3) then
					v3:kill()
				end
			end
				
			if boss_cooldown > 0 and boss2_hp > 0 and boss_cooldown % 20 > 9 then
				v.drawOnlyMask = true
			end
		end
		
		if boss_cooldown > 0 then
			boss_cooldown = boss_cooldown - 1
		end
	end
	
--boss2 behaviour function
	function chasingThwomp()
		for k,v in pairs(NPC.get(180, 2)) do
			if v.ai1 ~= 2 and v.ai1 ~= 3 and boss_cooldown == 0 then
				if v.ai1 ~= 0 then
					if v.x + 48 < player.x then
						v.speedX = 1.0
							
					elseif v.x > player.x + 32 then
						v.speedX = - 1.0
					end
				
				else
					if v.x + 48 < player.x then
						v.speedX = 1.5
							
					elseif v.x > player.x + 32 then
						v.speedX = - 1.5
					end
				end
			else
				v.speedX = 0
			end
			
			if boss_cooldown > 0 then
				v.speedY = 0
			end
		end
	end

--boss3 main function	
	function onLoopSection3()
		if boss3_hp > 0 then
			Text.print("HP: "..boss3_hp.."/10", 8, 8)
			maskSpawner()
		end
	
		for k,v in pairs(BGO.get(150)) do
			if boss_cooldown > 65 then
				--???
			end
			
			--???
		end
		
		if boss_cooldown > 0 then
			boss_cooldown = boss_cooldown - 1
		end
	end
	
--boss3 spawner function
	function maskSpawner()
		mask_X = 0
		mask_Y = 0
		
		if boss3_time == 0 then
			while mask_X + 28 >= player.x - 96 or mask_X <= player.x + 128 do
				mask_X = rng.randomInt(-139230, -139998)
			end
			
			while mask_Y == player.y do
				mask_Y = rng.randomInt(-140608, -140032)
			end
			
			NPC.spawn(210, mask_X, mask_Y, player.section)
			boss3_time = 100
		end
		
		boss3_time = boss3_time - 1
	end
	
--onNPCKill function
	function onNPCKill(eventObj, npcObj, npcKillReason)
		--boss1 defeat
		if npcObj.id == 71 then
			star1 = NPC.spawn(196, -179616, -180640, player.section)
			star1.speedY = 5.5
			playSFX(21)
			playMusic(16)
		end
		
		--boss2 defeat
		if npcObj.id == 180 then
			NPC.spawn(26, -159616, -160416, player.section)
			star2 = NPC.spawn(196, -159616, -160640, player.section)
			star2.speedY = 5.5
			playSFX(21)
			playMusic(16)
		end
		
		--boss3 defeat
			
		
		--when star is taken
		if npcObj.id == 196 then
			triggerEvent("boss"..tostring(player.section).." - defeat")
		end
	end
line 206, in function maskSpawner()

There's no error. SMBX just crashes when I enter the section where it is called. :(

Re: Need help with lua? - LunaLua General Help

Posted: Sat Nov 26, 2016 8:37 am
by PixelPest
I'd suggest that the while loop is possibly running infinitely. Try replacing it with an if statement both times it appears in maskSpawner()