reusable torch. (lantern)

Post » Wed Jun 20, 2012 1:38 pm

im looking for a little advice from you guys again.......

im making an oil burning lantern, and all i have left to do is make the lantern reusable.

ill be referring to the lantern as a torch as it is just a modified version of the LIGH object torch01.

i have two models for the lantern, ON and OFF. ive already got the crafting and refilling sorted out, but how would i go about swapping the ON lantern model for the OFF lantern model when the torch timer runs out?

im terrible at scripting, i have tried to get to grips with papyrus but there is too much information missing from the tutorials at the CK wiki. i just get lost within a few minutes......

if there are any skilled scripters out there who would be willing to try making this script i would be very grateful, but id be just as happy if someone showed me how to make it myself!



thanks guys.
User avatar
Astargoth Rockin' Design
 
Posts: 3450
Joined: Mon Apr 02, 2007 2:51 pm

Post » Wed Jun 20, 2012 12:52 pm

also, whats going on with the torch inventory icon?

the only object in the inventory that cant be moved or rotated?!

this makes me sad.
User avatar
Andrew Perry
 
Posts: 3505
Joined: Sat Jul 07, 2007 5:40 am

Post » Wed Jun 20, 2012 12:18 pm

http://www.creationkit.com/OnUnequipped_-_ObjectReference

;TorchOff should be the ID of the off version, obviously.ObjectReference property TorchOff autoEvent onUnequipped(actor akActor)	akActor.equipitem(TorchOff, false, true)Endevent

Attach this to your "on" torch.
It works for NPCs too, if you want it to only work for the player, add the player check from the wiki page.

Edit: Lights might not be "objectreference", I haven't really done much with adding/removing stuff from the player's inventory.
User avatar
Brittany Abner
 
Posts: 3401
Joined: Wed Oct 24, 2007 10:48 pm

Post » Thu Jun 21, 2012 12:53 am

seventyfour wins a magic bean.

and some kudos.

thanks mate :biggrin:
User avatar
Code Affinity
 
Posts: 3325
Joined: Wed Jun 13, 2007 11:11 am

Post » Wed Jun 20, 2012 9:21 pm

hmm, just tested that out, and it compiles no problem. but has no effect.

i also have a feeling this script will kick in every time you unequip the lantern to switch to a shield or off hand weapon.

also if i make it focus on when the item is removed from my inventory instead of when it is uneqiupped, the script will kick in every time the player drops the lit lantern.

i feel a headache coming on......

EDIT. I should learn how to read edits!
User avatar
Patrick Gordon
 
Posts: 3366
Joined: Thu May 31, 2007 5:38 am

Post » Thu Jun 21, 2012 1:50 am

Oh, right, try this then:
;TorchOff should be the ID of the off version, obviously.ObjectReference property TorchOff autoint time = 240int counting = 0Event OnEquipped(Actor akActor)	RegisterForSingleUpdate(1.0)EndeventEvent OnUpdate()	;true = get from left hand	if ( akActor.GetEquippedWeapon(true) == self )		;One second has passed with the item equipped, count it		counting += 1		if ( counting < time )			;The torch hasnt run out, update again			RegisterForSingleUpdate(1.0)		else			;The torch has run out, replace it with the off one			  akActor.additem(TorchOff, 1, true)			akActor.equipitem(TorchOff, false, true)			akActor.removeitem(self)		endif	endifEndEvent

240 seconds is the default torch time, but tou might want to set the torch length to infinite and just let the script remove it, to avoid any oddities with the counting being inaccurate.
If it can't compile because "akActor" doesn't exist on line 13, you might have to put akActor into a property outside of the OnEquipped event.
If it compiles but just doesn't "work", then maybe torches aren't detected by "GetEquippedWeapon", and then I have no idea what you should do.
I haven't tested it again but it might give you an idea of how it should work...
User avatar
Alyce Argabright
 
Posts: 3403
Joined: Mon Aug 20, 2007 8:11 pm

Post » Wed Jun 20, 2012 2:31 pm

