need scripting help

Post » Sat May 28, 2011 2:22 am

I'm trying to make a dummy torch that runs a script when it is equipped. The idea is to have this dummy torch hot-keyed to were i usually have my torch hot-keyed to and it will "fake toggle" or unequip my torch.

Spoiler
begin Mf_TorchToggleshort OnPcEquipIf ( OnPcEquip == 1 )	if ( player->HasItemEquipped, torch == 1 )		player->additem, "Mf_shield" 1			;a weightless shield		player->equip, "Mf_shield"				;unequips torch in the process		player->removeitem, "Mf_shield" 1		return	else		player->equip, "torch"	endifendifend Mf_TorchToggle


This doesn't do anything in game accept equip my fake torch. It just plays the holding torch animation.
User avatar
Alex [AK]
 
Posts: 3436
Joined: Fri Jun 15, 2007 10:01 pm

Post » Sat May 28, 2011 1:24 am

player->additem, "Mf_shield" 1 ;a weightless shield
player->equip, "Mf_shield" ;unequips torch in the process
player->removeitem, "Mf_shield" 1


This kinda looks like your removing the item you just equipped....

EDIT: Why not make a nearly weightless shield with a constant light enchantment on it?
User avatar
CYCO JO-NATE
 
Posts: 3431
Joined: Fri Sep 21, 2007 12:41 pm

Post » Fri May 27, 2011 10:04 pm

Equipping a shield un-equips torches, but I don't want the shield to stay in my inventory.

The reason I'm making this script is for when im playing a charater that doesn't use shields or 2 handed weapons. I just want to be able to equip/un-equip a torch with 1 button. Instead of having to pull up the inventory menu, select the torch then drag and drop it back in the inventory, and then close the menu.
User avatar
Catherine N
 
Posts: 3407
Joined: Sat Jan 27, 2007 9:58 pm

Post » Fri May 27, 2011 8:00 pm

I tried putting this script on a ring

Spoiler
begin Mf_TorchToggleShort OnPcEquipIf ( OnPcEquip == 1 )	set OnPcEquip to 0	If ( player->HasItemEquipped, torch == 1 )		player->additem, "Mf_shield" 1			;a weightless shield		player->equip, "Mf_shield"				;unequips torch in the process		player->removeitem, "Mf_shield" 1		return	else		player->equip, "torch"		return	endifendifend Mf_TorchToggle


This script doesn't do anything, and i now even if it did work I would have to unequip the ring which is kind of counter productive to what im doing. Im not sure if you can remove an item that has it's script running on it at the same time.

Anyway, if I put this next script on the ring,

Spoiler
begin Mf_TorchToggleShort OnPcEquipIf ( OnPcEquip == 1 )	set OnPcEquip to 0	player->equip, "torch"endifend Mf_TorchToggle


when I equip the scripted ring it equips a torch like its supposed to. Does the line "If ( player->HasItemEquipped, torch == 1 )" not work for torches? It works for belts according to the UESP.
User avatar
Stay-C
 
Posts: 3514
Joined: Sun Jul 16, 2006 2:04 am

Post » Sat May 28, 2011 7:11 am

Equipping a shield un-equips torches, but I don't want the shield to stay in my inventory.

The reason I'm making this script is for when im playing a charater that doesn't use shields or 2 handed weapons. I just want to be able to equip/un-equip a torch with 1 button. Instead of having to pull up the inventory menu, select the torch then drag and drop it back in the inventory, and then close the menu.


Hmmm.. How about you use a hotkey?

