Abesh Posted June 12, 2009 Share Posted June 12, 2009 The goal of this script is to have something equip when I press - and then unequip with the same button. This seems to work pretty well, the problem is it does this very fast. It seems to not do anything, but when I turn messages on, it shows that it's actually adding, equipping, unequipping and removing the item at a time. If anyone had any help I'd appreciate it. I figured out how to do it a while ago, but somehow must have screwed it up and now have no idea how to right it. ----------------------ScriptName NAPAVisorMode float time; short reset; Begin OnEquip set NAPAHelmetMode to 0 End begin GameMode if reset == 0 if time < .5 set time to time + GetSecondsPassed; else set time to 0; set reset to 1; endif else if IsKeyPressed 12 if NAPAHelmetMode == 0 player.AddItem ArmorNAPAHelmNV 1 1 player.EquipItem ArmorNAPAHelmNV 0 1 set NAPAHelmetMode to 1 else player.UnEquipItem ArmorNAPAHelmNV 0 1 player.RemoveItem ArmorNAPAHelmNV 1 1 set NAPAHelmetMode to 0 endif set reset to 0; endif endif end Begin OnUnequip player.UnEquipItem ArmorNAPAHelmNV 0 1 player.RemoveItem ArmorNAPAHelmNV 1 1 set NAPAHelmetMode to 0 rimod NAPAVision End----------------------- Where in this case the item in question can be swapped for something else for testing, or if need be I can send the esp. Link to comment Share on other sites More sharing options...
TGBlank Posted June 12, 2009 Share Posted June 12, 2009 Well, you got a timer setup right there, so it *should* work if you increase the timer. The other thing to take into consideration is that passing the nomsg flag to additem and equipitem (and removeitem and unequipitem) can cause the game not to update the models accordingly, and most importantly, it tends to bypass onequip code blocks. The timer however should still be increased to a second or two, or the code reworked so the time starts ticking from the point where the player releases the key. Link to comment Share on other sites More sharing options...
Abesh Posted June 12, 2009 Author Share Posted June 12, 2009 The timer however should still be increased to a second or two, or the code reworked so the time starts ticking from the point where the player releases the key. This sounds promising, but I have no idea how to actually go about scripting that. The timer was yanked whole cloth from somewhere else, and I still need to fool around with it before I fully understand it. Any hints? edit: I tried increasing the time, and it works most of the time, unless I click the key in rapid succession. I'll keep fiddling with the timing. Link to comment Share on other sites More sharing options...
TGBlank Posted June 12, 2009 Share Posted June 12, 2009 Basically, your timer starts counting half a second from the point where the player touches the key, give or take some margin of error, it's rather likely for your code to register two keypresses when there was actually only one. the code skeleton for a non-timer-using version that wait for release would be along the lines of: If (Iskeypressed <sumkeycode>) If (DoOnce) <Stuff Happens> Set DoOnce to 0 EndIf Else Set DoOnce to 1 EndIf A delay timer can also be used in addition. If (Iskeypressed <sumkeycode>) If (DoOnce) <Stuff Happens> Set DoOnce to 0 EndIf Else Set Timer to Timer + GetSecondsPassed If (Timer > <Threshold>) Set Timer to 0 Set DoOnce to 1 EndIf EndIf Note that gamemode blocks will always run as long as the object exists in memory, that is, as long as it is persistent, it is in the same cell as the player, Or it is in the inventory of an actor or container in the same cell as the player (not sure if it would also run if it's in the inventory of an actor or container that is persistent). Link to comment Share on other sites More sharing options...
Abesh Posted June 15, 2009 Author Share Posted June 15, 2009 This is the current incarnation of the script, which admittedly looks very similar as the last one. The main changes are the fact that I've played around with the timing such that it works most of the time. However, I haven't been able to figure out how to, as you say, set it such that it activates only when the button is released. Plugging this into the code skeletons you gave me gave me the switching-too-fast-between-modes problem, but that's more likely a problem with something I did rather than the idea itself. ScriptName NAPAVisorMode Float timer; Short refresh; Begin GameMode if refresh == 0 if timer < 0 set timer to timer + GetSecondsPassed; else set timer to 0 set refresh to 1 endif else if ( Player.GetEquipped ArmorNAPAHelm == 1 ) if IsKeyPressed 12 if NAPAHelmetMode == 0 player.AddItem ArmorNAPAHelmNV 1 1 player.EquipItem ArmorNAPAHelmNV 0 1 set NAPAHelmetMode to 1 set refresh to 0 else set NAPAHelmetMode to 0 player.UnEquipItem ArmorNAPAHelmNV 0 1 player.RemoveItem ArmorNAPAHelmNV 1 1 endif set refresh to 0 endif endif endif End Begin OnUnequip player.UnEquipItem ArmorNAPAHelmNV 0 1 player.RemoveItem ArmorNAPAHelmNV 1 1 set NAPAHelmetMode to 0 rimod NAPAVision End Link to comment Share on other sites More sharing options...
TGBlank Posted June 15, 2009 Share Posted June 15, 2009 Ehm... i don't see where you're resetting timer... Anyways, take the code skeleton #2, replace <sumkeycode> for 12, replace <stuff happens> with your "if NAPAHelmetMode... else... endif" block, removing the "set refresh to 0" from it. Change <threshold> for w/e value you wish it to be, try 2 or so.The whole thing should replace your gamemode block, change the variables you declare as necessary. Add the onunequip block you have at the end. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.