Scriptname lanternburnout extends ObjectReference Light Property Torch01LANTERNOFF autoEvent onUnequipped(actor akActor)akActor.additem(Torch01LANTERNOFF, 1, true)akActor.equipitem(Torch01LANTERNOFF, false, true)Endevent

this is what ive got now but it still isnt working.

EDIT: thanks, ill try that now!
User avatar
Rhi Edwards
 
Posts: 3453
Joined: Fri Jul 28, 2006 1:42 am

Post » Wed Jun 20, 2012 8:27 pm

i added the akactor property and it fails compilation on this now:

c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\lanternburnout.psc(15,37): cannot compare a weapon to a lanternburnout (cast missing or types unrelated)

any ideas?

EDIT: its the getequippedweapon line. it would appear you are right, torches arent recognised as weapons. i tried replacing "weapon" with "shield" and got a fail:


c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\lanternburnout.psc(15,13): too many arguments passed to function
User avatar
Tiff Clark
 
Posts: 3297
Joined: Wed Aug 09, 2006 2:23 am

Post » Wed Jun 20, 2012 10:49 am

Remove "true" from the parentheses? but keep it as "getequippedshield", that argument is only for getting weapons. Since the shield can only be equipped in the left hand, getquippedshield doesn't have any arguments.

Edit: Why can't we make left-handed characters!? If I was left-handed it would ruin my immersion! :tongue:

Also, I know you said you made akActor a property, but what I meant was make it a property with a different name, like:
Actor property torchuser

Then fill it in the OnEquipped block like:
torchuser = akActor

Then change every instance of akActor in the OnUpdate block to torchuser.

The reason you might need to do this is because akActor may only be accessible by code in the OnEquipped event.


Edit 2:
http://www.creationkit.com/GetEquippedItemType_-_Actor might be useful as well, if you can't get the torch itself as a shield.

You could replace
GetEquippedShield() == self
with
GetEquippedItemType(0) == 11

And it would work for sure, but the problem is if you have more than one torch in your inventory it's going to remove them all when one of them runs out. I think. Or weird stuff will happen if you switch to another torch without unequipping the current one. I'm not completely sure though, so you can try it.

Edit 3 AGAIN:
If you use GetEquippedItemType, you can try adding an OnUnequipped block with UnregisterForUpdate in it:
Event OnUnequipped(Actor akActor)    UnregisterForUpdate()Endevent
That would hopefully stop it from updating for itself again if you switched to a different torch.
User avatar
Ricky Rayner
 
Posts: 3339
Joined: Fri Jul 13, 2007 2:13 am

Post » Wed Jun 20, 2012 6:03 pm

i am left handed, and yes it really annoys me that everything is backwards in my game!!!


New error this time:

c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\lanternburnout.psc(16,13): GetEquippedshield is not a property on script actor or one of its parents

EDIT: forgot the parentheses.

getting this again now:


c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\lanternburnout.psc(16,33): cannot compare a armor to a lanternburnout (cast missing or types unrelated)
User avatar
SaVino GοΜ
 
Posts: 3360
Joined: Mon Sep 17, 2007 8:00 pm

Post » Wed Jun 20, 2012 10:50 pm

Try the thing I suggested in my previous post then; Replacing GetEquippedShield with GetEquippedItemType and adding the OnUnequipped block.
User avatar
Khamaji Taylor
 
Posts: 3437
Joined: Sun Jul 29, 2007 6:15 am

Post » Wed Jun 20, 2012 6:18 pm

Scriptname lanternburnout extends ObjectReference Light property Torch01LANTERNOFF autoActor property akActor autoint time = 240int counting = 0Event OnEquipped(actor akActor)RegisterForSingleUpdate(1.0)EndeventEvent OnUpdate();true = get from left handif (akActor.GetEquippedItemType(0) == 11 );One second has passed with the item equipped, count itcounting += 1if ( counting < time );The torch hasnt run out, update againRegisterForSingleUpdate(1.0)else;The torch has run out, replace it with the off oneakActor.additem(Torch01LANTERNOFF, 1, true)akActor.equipitem(Torch01LANTERNOFF, false, true)akActor.removeitem(self)endifendifEndEventEvent OnUnequipped(actor akActor)UnregisterForUpdate()Endevent


