How Do I Make Mouser Stun Players?

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
mariobrigade2018
Spike
Spike
Posts: 275
Joined: Wed May 24, 2023 7:00 pm
Flair: Normie in coding who dreams of making a Mario game
Pronouns: he/him

How Do I Make Mouser Stun Players?

Postby mariobrigade2018 » Fri Dec 01, 2023 4:04 pm

I Reskined Mouser to be a Heavy Bomb Bro. But I want it to stun the player when it hits the ground like a Sledge Bro. How would I do this?
CGFX I was talking about:
Image

deice
Volcano Lotus
Volcano Lotus
Posts: 548
Joined: Fri Jul 23, 2021 7:35 am

Re: How Do I Make Mouser Stun Players?

Postby deice » Sat Dec 02, 2023 7:46 am

since the "quake" setting doesn't work for npcs that don't use the "bro" ai script, here's some code that roughly recreates the effect for mouser:

Code: Select all

local stun = require("playerstun")

local EARTHQUAKE_STRENGTH = 15
local STUN_DURATION = 130

local function playerGroundCheck(p)
	return ((p:isOnGround() and p.speedY == 0) or p:mem(0x48, FIELD_WORD) > 0 or p:mem(0x176, FIELD_WORD) > 0)
end

function onTick()
	for _, v in NPC.iterate(262) do
		if(v.isValid and v.despawnTimer > 0) then
			v.data.__previousFallSpeed = v.data.__previousFallSpeed or 0
			if(v.speedY == 0 and v.data.__previousFallSpeed ~= 0) then
				Defines.earthquake = EARTHQUAKE_STRENGTH
				SFX.play(37)
				for p, pp in ipairs(Player.get()) do
					if(pp.section == v.section and playerGroundCheck(pp)) then
						stun.stunPlayer(p, STUN_DURATION)
					end
				end
			end
			v.data.__previousFallSpeed = v.speedY
		end
	end
end

mariobrigade2018
Spike
Spike
Posts: 275
Joined: Wed May 24, 2023 7:00 pm
Flair: Normie in coding who dreams of making a Mario game
Pronouns: he/him

Re: How Do I Make Mouser Stun Players?

Postby mariobrigade2018 » Sat Dec 02, 2023 8:42 pm

deice wrote:
Sat Dec 02, 2023 7:46 am
since the "quake" setting doesn't work for npcs that don't use the "bro" ai script, here's some code that roughly recreates the effect for mouser:

Code: Select all

local stun = require("playerstun")

local EARTHQUAKE_STRENGTH = 15
local STUN_DURATION = 130

local function playerGroundCheck(p)
	return ((p:isOnGround() and p.speedY == 0) or p:mem(0x48, FIELD_WORD) > 0 or p:mem(0x176, FIELD_WORD) > 0)
end

function onTick()
	for _, v in NPC.iterate(262) do
		if(v.isValid and v.despawnTimer > 0) then
			v.data.__previousFallSpeed = v.data.__previousFallSpeed or 0
			if(v.speedY == 0 and v.data.__previousFallSpeed ~= 0) then
				Defines.earthquake = EARTHQUAKE_STRENGTH
				SFX.play(37)
				for p, pp in ipairs(Player.get()) do
					if(pp.section == v.section and playerGroundCheck(pp)) then
						stun.stunPlayer(p, STUN_DURATION)
					end
				end
			end
			v.data.__previousFallSpeed = v.speedY
		end
	end
end
It worked for the first two tries, but now I get this:
Image

Do note that I placed and modified this for an npc-n.lua file.

Edit: Its not this. Something else has happened.

Edit2: One corrupted txt file deletion later, and it works like a charm now. Thanks!


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 6 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari