Jump to content

Tiny problem with scripting


Hunter357

Recommended Posts

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 RW0DoorOpenScript

short LockState
short DoorUnlocked
short button

;--------------------------------------------------------------------------------------------------

BEGIN OnActivate

IF DoorUnlocked == 0
if IsActionRef player
showmessage breakinMSG;
endif

if LockState == 1
showmessage DoorBreach;
set DoorUnlocked to 1
unlock
endif

if LockState == 2
showmessage DoorBreachFailed;
endif

if LockState == 3
showmessage DoorLock;
endif
ENDIF

if DoorUnlocked == 1
if IsActionRef player
Activate
endif
endif
END

;--------------------------------------------------------------------------------------------------

BEGIN MenuMode 1001
Set 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
endif
END

 

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,

regards

Lucas

Link to comment
Share on other sites

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 by Ladez
Link to comment
Share on other sites

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...