Page 1 of 2

need help ' onUseItem '

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

Re: need help ' onUseItem '

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

Re: need help ' onUseItem '

Posted: Sat Feb 02, 2013 8:27 pm
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

Re: need help ' onUseItem '

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

Re: need help ' onUseItem '

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

Re: need help ' onUseItem '

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

Re: need help ' onUseItem '

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

Re: need help ' onUseItem '

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

Re: need help ' onUseItem '

Posted: Sun Feb 03, 2013 3:38 pm
by Ixnatifual
Try hudPrint instead. I think print only writes to the console?

Re: need help ' onUseItem '

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