Using this it has compiled! im about to test it in game.

i tried the torchuser thing, and it kept spitting out errors about torchuser being undefined?
User avatar
Mark
 
Posts: 3341
Joined: Wed May 23, 2007 11:59 am

Post » Wed Jun 20, 2012 5:35 pm

still doesnt seem to have any effect. i shortened the time to 24 instead of 240 just for testing purposes, and set the torch timer to 300 seconds ( i dont know how to make it infinite )

nothing happens at 24 seconds. i dont know how to do it but could i add some sort of debug message to test if the script is even working?
User avatar
hannaH
 
Posts: 3513
Joined: Tue Aug 15, 2006 4:50 am

Post » Wed Jun 20, 2012 12:20 pm

still doesnt seem to have any effect. i shortened the time to 24 instead of 240 just for testing purposes, and set the torch timer to 300 seconds ( i dont know how to make it infinite )

nothing happens at 24 seconds. i dont know how to do it but could i add some sort of debug message to test if the script is even working?

debug.messagebox("Test")

I'll try testing it myself and post again.
User avatar
Penny Courture
 
Posts: 3438
Joined: Sat Dec 23, 2006 11:59 pm

Post » Wed Jun 20, 2012 11:21 pm

Okay, well I re-wrote it to be like this:
Spoiler

Scriptname aaTorchSwapper extends objectreferenceLight property Torch01_test_off autoActor property torchuser autoint timeout = 24;0int count = 0Event OnEquipped(actor akActor)	torchuser = akActor	debug.notification("torchuser is "+torchuser)	RegisterForUpdate(1)EndeventEvent OnUpdate()	debug.notification("Updating")		if ( torchuser.GetEquippedItemType(0) == 11 )		debug.notification("User is carrying torch, "+count as int+" seconds have passed.")		;One second has passed with the item equipped, count it		count += 1		if ( count >= timeout )			;Timeout reached, torch runs out.			debug.notification("Torch ran out, swapping to the other one.")			;Stop updating			UnregisterForUpdate()			;The torch has run out, replace it with the off one			torchuser.additem(Torch01_test_off, 1, true)			torchuser.equipitem(Torch01_test_off, false, true)			torchuser.removeitem(self)		endif	else		;User unequipped the torch?		UnregisterForUpdate()	endif	EndEventEvent OnUnequipped(actor akActor)	debug.notification("User stopped carrying the torch, not updating again.")	;User unequipped this torch.	UnregisterForUpdate()Endevent

But the stuff in OnUpdate is never processed even after being registered for update. I have no idea why, so hopefully someone else will know why...

Edit 2:
Sorry that I'm nearly "hijacking" your mod, but I'm a perfectionist and can't let something like this go...
Here's a fully working version that doesn't use the onupdate block. I tested it and it works.
Spoiler

Scriptname aaTorchSwapper extends objectreference;fill the first one with the on light, and the second one with the off lightLight property Torch01_test_on autoLight property Torch01_test_off autoActor property torchuser autoint timeout = 10 ;240int count = 0bool updating = falseEvent OnEquipped(actor akActor)	;make torchuser the actual torch user	torchuser = akActor	;User equipped this torch, start updating	updating = true		while ( updating == true )		;Wait 1 second on each update		utility.wait(1)		if ( torchuser.GetEquippedItemType(0) == 11 )			;One second has passed with the item equipped, count it			count += 1			if ( count >= timeout )				;Torch ran out, stop udating and replace it				updating == false				torchuser.additem(Torch01_test_off, 1, true)				torchuser.equipitem(Torch01_test_off, false, true)				torchuser.removeitem(Torch01_test_on, 1, true)			endif		else			;User unequipeed the torch?			updating = false		endif	endwhile	EndeventEvent OnUnequipped(actor akActor)	;User unequipped the torch.	updating = falseEndevent
User avatar
darnell waddington
 
Posts: 3448
Joined: Wed Oct 17, 2007 10:43 pm

Post » Wed Jun 20, 2012 11:03 pm

thats cool mate, you already achieved alot more than i ever would have, so thanks for being so helpful!

