need help ' onUseItem '

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Pandafox
Posts: 268
Joined: Wed Apr 11, 2012 11:25 pm
Location: France
Contact:

need help ' onUseItem '

Post by Pandafox »

hi,

I'm trying to make a special item which create a teleporter when use it.
I tried and tried many different methods but I can't find how to... :?

I think I must use the onUseItem function in the defineObject but it don't works.... please help :mrgreen:
User avatar
crisman
Posts: 305
Joined: Sat Sep 22, 2012 9:23 pm
Location: Italy

Re: need help ' onUseItem '

Post by crisman »

I think it should be something like:

onUseItem = function (self, champ)

party:setPosition(X, Y, F, L)
--where X and Y are the coordinates, F is facing, and L is the level.
return true
--return false if you don't want the item to be consumed after using it
end

EDIT: if it works it will be without the teleport graphical effects, if you want them I'll show you how to add them.
User avatar
Komag
Posts: 3654
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: need help ' onUseItem '

Post by Komag »

setPosition does not press the pressure plate of the destination, and may have other side effects I don't know about, so make sure it works well enough for you. If it's not going to work you might need to spawn a teleporter and also spawn a short timer to later destroy the teleporter and destroy itself
Finished Dungeons - complete mods to play
User avatar
crisman
Posts: 305
Joined: Sat Sep 22, 2012 9:23 pm
Location: Italy

Re: need help ' onUseItem '

Post by crisman »

I think setPosition is used for the teleport entity itself.
For the pressure plate that's not true, they will be pressed. But you''re right about the side effects (I know them well since I'm working on a co-op based dungeon and those problems gave me a lot of trouble at the beginning :lol: )
If a script with setPosition is used while falling or changing floor, it will glitch and teleport you up or down depends if you use them on stairs or while falling into a pit.
So if you are not confident, just do as Komag said.
User avatar
Komag
Posts: 3654
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: need help ' onUseItem '

Post by Komag »

I could swear I recently tested setPosition onto a plate and it didn't get pressed until I first stepped off and then on again. Maybe I'm remembering wrong, or maybe there was some circumstance that affected it
Finished Dungeons - complete mods to play
User avatar
crisman
Posts: 305
Joined: Sat Sep 22, 2012 9:23 pm
Location: Italy

Re: need help ' onUseItem '

Post by crisman »

Interesting, if there are some weird things regarding pressure plates I'd like to know it. :)
I bumped my head so hard to solve the stairs-pits glitch (I cannot figure out how to know when the party is changing level by falling/using stairs, so I had to do a walkaround)...
But I'm trying several times, there seems to be no problem regarding pressure plate, each time I'm swapping team, the plate is always pressed :D
User avatar
Pandafox
Posts: 268
Joined: Wed Apr 11, 2012 11:25 pm
Location: France
Contact:

Re: need help ' onUseItem '

Post by Pandafox »

thanks for the answers, but my problem is not exactly how to spawn a teleporter or how to teleport the party...
The problem is more... more stupid I think.... :oops:
I don't know how to make the onUseItem active.

I create an item like that :

Code: Select all

defineObject {
		name = "chaos_staff",
		class = "Item",
		uiName = "Chaos staff",
		model = "mod_assets/models/cs.fbx",
		description = "The legendary Chaos staff. Only this staff can defeat the Dark Soul.",
		gfxAtlas = "mod_assets/textures/cs.tga",
		gfxIndex = 4,
		weight = 6.66,
        	onUseItem = function(self, champion)
                        print ( "ok" )
			playSound("consume_potion")
			return true
		end,
}
But when I use it in game (right click) nothing at all happend.... :shock:
User avatar
Komag
Posts: 3654
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: need help ' onUseItem '

Post by Komag »

there shouldn't be a space after print and before the (
print("ok")

Also, you could try the party onUseItem version, and just require that the item.name be "chaos_staff" before it does the things
Finished Dungeons - complete mods to play
Ixnatifual

Re: need help ' onUseItem '

Post by Ixnatifual »

Try hudPrint instead. I think print only writes to the console?
User avatar
Pandafox
Posts: 268
Joined: Wed Apr 11, 2012 11:25 pm
Location: France
Contact:

Re: need help ' onUseItem '

Post by Pandafox »

That's ok, I found a solution :)

My chaos staff can create teleporters (which are not teleporters in fact, but I can't tell more) ;)
Now I'm trying to create a timer by script (at the same time it creates a teleporter) to destroy this teleporter after few seconds...
hard brainworking...... :mrgreen:
Post Reply