Making coins appear When npc Is hit by fireballs?

This is the place for discussion and support for LunaLua and related modifications and libraries.
Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
User avatar
Darkonius Mavakar
Boom Boom
Boom Boom
Posts: 1667
Joined: Fri Dec 27, 2013 2:45 pm
Flair: Pizza
Current Project: None as of now.
Contact:

Making coins appear When npc Is hit by fireballs?

Postby Darkonius Mavakar » Mon Jul 25, 2016 6:11 am

So you know how in the original SMW, when you hit an enemy with a fireball, A coin would appear?
Ok.
How do i do that?

User avatar
PixelPest
Link
Link
Posts: 7118
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Current Project: Boom Boom Evolution
Chat Username: PixelPest
Contact:

Re: Making coins appear When npc Is hit by fireballs?

Postby PixelPest » Mon Jul 25, 2016 6:34 am

I think it's actually pretty complicated, although someone did make it at one point and I think it might be in 2.0

User avatar
Hoeloe
Grinder
Grinder
Posts: 1104
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Current Project: A2XT Episode 2

Re: Making coins appear When npc Is hit by fireballs?

Postby Hoeloe » Mon Jul 25, 2016 7:12 am

PixelPest wrote:I think it's actually pretty complicated, although someone did make it at one point and I think it might be in 2.0
Uh, it's not really complicated. You can use the onNPCKill event to detect this, and you can use the kill reason and run a collision check with fireballs in there.

User avatar
Nat The Porcupine
Swooper
Swooper
Posts: 122
Joined: Tue Nov 10, 2015 2:55 pm
Current Project: Nothing ATM

Re: Making coins appear When npc Is hit by fireballs?

Postby Nat The Porcupine » Thu Aug 11, 2016 3:50 pm

PixelPest wrote:I think it's actually pretty complicated, although someone did make it at one point and I think it might be in 2.0
It was me. I wrote a script called "altfiredeathsystem.lua". Simply just save this as "altfiredeathsystem.lua" to your LuaScriptsLib folder & load up the API and you're good to go.
Here's the code:

Code: Select all

--Alternate Death by Fireball System--
--by Nat The Porcupine--

local altfiredeathsystem = {};
local colliders = API.load("colliders"); 
local coinStyleTable = {["SMB1"] = 88, ["SMB2"] = 138, ["SMB3"] = 10, ["SMW"] = 33, ["Zelda"] = 251, ["Sonic"] = 152};
local coinStyle = "SMB3";

function altfiredeathsystem.onInitAPI()
	registerEvent(altfiredeathsystem, "onTick", "onTick");
	registerEvent(altfiredeathsystem, "onNPCKill", "onNPCKill");
	registerEvent(altfiredeathsystem, "onTickEnd", "onTickEnd");
end

function altfiredeathsystem.onTick()

	for _,coin in pairs(NPC.get(coinStyleTable[coinStyle],-1)) do
		if coin.ai2 < 1 then
			coin.ai2 = 1;	--ai2 is usually unused on coin NPCs, but here we use it as a "just spawned" flag
		end
	end
	
end

function altfiredeathsystem.onNPCKill(event,npc,reason)
	
	if npc.id == 13 and npc.ai3 == 0 then	--This prevents a player's fireball from dying immediately so we can test for its collision later
		npc.ai3 = 1;
		event.cancelled = true;
	end
	
	if npc.id ~= 13 and reason == 3 then	--This checks for an NPC that isn't a fireball that has died as the result of a thrown projectile
		
		for _,fireball in pairs(NPC.get(13,-1)) do
			if colliders.collide(fireball,npc) then
				
				NPC.spawn(coinStyleTable[coinStyle],npc.x,npc.y,player.section,false);	--Spawns the coin
				
				for _,coin in pairs(NPC.get(coinStyleTable[coinStyle],player.section)) do
					if colliders.collide(coin,npc) and coin.ai2 == 0 then
						coin.speedX = fireball.direction * 0.75;	--Sets the X speed of the coin
						coin.speedY = -4;	--Sets the Y speed of the coin
						coin.ai1 = 1;	--Enables gravity
					end
				end
			end
		end
			
		npc:kill(9);
		playSFX(9);
		
	end
	
end

function altfiredeathsystem.onTickEnd()
	for _,npc in pairs(NPC.get(13,-1)) do
		if npc.ai3 == 1 then
			npc:kill(4);	--Kills the fireball for good
		end
	end
end

return altfiredeathsystem;
As for its inclusion in 2.0, Horikawa never actually responded to the PM I sent it to her in, so I doubt it'll end up included in the next release, if at all.


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 1 guest