Press F1, click on a number (say, 1?) and select the mundane item you want to equip. You will instantly equip that item by pressing 1 (if you aren't attacking at that particular moment), allowing you to avoid the inventory nearly entirely.
User avatar
Cesar Gomez
 
Posts: 3344
Joined: Thu Aug 02, 2007 11:06 am

Post » Sat May 28, 2011 1:55 am

Yes, I know how to hot-key an item. I have torches set to 1, but pressing that button again doesn't unequip the torch. That's why im wanting to hot-key some type of item that runs a script when it's equiped to check and see if I have a torch equiped, if I do have a torch equiped it would unequip the torch (equip the weightless shield then remove the shield), or if I didn't have a torch equiped when the script is ran, the script would equip a torch for me.
User avatar
Poetic Vice
 
Posts: 3440
Joined: Wed Oct 31, 2007 8:19 pm

Post » Sat May 28, 2011 8:52 am

What you're doing isn't possible how you're doing it, I don't think. Because the original torch gets unequipped, your check fails.

Now, the additem/equip/removeitem snippet that Era quoted is the standard and recommended way of unequipping an item without MWSE, and does that fine.

However, what you want to do in this case is a bit backwards. I'm not sure how it will interact with hot-keys, but try this as a global script:
if ( "player"->GetItemEquipped "fake_torch" > 0 )
"player"->RemoveItem "fake_torch" 1
"player"->AddItem "fake_torch" 1
endif


When the player equips your fake torch, it will be unequipped (by being removed) and then added as a regular inventory item (leaving the slot empty). You could use a second item and the additem/equip/removeitem bit, but that seems unnecessarily complicated here. If the above snippet does break the hotkey, then you'll have to go that second route, which involves:
if ( "player"->GetItemEquipped "fake_torch" > 0 )
"player"->AddItem "empty_shield" 1
"player"->Equip "empty_sheild" 1
"player"->RemoveItem "empty_shield" 1
endif

Again, leaves you with an empty torch slot, but this time the hotkey won't get reset because the fake torch never leaves your inventory.
User avatar
Stephani Silva
 
Posts: 3372
Joined: Wed Jan 17, 2007 10:11 pm

Post » Fri May 27, 2011 10:20 pm

Ok, I made this global script (which is a start script, right?) and it didn't work.

Spoiler
begin Mf_TorchToggleIf ( player->hasItemEquipped, mf_ring > 0 )	player->removeItem, "mf_ring" 1	player->additem, "mf_ring" 1	if ( player->HasItemEquipped, torch > 0 )			player->additem, "mf_shield" 1			player->equip, "mf_shield"			player->removeitem, "mf_shield" 1			return	else			player->equip, "torch"			return	endif		endifend Mf_TorchToggle

User avatar
James Wilson
 
Posts: 3457
Joined: Mon Nov 12, 2007 12:51 pm

Post » Fri May 27, 2011 10:58 pm

For some reason the global script stops when it has to check for variables, or maybe i have the syntax wrong.

the ring script

begin Mf_ringscriptshort OnPcEquipIf ( OnPcEquip == 1 )	set OnPcEquip to 0	startscript, "Mf_torchtoggle"endifend Mf_ringscript


the global script

Spoiler
begin Mf_TorchToggleplayer->removeItem, "mf_ring" 1player->additem, "mf_ring" 1if ( player->HasItemEquipped "torch" > 0 )	player->additem, "BM_Ice minion_Shield1" 1	player->equip, "BM_Ice minion_Shield1"	player->removeitem, "BM_Ice minion_Shield1" 1else	player->equip, "torch"endifstopscript mf_torchtoggleendifend Mf_TorchToggle


this does nothing, but if I simplify it,,,

Spoiler
begin Mf_TorchToggleplayer->removeItem, "mf_ring" 1player->additem, "mf_ring" 1stopscript mf_torchtoggleendifend Mf_TorchToggle


this one works, it will remove/add the ring when ever i equip it.

When ever it gets to that first "if" line it just stops.

ps. btw, I don't loose the hot-key when the ring is removed/added. At least that works I guess.

EDIT:

I found out that "if ( player->HasItemEquipped "torch" > 0 )" doesnt work, or it doesn't work like i'm using it. If morrowind had a "GetItemEquipped" function, it would work.

LAST EDIT: solved (yay i can go to bed now)

added this script to torch
Spoiler
begin Mf_torchequippedshort OnPcEquipIf ( OnPcEquip == 1 )	set OnPcEquip to 0	set Mf_torch_global to 1endifend Mf_torchequipped


added this to the ring
Spoiler
begin Mf_ringscriptshort OnPcEquipIf ( OnPcEquip == 1 )	set OnPcEquip to 0	startscript, "Mf_torchtoggle"endifend Mf_ringscript


and finnaly added this global script

Spoiler
begin Mf_TorchToggleplayer->removeItem, "mf_ring" 1player->additem, "mf_ring" 1if ( Mf_torch_global > 0 )	player->additem, "BM_Ice minion_Shield1" 1	player->equip, "BM_Ice minion_Shield1"	player->removeitem, "BM_Ice minion_Shield1" 1	set Mf_torch_global to 0	else	player->equip, "torch"endifstopscript mf_torchtoggleendifend Mf_TorchToggle


Now, if the torch burns out while the global var is still set to 1 you just have to hit the hot-key 1 more time, no big deal. And there is a mild studder on all animations (lasts for a millisecond) when the script is ran. I spammed the hell out of the hot-key to see if it would crash but it didn't. Now I just need to make this compatible with TLM.

Thank you PK for the help!
User avatar
Lucy
 
Posts: 3362
Joined: Sun Sep 10, 2006 4:55 am

Post » Fri May 27, 2011 9:45 pm

IIRC equip adds an item if you do not have it already, but it does not update encumbrance, so you risk screwing your encumbrance if torch is gone, maybe it would be better
if ( player->GetItemCount "torch" == 0 )    player->AddItem "torch" 1endifplayer->equip "torch"

User avatar
Kelvin
 
Posts: 3405
Joined: Sat Nov 17, 2007 10:22 am

Post » Sat May 28, 2011 6:39 am

IIRC equip adds an item if you do not have it already, but it does not update encumbrance, so you risk screwing your encumbrance if torch is gone, maybe it would be better
if ( player->GetItemCount "torch" == 0 )    player->AddItem "torch" 1endifplayer->equip "torch"




You are right, I missed that. So I added a work around similar to yours, but it broke the script and it wont work now.

Spoiler
begin Mf_TorchToggleplayer->removeItem, "mf_ring" 1player->additem, "mf_ring" 1if ( Mf_torch_global > 0 )	player->additem, "BM_Ice minion_Shield1" 1	player->equip, "BM_Ice minion_Shield1"	player->removeitem, "BM_Ice minion_Shield1" 1	set Mf_torch_global to 0elseif ( player->getItemCount, "torch" > 0 )	player->equip, "torch"else	messagebox, "You do not have a torch."endifstopscript mf_torchtoggleend Mf_TorchToggle


It doesn't work at all now, and I have no idea why.

EDIT:

I changed the script to this

begin Mf_TorchToggleplayer->removeItem, "mf_ring" 1player->additem, "mf_ring" 1if ( Mf_torch_global > 0 )	player->additem, "BM_Ice minion_Shield1" 1	player->equip, "BM_Ice minion_Shield1"	player->removeitem, "BM_Ice minion_Shield1" 1	set Mf_torch_global to 0elseif ( Mf_torch_global < 0 )              <--------------------if I change < to <= or == it doesn't work at all, but it needs to be <= because this global will never be less than 0	if ( player->getItemCount, "torch" >= 1 )		player->equip, "torch"	else		messagebox, "You do not have a torch."	endifendifstopscript mf_torchtoggleend Mf_TorchToggle


So now it will unequip a torch if I have one out, but it wont equip one if I don't have one out.
User avatar
Erich Lendermon
 
Posts: 3322
Joined: Sat Nov 03, 2007 4:20 pm

Post » Fri May 27, 2011 7:59 pm

I'd try something simpler.
Create a MISC object (so it will not be really equipped) to use as toggler ; I'd give it the appearance of a unlit torch, for instance:
id: mf_fake_torch
name: Torch Toggler
mesh: l\light_torch_burnedout.nif
icon: l\llight_torch10.tga
weight: 3
value: 5

and attach to it the local script:
begin Mf_FakeTorchScript; this should be attached to a misc fake torch itemshort OnPcEquipshort torchEquippedIf ( OnPcEquip )	if ( torchEquipped )		player->additem "chitin_shield" 1		player->equip "chitin_shield"		player->removeitem "chitin_shield" 1		set torchEquipped to 0	else		if ( player->GetItemCount "torch" > 0 )			player->equip "torch"			set torchEquipped to 1		else			MessageBox "You do not have a torch."		endif	endif	set OnPcEquip to 0endifend

User avatar
Patrick Gordon
 
Posts: 3366
Joined: Thu May 31, 2007 5:38 am

Post » Fri May 27, 2011 6:24 pm

That script is similar to my first one, but yours is a lot better. But it doesn't work for some reason. I don't understand, and can't see anything wrong with it. I even tried putting it on a ring and still no luck.
It's irritating, I want to just chalk this up as a loss, but I can't :banghead: .
User avatar
vicki kitterman
 
Posts: 3494
Joined: Mon Aug 07, 2006 11:58 am

Post » Sat May 28, 2011 5:33 am

You can take abot's script and add debug messages. After each if, put a message with the if line copy-pasted into it, and for each if add an else with the opposing message. Then just run it and see which pop up, and you can tell where execution went (a very simple form of debugging).
User avatar
Damian Parsons
 
Posts: 3375
Joined: Wed Nov 07, 2007 6:48 am

Post » Sat May 28, 2011 8:04 am

Finally some progress, I haven't got it right, but I'm getting new results.

Spoiler
begin Mf_FakeTorchScript; this should be attached to a misc fake torch itemshort OnPcEquipshort torchEquippedIf ( OnPcEquip == 1 )	set OnPcEquip to 0	if ( torchEquipped == 1 )		player->additem "chitin_shield" 1		player->equip "chitin_shield"		player->removeitem "chitin_shield" 1		set torchEquipped to 0	elseif ( player->GetItemCount, "gold_001" > 0 )  <------------------------LOOK		player->equip "torch"		set torchEquipped to 1	elseif ( player->GetitemCount "torch" == 0 )		MessageBox "You do not have a torch."	endifendifstopscript Mf_fakeTorchScriptend Mf_FakeTorchScript


Morrowind doesn't know what to do with the line if ( player->GetItemCount "torch" > 0 ), so I changed it to look for gold in lieu of torch, and the script works, it equips/unequips my torch. It's kind of like the situation with one of my earlier attempts, if ( player->HasItemEquipped "torch" > 0 ), all though I might not have been using that line right.

This idea of mine might not be possible .

EDIT:

OK, this is weird. I changed the form id name of torch to torchMW and the script works perfectly. I was kind of wanting to release this mod to the community, but I don't know if it's kosher to change form id names on existing items. What do you guys think?

Hopefully this is my final thanks and no more bugs will pop up (i shouldn't have said that), but thank you all very much you guys are beyond awesome.


here is the final script:

Spoiler
begin Mf_FakeTorchScriptshort OnPcEquipshort torchEquippedIf ( OnPcEquip == 1 )	set OnPcEquip to 0	if ( torchEquipped == 1 )		player->additem "chitin_shield" 1		player->equip "chitin_shield"		player->removeitem "chitin_shield" 1		set torchEquipped to 0	elseif ( player->GetItemCount, "torchMW" > 0 )		messagebox, "you have a torch"		player->equip "torchMW"		set torchEquipped to 1	elseif ( player->GetitemCount "torchMW" == 0 )		MessageBox "You do not have a torch."		player->additem "chitin_shield" 1		player->equip "chitin_shield"		player->removeitem "chitin_shield" 1	endifendifstopscript Mf_fakeTorchScriptend Mf_FakeTorchScript

User avatar
Tyler F
 
Posts: 3420
Joined: Mon Aug 27, 2007 8:07 pm

Post » Sat May 28, 2011 5:37 am

safest way is to copy the item to your own item id, then search and replace.
User avatar
Alisia Lisha
 
Posts: 3480
Joined: Tue Dec 05, 2006 8:52 pm

Post » Sat May 28, 2011 10:09 am

http://abot.silgrad.com/temp//mfTorchTest.zip worked for me.
Anyway, just to be sure the problem is your setup not recognizing "torch", try it with only Morrowind loaded and from a fresh new game, so we can exclude other mods/savegame conflicts.
Start a new game, open the game console and type
player->GetItemCount "torch"
if it does not work, then we have a problem.
If it works, then it should work from the script also.
mfTorchTest.esp could be tested this way
type:
placeatpc mf_fake_torch 1 0 0
pick up the fake torch (Torch Toggler) and try equipping it
If the script works, you should see the "You do not have a torch." message

type:
placeatpc torch 1 0 0
pick up the real torch, try equipping the Torch Toggler
User avatar
Steeeph
 
Posts: 3443
Joined: Wed Apr 04, 2007 8:28 am

Post » Sat May 28, 2011 8:40 am

OK, here is what i've found out so far, with my fully modded game on any save, I can put player->getitemcount, "torch" in the console and it WILL return the correct number of torches in my inventory (WTF) yet my simple script wont work. Then I tried your esp on a fresh save with only the morrowind.esm loaded, and when i equip the mf_fake_torch I do get the "you do not have a torch" message. I can't put your "mf_fake_torch" in my quick slots for some reason. So then i loaded my torch toggle esp (with just the MW.esm) changed the getitemcount to "torch" in the script and it still doesn't work.

I want to make sure I'm understanding you right. So you are saying that the following script works for you?

begin Mf_FakeTorchScriptshort OnPcEquipshort torchEquippedIf ( OnPcEquip == 1 )	set OnPcEquip to 0	if ( torchEquipped == 1 )		player->additem "chitin_shield" 1		player->equip "chitin_shield"		player->removeitem "chitin_shield" 1		set torchEquipped to 0	elseif ( player->GetItemCount, "torch" > 0 )		messagebox, "you have a torch"		player->equip "torch"		set torchEquipped to 1	elseif ( player->GetitemCount "torch" == 0 )		MessageBox "You do not have a torch."		player->additem "chitin_shield" 1		player->equip "chitin_shield"		player->removeitem "chitin_shield" 1	endifendifend Mf_FakeTorchScript

User avatar
JR Cash
 
Posts: 3441
Joined: Tue Oct 02, 2007 12:59 pm

Post » Fri May 27, 2011 8:28 pm

OK, here is what i've found out so far, with my fully modded game on any save, I can put player->getitemcount, "torch" in the console and it WILL return the correct number of torches in my inventory (WTF) yet my simple script wont work. Then I tried your esp on a fresh save with only the morrowind.esm loaded, and when i equip the mf_fake_torch I do get the "you do not have a torch" message. I can't put your "mf_fake_torch" in my quick slots for some reason. So then i loaded my torch toggle esp (with just the MW.esm) changed the getitemcount to "torch" in the script and it still doesn't work.

I want to make sure I'm understanding you right. So you are saying that the following script works for you?

begin Mf_FakeTorchScriptshort OnPcEquipshort torchEquippedIf ( OnPcEquip == 1 )	set OnPcEquip to 0	if ( torchEquipped == 1 )		player->additem "chitin_shield" 1		player->equip "chitin_shield"		player->removeitem "chitin_shield" 1		set torchEquipped to 0	elseif ( player->GetItemCount, "torch" > 0 )		messagebox, "you have a torch"		player->equip "torch"		set torchEquipped to 1	elseif ( player->GetitemCount "torch" == 0 )		MessageBox "You do not have a torch."		player->additem "chitin_shield" 1		player->equip "chitin_shield"		player->removeitem "chitin_shield" 1	endifendifend Mf_FakeTorchScript




EDIT: For the time being ignore this last post of mine, I forgot to add time to my dummy torch, brb with my results.

Edit2: OK, that script works perfectly (with a regular Ed id "torch"),but only if it is used with the MW.esm only. If it is used with BM.esm or Tri.esm I get an error "script error expression in mf_fake_torch script", then another error "left eval" But, If I change torch to torch_256, or any other existing torch it works fine. So this is either a bad install or a bug in BM or tri.
User avatar
Lady Shocka
 
Posts: 3452
Joined: Mon Aug 21, 2006 10:59 pm

Post » Fri May 27, 2011 5:53 pm

Hmm, Torch light is overridden by Tribunal.esm, so I'd try compiling the mod with/without Tribunal.esm loaded and see if something changes.
Also, I have changed the fake item to be a shield, so it can be assigned to a quick key; I tried a light before, but it did not work well.
http://www.mediafire.com/?taac8qtsst5zoog
I compiled with Morrowind only and tried the mod with both Tribunal and Bloodmoon loaded, and it works for me.
Time to hit the sack, good luck!
User avatar
chloe hampson
 
Posts: 3493
Joined: Sun Jun 25, 2006 12:15 pm

Post » Fri May 27, 2011 8:13 pm

I reinstalled mw with the expansions and the scripts works perfectly now! I don't know what i did to corrupt bm/tri. Thanks again abot, you are the [censored]! :foodndrink:
User avatar
Breautiful
 
Posts: 3539
Joined: Tue Jan 16, 2007 6:51 am


Return to III - Morrowind