SSG3's LUA Questions

Status
Not open for further replies.

SSG3

Oh, THAT Youtuber...
I thought that i'd make this to prevent making additional threads for help on LUA.

The problem this time? Metroid Sonic's Morph Ball code. As Someone wanted me to put in the Morph Ball for Metroid Sonic in V7, I thought i'd give it a shot. It didn't turn out well at all. Here's the code:

Code:
addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "metroidsonic"
		and not player.spectator
			if not (player.cmd.buttons & BT_USE)
				player.spinoff = true
				player.spinon = false
			elseif (player.spinoff) then
				player.spinoff = false
				player.spinon = true
			else
				player.spinon = false
			end
			
			if player.morphball == nil
				player.morphball = false
			end
			
			if player.morphball = true
				if player.speed = 0
					player.mo.state = S_PLAY_ATK4
				else
					player.panim = PA_ROLL
				end
			end
				
			if player.cmd.buttons & BT_USE
				if P_IsObjectOnGround(player.mo)
					player.normalspeed = skins[player.mo.skin].normalspeed - 10
					player.acceleration = skins[player.mo.skin].acceleration - 10
					player.morphball = true
				else
					player.normalspeed = skins[player.mo.skin].normalspeed
					player.acceleration = skins[player.mo.skin].acceleration
					player.morphball = false
				end
			end
			
			if player.spinon
				if (not P_IsObjectOnGround(player.mo) and player.canscrew > 0)
					player.mo.momx = 0
					player.mo.momy = 0
					player.mo.momz = 0
					player.mo.state = S_PLAY_FALL1
				end
			end
		end
	end
end)

If anyone can help me (since I have no way to access SRB2Fun), that'd be much appreciated.

And one for the ice flower, how can I have the color change back to the color the player was originally when they're hit (like the fire flower), since as of the latest version it changes their color to the player skin's prefcolor. Also, I want the ice flower to disappear when the bot picks it up (yes, I want the bot to use it, too)
EDIT: Ice flower fixed... forget that bit.
 
Last edited:
havent posted in awhile, but i have another problem:
Code:
//Now the Command and function

local function P_ReturnValidColour(color)
	if(color)
		if(color == "white")
			return SKINCOLOR_WHITE
		elseif(color == "silver")
			return SKINCOLOR_SILVER
		elseif(color == "grey")
			return SKINCOLOR_GREY
		elseif(color == "black")
			return SKINCOLOR_BLACK
		elseif(color == "cyan")
			return SKINCOLOR_CYAN
		elseif(color == "teal")
			return SKINCOLOR_TEAL
		elseif(color == "steel_blue")
			return SKINCOLOR_STEELBLUE
		elseif(color == "blue")
			return SKINCOLOR_BLUE
		elseif(color == "peach")
			return SKINCOLOR_PEACH
		elseif(color == "tan")
			return SKINCOLOR_TAN
		elseif(color == "pink")
			return SKINCOLOR_PINK
		elseif(color == "lavender")
			return SKINCOLOR_LAVENDER
		elseif(color == "purple")
			return SKINCOLOR_PURPLE
		elseif(color == "orange")
			return SKINCOLOR_ORANGE
		elseif(color == "rosewood")
			return SKINCOLOR_ROSEWOOD
		elseif(color == "beige")
			return SKINCOLOR_BEIGE
		elseif(color == "brown")
			return SKINCOLOR_BROWN
		elseif(color == "red")
			return SKINCOLOR_RED
		elseif(color == "neon_green")
			return SKINCOLOR_NEONGREEN
		elseif(color == "green")
			return SKINCOLOR_GREEN
		elseif(color == "zim")
			return SKINCOLOR_ZIM
		elseif(color == "olive")
			return SKINCOLOR_OLIVE
		elseif(color == "yellow")
			return SKINCOLOR_YELLOW
		elseif(color == "gold")
			return SKINCOLOR_GOLD
		else
			return SKINCOLOR_RED
		end
	else
		return SKINCOLOR_RED
	end
end

COM_AddCommand("spawnpresent", function(player, arg1, arg2)
	if not arg1 then
		CONS_Printf(player, "\"spawnpresent <objecttype> <optional colour>\": spawn a present in front of you with an object inside.")
	else
		if EvalMath(arg1) then
			local present = P_SpawnMobj(player.mo.x+FixedMul(40*FRACUNIT, cos(player.mo.angle)),
						player.mo.y+FixedMul(40*FRACUNIT, sin(player.mo.angle)), player.mo.z, MT_PRESENT)
			present.angle = player.mo.angle
			if not arg2 then
				present.color = SKINCOLOR_RED
			else
				present.color = P_ReturnValidColour(arg2)
			end
			if not present.contains then present.contains = EvalMath(arg1) end
			CONS_Printf(player, "Successfully spawned a present in front of you!")
		else
			CONS_Printf(player, "The console threw an error. Fix that error and try again.")
		end
	end
end)

//thinkframe for helping with the present unwrapping
addHook("ThinkFrame", do
	for player in players.iterate
		if not player.mo then return end
		if not (player.mo.presenthelper and player.mo.presenthelper.valid)
			player.mo.presenthelper = P_SpawnMobj(player.mo.x+FixedMul(50*FRACUNIT, cos(player.mo.angle)),
						player.mo.y+FixedMul(50*FRACUNIT, sin(player.mo.angle)), player.mo.z, MT_GFZFLOWER1)
			player.mo.presenthelper.flags2 = $1|MF2_DONTDRAW
			player.mo.presenthelper.flags = $1|MF_NOCLIP|MF_NOCLIPHEIGHT
			player.mo.presenthelper.tracer = player.mo
		elseif (player.mo.presenthelper and player.mo.presenthelper.valid)
			P_TeleportMove(player.mo.presenthelper, player.mo.x+FixedMul(50*FRACUNIT, cos(player.mo.angle)),
						player.mo.y+FixedMul(50*FRACUNIT, sin(player.mo.angle)), player.mo.z)
		end
	end
end)

//function on how it'll work
addHook("MobjCollide", function(flower, present)
	if (flower.type == MT_GFZFLOWER1) //is the collider a flower?
	and (flower.tracer and flower.tracer.valid) //and it has a tracer?
	and (flower.tracer.player) //and the tracer is a player?
		if (flower.tracer.player.cmd.buttons & BT_CUSTOM3) then //pressing custom 3?
			P_SpawnMobj(present.x, present.y, present.z, MT_PRESENTSMOKE)
			local gift = P_SpawnMobj(present.x, present.y, present.z, EvalMath(present.contains))
			gift.angle = present.angle
			P_RemoveMobj(present)
		end
	end
end, MT_PRESENT)

I think Its the mobjcollide that isnt working... I press custom 3 and nothing happens. Am I doing anything wrong?

edit: FIXED. disregard this post
 
Last edited:
Status
Not open for further replies.

Who is viewing this thread (Total: 0, Members: 0, Guests: 0)

Back
Top