Hunter357 Posted August 26, 2014 Share Posted August 26, 2014 Hi there... I have a little problem with some scripts that i wrote and can't find the source of it. So i wanted to make alternative ways to breach closed doors, and so i wrote something like this... scn RW0DoorOpenScriptshort LockStateshort DoorUnlockedshort button;--------------------------------------------------------------------------------------------------BEGIN OnActivateIF DoorUnlocked == 0 if IsActionRef player showmessage breakinMSG; endif if LockState == 1 showmessage DoorBreach; set DoorUnlocked to 1 unlockendifif LockState == 2 showmessage DoorBreachFailed; endifif LockState == 3 showmessage DoorLock; endifENDIFif DoorUnlocked == 1 if IsActionRef player Activate endifendifEND;--------------------------------------------------------------------------------------------------BEGIN MenuMode 1001Set Button to GetButtonPressed;;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ( BUTTON 0 ) - - - - - - - - - - - - - - - - - - - - - - - - - - - if ( Button == 0 ) Set Button to -1; set LockState to 3 Return; endif;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ( BUTTON 1 ) - - - - - - - - - - - - - - - - - - - - - - - - - - - if ( Button == 1 ) Set Button to -1; if (player.GetItemCount WeapNVFireaxe >= 1) set LockState to 1 else set LockState to 2 endif endif;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ( BUTTON 2 ) - - - - - - - - - - - - - - - - - - - - - - - - - - - if ( Button == 2 ) Set Button to -1; if (player.GetItemCount WeapTireIron >= 1) set LockState to 1 else set LockState to 2 endif endifEND Script works perfectly, except that message windows appear with 1 action delay (so if my first action is to breach door with fireaxe, and i don't have a fireaxe nothing happend, door remains locked, no windows appear nothing... Then i approach door once again and this time i choose option "do nothing", and all actions follow like they should but after i press the button i receive message from previous action - breaching doors with fireaxe (so the one with "you don't have necessary tools)... now i tried few combinations and it still doesn't work like it should... Could i please ask someone who knows whats going on to look throo my script and tell me what i did wrong? Thanks in advance,regardsLucas Link to comment Share on other sites More sharing options...
Ladez Posted August 26, 2014 Share Posted August 26, 2014 (edited) The script doesn't return to your OnActivate block, that part only runs once immediately after the scripted object is activated. That's why you only begin to see the messages after you've activated it the second time. Aside from that you should change your MenuMode block to a GameMode block and move a good portion of your code from OnActivate down there as well. This script should work. I've made some other adjustments as well so it's more succinct. For instance, you don't need the DoorUnlocked variable when you can simply call GetLocked, and setting the button variable to -1 is redundant since that's what GetButtonPressed returns when no button has been pressed. scn RW0DoorOpenScript short bMenu short button BEGIN OnActivate if IsActionRef Player if GetLocked == 1 ShowMessage breakinMSG; set bMenu to 1 elseif GetLocked == 0 Activate Player endif endif END BEGIN GameMode Set button to GetButtonPressed; if ( bMenu && button == 0 ) ; - - - - - - - - - - - - - - - BUTTON 0 ShowMessage DoorLock; elseif ( bMenu && button == 1 ) ; - - - - - - - - - - - - - BUTTON 1 if (player.GetItemCount WeapNVFireaxe >= 1) ShowMessage DoorBreach; Unlock else ShowMessage DoorBreachFailed; endif elseif ( bMenu && button == 2 ) ; - - - - - - - - - - - - - BUTTON 2 if (player.GetItemCount WeapTireIron >= 1) ShowMessage DoorBreach; Unlock else ShowMessage DoorBreachFailed; endif endif set bMenu to 0 END Edited August 26, 2014 by Ladez Link to comment Share on other sites More sharing options...
Hunter357 Posted August 26, 2014 Author Share Posted August 26, 2014 Wow... thanks Ladez it really is much simpler...I've tried before to do all commands in gamemode, but also in much more twisted way and it simply put me in infinite loop of message windows after preforming action...This on other hand work perfectly and also will help me modified my other scripts to run much better.Thanks once more! regards,Lucas Link to comment Share on other sites More sharing options...
Ladez Posted August 26, 2014 Share Posted August 26, 2014 Yeah, you just need a control variable to prevent the messages from looping. That's the one I called bMenu. :) Link to comment Share on other sites More sharing options...
Recommended Posts