if anybody else has any thoughts, feel free to chip in!
User avatar
OTTO
 
Posts: 3367
Joined: Thu May 17, 2007 6:22 pm

Post » Thu Jun 21, 2012 1:31 am

thats cool mate, you already achieved alot more than i ever would have, so thanks for being so helpful!

if anybody else has any thoughts, feel free to chip in!

Well, I just edited my post with a working version - I tested it. :lmao:
User avatar
SamanthaLove
 
Posts: 3565
Joined: Mon Dec 11, 2006 3:54 am

Post » Wed Jun 20, 2012 11:46 am

:biggrin: sorry im not keeping up with the edits!

just testing it now....
User avatar
Cat
 
Posts: 3451
Joined: Mon Dec 18, 2006 5:10 am

Post » Thu Jun 21, 2012 12:05 am

should i change the 240 in the time section to 24 to speed up testing? i dont know what the 10 ;240 means :blush:
User avatar
M!KkI
 
Posts: 3401
Joined: Sun Jul 16, 2006 7:50 am

Post » Wed Jun 20, 2012 9:25 pm

thats cool mate, you already achieved alot more than i ever would have, so thanks for being so helpful!

if anybody else has any thoughts, feel free to chip in!

My suggestion:

Spoiler
Scriptname SomeScript extends ReferenceAlias ;or ActiveMagicEffectLight property Lantern_On autoLight property Lantern_Off autoActor PlayerInt LanternCountEvent OnInit()	Player = Game.GetPlayer()EndEventEvent OnObjectEquipped(Form akBaseObject, ObjectReference akReference)	if (akBaseObject == Lantern_On)		LanternCount = Player.GetItemCount(Lantern_On)	endifEndEventEvent OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)	if (akBaseObject == Lantern_On)		if (LanternCount > Player.GetItemCount(Lantern_On)			Player.AddItem(Lantern_Off, 1, True)			Player.EquipItem(Lantern_Off, False, True)		endif	endifEndEvent
User avatar
lilmissparty
 
Posts: 3469
Joined: Sun Jul 23, 2006 7:51 pm

Post » Wed Jun 20, 2012 5:33 pm

should i change the 240 in the time section to 24 to speed up testing? i dont know what the 10 ;240 means :blush:

; means it's a comment and everything after ; is ignored... I set it to 10 to make testing quick, but you should set it to whatever you want. If you want them to last as long as vanilla, then 240.
User avatar
Solène We
 
Posts: 3470
Joined: Tue Mar 27, 2007 7:04 am

Post » Wed Jun 20, 2012 11:40 am

@RandomNoob

i tried your script, i had to add a missing parenthesis to the end of line 21 to get it to compile. unfortunately it didnt work as it should. im starting to think my lantern isnt being recognised as a torch or something...

@seventyfour

if i zip up this esp can you try connecting your script to the two lantern objects and try running it in your game?

you seem to be able to get the script to run, im wondering if a mod im running is interfering with the script.....
User avatar
Sxc-Mary
 
Posts: 3536
Joined: Wed Aug 23, 2006 12:53 pm

Post » Wed Jun 20, 2012 2:49 pm

@RandomNoob

i tried your script, i had to add a missing parenthesis to the end of line 21 to get it to compile. unfortunately it didnt work as it should. im starting to think my lantern isnt being recognised as a torch or something...

@seventyfour

if i zip up this esp can you try connecting your script to the two lantern objects and try running it in your game?

you seem to be able to get the script to run, im wondering if a mod im running is interfering with the script.....

Yep.
User avatar
Mistress trades Melissa
 
Posts: 3464
Joined: Mon Jun 19, 2006 9:28 pm

Post » Wed Jun 20, 2012 9:43 pm

its alright, i just realised i was being an idiot! the new script wasnt being applied to the old lantern in my inventory.

spawning a new lantern made it work perfectly.

Hats off to you seventyfour, i shall give you credit in the release details of the mod! :banana:

Thanks randomnoob too for giving a perfectly reasonable input into the discussion!
User avatar
Gracie Dugdale
 
Posts: 3397
Joined: Wed Jun 14, 2006 11:02 pm


Return to V - Skyrim