freeslot("sfx_statu2", "sfx_bkpoof", "sfx_mswing")

addHook("PlayerThink", function(player) //Adds a PlayerThink hook.
		if (player.mo and player.mo.skin == "gargoyle") //Change "skinname" to the character's skin you want to use.
		and not (player.powers[pw_carry] & CR_NIGHTSMODE) then //Do not intefere with nights, it may crash the game.
			//Infinite breath in water and space
			player.powers[pw_underwater] = 1073741824
			player.powers[pw_spacetime] = 1073741824
			if not player.mo.footsteptimer //If the variable "footsteptimer" doesn't exist,
				player.mo.footsteptimer = 0 //Create the variable.
			end // End this block
                        //Gargoyle is a pushable object when he's on the ground and alive. He can also break bustable blocks.
		        if P_IsObjectOnGround(player.mo)
                        and not (player.playerstate & PST_DEAD) //Prevents game crash when falling in pit while in pushable state
						and not (player.panim & PA_ROLL) //This fixes the glitch where the gargoyle needs to jump twice.
				player.mo.flags = $1|MF_PUSHABLE
                                player.charability = CA_GLIDEANDCLIMB
			else
				player.mo.flags = $1 & ~MF_PUSHABLE
                                player.charability = CA_FLOAT
			end
                        if player.powers[pw_super]
                                player.charability = CA_FLOAT
                        end
			if player.mo.footsteptimer <= 7 then
				player.mo.footsteptimer = $ + 1	//Continously increase footsteptimer, make sure it can never reach above 8
			end
			if player.speed != 0
			and P_IsObjectOnGround(player.mo) //Will make sure you aren't making the noise while airborne.
			and (player.mo.footsteptimer >= 8) then //If a fourth of a second has pas sed since the last step sound,
				S_StartSound(player.mo, sfx_statu2) //Replace "soundname" with whatever the sound name is, removing "DS" from the beginning.
				player.mo.footsteptimer = 0 //Reset the foostep timer.
			end //End this block.
		end //End the player and nightsmode check block
end) //Finish the hook.
//You don't get to be pushable if you're not Gargoyle.
addHook("PlayerThink", function(player) //Adds a ThinkFrame hook.
		if (player.mo) then
			if not (player.mo.skin == "gargoyle") then
				player.mo.flags = $1 & ~MF_PUSHABLE
			end
		end
end)
//Immunity to fire!
addHook("ShouldDamage", function(target, inflictor, source, damage)
	// I am immune to fiery things
	if (target.skin == "gargoyle")
		// Fire objects
		if (inflictor and inflictor.flags & MF_FIRE) or (source and source.flags & MF_FIRE)
			return false
		end
		// Lava
		if not inflictor and not source and P_PlayerTouchingSectorSpecial(target.player, 1, 3)
			return false
		end
	end
end, MT_PLAYER)

//MI's code, Gargoyle can't grab air bubbles
local function DontTouchThis(bubb, garg)
	if garg.skin == "gargoyle" then
		return true
	end
end
addHook("TouchSpecial", DontTouchThis, MT_EXTRALARGEBUBBLE)
//Copy-pasted from wiki example, just changed a few terms.
addHook("PlayerThink", function(player)
                if player.mo.skin != "gargoyle" then
					return
                end
                if player.rings >= 100
                and not player.nukepressed
                        player.nukeready = true
                        player.nuking = false
                elseif player.mo.health <= 100
                and not player.nukepressed
                        player.nukeready = false
                elseif player.nukeready
                and player.nukepressed
                        player.nuking = true
                        player.nukeready = false
                else
                        player.nuking = false
                end                
                if player.nuking then
                        P_NukeEnemies(player.mo, player.mo, 1536*FRACUNIT)
                        player.rings = $ - 100
                        S_StartSound(player.mo, sfx_bkpoof)
                end
                if (player.cmd.buttons & BT_CUSTOM3)
                        player.nukepressed = true
                else
                        player.nukepressed = false
                end
end)

addHook("PlayerThink", function(player)
                if player.mo.skin != "gargoyle" then
                        return
                end
                if player.rings >= 20
                and (player.pflags & PF_JUMPED)
                and not P_IsObjectOnGround(player.mo)
                and not (player.cmd.buttons & BT_CUSTOM2) then
                        player.jumpready = true
                        player.jumping = false
                elseif player.rings <= 19
                and not (player.pflags & PF_JUMPED)
                and P_IsObjectOnGround(player.mo)
                        player.jumpready = false
                elseif player.jumpready
                and not P_IsObjectOnGround(player.mo)
                and (player.cmd.buttons & BT_CUSTOM2) then
                        player.jumping = true
                        player.jumpready = false
                else
                        player.jumping = false
                end                
                if player.jumping then
                                player.mo.momz = 32*FRACUNIT
                                player.rings = $ - 20
                                S_StartSound(player.mo, sfx_mswing)
                end
end)
