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 » Sat Feb 02, 2013 5:51 pm

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 » Sat Feb 02, 2013 7:43 pm

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: 3637
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: need help ' onUseItem '

Post by Komag » Sat Feb 02, 2013 8:27 pm

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 » Sat Feb 02, 2013 11:53 pm

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: 3637
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: need help ' onUseItem '

Post by Komag » Sun Feb 03, 2013 2:12 am

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 » Sun Feb 03, 2013 2:56 am

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 » Sun Feb 03, 2013 12:38 pm

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: 3637
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: need help ' onUseItem '

Post by Komag » Sun Feb 03, 2013 1:12 pm

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

User avatar
Ixnatifual
Posts: 731
Joined: Mon Apr 16, 2012 5:23 pm

Re: need help ' onUseItem '

Post by Ixnatifual » Sun Feb 03, 2013 3:38 pm

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 » Sun Feb 03, 2013 3:52 pm

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