Problem with Touchspecial

Status
Not open for further replies.

SSG3

Oh, THAT Youtuber...
Another LUA problem while trying to code a custom ice flower (and ice ball) powerup. This is the "TouchSpecial" hook which, when you collect an ice flower, enables you to fire ice balls with FIRENORMAL (or Ring Toss Normal in-game).

So, on with the code:
Code:
addHook("TouchSpecial", giveicepower(MT_ICEFLOWER, player), 1046)
	for player in players.iterate
		if player.mo 
		and not (player.spectator)
		and not (player.pflags & PF_NIGHTSMODE)
		and not (player.mo.state == S_PLAY_DIE)
			if player.iceflowershoot == 0
				player.iceflowershoot = 1
			end
			player.skincolor = SKINCOLOR_TEAL
		end
	end
end

This gives me, when I load it in SRB2, "WARNING: iceflower.wad/LUA_ICEY: 29 (basically the last "end"): '<eof>' expected near "end". What should I do?
 
Okay, first thing's first, MT_ICEFLOWER is an object type number, not a valid name for a variable representing an object. Second, what on earth is "1046"? There are a few other glaring problems with your script, so perhaps it may be easiest to explain from the beginning how addHook works...

BASICS:

The format of addHook with the "TouchSpecial" hook is such:
Code:
addHook("TouchSpecial", FunctionName, MT_OBJECTTYPE)

MT_OBJECTTYPE is the object type to touch that you want to apply the function for. "FunctionName" here can be a function as such:

Code:
local function FunctionName(special, toucher)
	-- insert code here
end

addHook("TouchSpecial", FunctionName, MT_OBJECTTYPE)

OR be a implicit function defined within the addHook function itself, as you and other people do a lot for some reason (in this case "FunctionName" doesn't get to have an actual name, it's just known as "function"):

Code:
addHook("TouchSpecial", function(special, toucher)
	-- insert code here
end, MT_OBJECTTYPE)

In both the above cases, "special" and "toucher" are example names for variables representing the touched object with MF_SPECIAL and the touching object. The latter is not the player directly (I'll explain how to get the player below).

ADDING YOUR CODE IN:

Now, assuming you want your object type to be called MT_ICEFLOWER, this should be placed where "MT_OBJECTTYPE" is above.

Next of all, if you want only the player that touched the object (rather than all players in the game) to be used in your code, you can set a new variable called "player" to the value of "toucher.player". Readjusting your code, you should be doing this:

Code:
addHook("TouchSpecial", function(special, toucher)
	local player = toucher.player
	if not (player.spectator)
	and not (player.pflags & PF_NIGHTSMODE)
	and not (player.mo.state == S_PLAY_DIE)
		if player.iceflowershoot == 0
			player.iceflowershoot = 1
		end
		player.skincolor = SKINCOLOR_TEAL
	end
end, MT_ICEFLOWER)

Hopefully this should help you understand things better somewhat.
 
Last edited:
1046 is the MT_ICEFLOWER's mapthingnum, so don't get confused by that. I tried out your code, and the console game me "WARNING: mobjtype MT_ICEFLOWER does not exist!" when it does exist as a custom object, coded through SOC. Any help on that?

EDIT: Added before the hook "freeslot("MT_ICEFLOWER")" and it worked. Thanks.

EDIT2: Collecting the Ice Flower doesn't change my skin color to SKINCOLOR_TEAL. Any help?

EDIT3: Nevermind. I fixed it myself to player.mo.color instead.
 
Last edited:
Status
Not open for further replies.

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

Back
Top