Jump to content

Scripting hotkeys


AxlDave

Recommended Posts

I am attempting to assign a weapon to a particular key such that it equips / unequips each time the key is pressed. The script I have at the moment is:

 

scn AXLWolverineAdamantiumClawsEquipScript

short sToggle
short DoOnce

BEGIN GameMode

if ( Player.HasPerk AdamantiumSkeleton == 0 )
if ( Player.HasPerk AXLWolverineSuperStrikePerk == 1 )
RETURN
endif
endif

if ( Player.HasPerk AdamantiumSkeleton == 1 )
if ( Player.HasPerk AXLWolverineSuperStrikePerk == 0 )
if sToggle != IsKeyPressed 46
set sToggle to IsKeyPressed 46
if sToggle
if ( DoOnce == 0 )
player.equipitem AXLWolverineAdamantiumClawsWeapon
set DoOnce to -1
endif
if ( DoOnce == -1 )
player.equipitem AXLWolverineAdamantiumClawsWeapon
set DoOnce to 0
endif
endif
endif
endif
endif

END

 

However it does not appear to do anything. I am pretty sure I have used the IsKeyPressed command wrong.

 

Can anyone suggest where I am going wrong?

Link to comment
Share on other sites

You need to use the function like this...

scn AXLWolverineAdamantiumClawsEquipScript

short sToggle
short DoOnce

BEGIN GameMode


 if (Player.HasPerk AdamantiumSkeleton == 1) && (Player.HasPerk AXLWolverineSuperStrikePerk == 0 )
   if IsKeyPressed 46
     If sToggle == 0
       Set sToggle to 1
       if ( DoOnce == 0 )
         player.equipitem AXLWolverineAdamantiumClawsWeapon
         set DoOnce to -1
       elseif ( DoOnce == -1 )
         player.equipitem AXLWolverineAdamantiumClawsWeapon
         set DoOnce to 0
       endif
     endif
   else
     Set sToggle to 0
   endif
 else
  Return
 endif
END
Link to comment
Share on other sites

Nicely done, cheers for that man, it does what it is supposed to now.

 

Only problem now is that it's a little slow with reacting to the key press, in that I generally have to wait about 20 seconds between equipping / unequipping and generally need to hold the key down for several seconds after waiting. I'm guessing this is because it has to read through the script to understand what to do, which takes time. If this is the case, perhaps you could suggest some way to "tidy up" the script?

 

Another possibility is that I have 3 of these scripts running individually but concurrently, as I have 3 stages of claws: Bone, Adamantium, Super Strike Adamantium. Would I be better served having all of these possibilities in one script?

 

Again, thanks for the working version of the script, if you could also advise me on making it more efficient, that would be awesome!

Link to comment
Share on other sites

Well, I kind of already made it as efficient as possible by removing extraneous code and combing if-then-else statements. Let me ask you this: what is your script running on, an object or is it a quest script? If it's a quest script, try setting the script processing delay to a shorter time, like 0.25 seconds. If it's not a quest script, try making it such. If it is a quest script with a short processing delay, then I would need more information.

 

I've used IsKeyPressed in the past and it's not a slow function. In fact, I have made far larger scripts with very involved loops (like a ref-walk) that don't show as much delay as your little script apparently does. Other things may be going on that aren't obvious.

 

Are you familiar with the printc FOSE command and the scof console command? To test your script, you can place several printc commands within the script that display GetSecondsPassed (Timer = Timer + GetSecondsPassed, then display Timer using printc). Then using the Set Console Output File (scof) command in the console, you can direct all the output from your printc commands to the file you specify, then parse through that text file, noticing how long it took for sections of your script to fire and how long it took between iterations. That can help if there is an area that appears to be slowing down the whole script.

 

As you know, IsKeyPressed returns a value as long as the key in questions is held down. In practice, a human is not quick enough to press and release a key before the script runs several times and thus returns several keypresses - which is why we toggle the key press until the value is no longer equal to our specific key. This implies that the script should be running many times a second and not once every 20 seconds. So something is a foot - so to speak.

 

One example of where a problem might lie is with object scripts. If the object in question is getting spawned multiple times, the script on it can be running concurrently many many times. I've seen this before and it's not good. I'm not saying that is what is happening with your script, but the person who had this problem had no idea that so many spawns were occurring and as such kept looking at one script for the problem when the problem was actually with an entirely different script that he never mentioned in his thread.

 

Oh yeah, I almost forgot... Yes, it would be better to have all of your effects in one script versus three. That is, if they are all similar to the one you've posted. As an FYI - I have had dozens and dozens of scripts running at the same time without issue (not to mention that the game has dozens of its own running as well), so I suspect that there is something funny going on that is preventing yours from running in a timely fashion.

Edited by pkleiss
Link to comment
Share on other sites

 

Let me ask you this: what is your script running on, an object or is it a quest script? If it's a quest script, try setting the script processing delay to a shorter time, like 0.25 seconds

 

It is a quest script, and the script processing delay is "Default", however quick that is.

 

 

Are you familiar with the printc FOSE command and the scof console command?

 

I'm afraid I am not familiar with these functions, I have only just started scripting and can do little more than basic if functions. I can always learn, though the more complex the code the bigger the headache, hah.

 

 

As you know, IsKeyPressed returns a value as long as the key in questions is held down. In practice, a human is not quick enough to press and release a key before the script runs several times and thus returns several keypresses - which is why we toggle the key press until the value is no longer equal to our specific key. This implies that the script should be running many times a second and not once every 20 seconds. So something is a foot - so to speak.

 

Hmm, so then could it be possible that the script is working so well that in one keypress the claws are actually equipping and unequipping several times? It does not show any equip / unequip messages in game, which it should, so it's possible I'm wrong with this.

 

 

If the object in question is getting spawned multiple times, the script on it can be running concurrently many many times.

 

Well, I thought I had written the script such that it would only happen once, but just in case here is the player.additem script I am using for Adamantium Claws. The other 2 add claws scripts are basically the same:

 

scn AXLWolverineAdamantiumClawsScript

 

short DoOnce

 

BEGIN GameMode

 

if ( Player.HasPerk AdamantiumSkeleton == 0 )

if ( Player.HasPerk AXLWolverineSuperStrikePerk == 1 )

RETURN

endif

endif

 

if ( DoOnce == 0 )

if ( Player.HasPerk AdamantiumSkeleton == 1 )

player.removeitem AXLWolverineBoneClawsWeapon 1 1

player.additem AXLWolverineAdamantiumClawsWeapon 1

player.equipitem AXLWolverineAdamantiumClawsWeapon

set DoOnce to -1

endif

endif

 

END

 

 

Yes, it would be better to have all of your effects in one script versus three. That is, if they are all similar to the one you've posted.

 

They are similar, and I have compiled them into one script (with a bit of re-jigging) and as you thought it had little effect. Here is the merged script:

 

scn AXLWolverineClawsEquipScript

 

short sToggle

short DoOnce

 

BEGIN GameMode

 

if IsKeyPressed 46

if sToggle == 0

set sToggle to 1

 

if ( Player.HasPerk AXLWolverineMutationPerk >= 1 ) && ( Player.HasPerk AdamantiumSkeleton == 0 )

if ( DoOnce == 0 )

player.equipitem AXLWolverineBoneClawsWeapon

set DoOnce to -1

elseif ( DoOnce == -1 )

player.unequipitem AXLWolverineBoneClawsWeapon

set DoOnce to 0

endif

endif

 

if ( Player.HasPerk AdamantiumSkeleton == 1 ) && ( Player.HasPerk AXLWolverineSuperStrikePerk == 0 )

if ( DoOnce == 0 )

player.equipitem AXLWolverineAdamantiumClawsWeapon

set DoOnce to -1

elseif ( DoOnce == -1 )

player.unequipitem AXLWolverineAdamantiumClawsWeapon

set DoOnce to 0

endif

endif

 

if ( Player.HasPerk AXLWolverineSuperStrikePerk == 1 )

if ( DoOnce == 0 )

player.equipitem AXLWolverineSuperAdamantiumClawsWeapon

set DoOnce to -1

elseif ( DoOnce == -1 )

player.unequipitem AXLWolverineSuperAdamantiumClawsWeapon

set DoOnce to 0

endif

endif

 

endif

else

set sToggle to 0

endif

 

END

 

 

As an FYI - I have had dozens and dozens of scripts running at the same time without issue (not to mention that the game has dozens of its own running as well), so I suspect that there is something funny going on that is preventing yours from running in a timely fashion.

 

I had wondered if I set up the Quest which enables the script in the wrong way, but there is very little data attached. Here is the data I have:

 

QUEST NAME: Wolverine Claws Equip Quest

ID: AXLWolverineClawsEquipQuest

PRIORITY: 60

[x] Start Game Enabled

SCRIPT: AXLWolverineClawsEquipScript

SCRIPT PROCESSING DELAY: [x] Default

 

And aside from 2 blank quest stages, that's it. Not a lot to go wrong on.

 

Hopefully it's a simple error with a simple fix...

Link to comment
Share on other sites

The first thing to try is to uncheck that default processing delay and set it manually to 0.25. I don't recall what the default time is, but I do know it is a long time. The second thing to do... well, lets say step 1B, is to limit your script to just one armor changing section (if you have combined all three scripts) or just use one script to work on for now. For testing purposes, you can add a semi colon (;) to the beginning of a line of code to make it a comment. This way you can limit your script to do just one armor change while debugging it.

Link to comment
Share on other sites

 

The first thing to try is to uncheck that default processing delay and set it manually to 0.25.

 

Well what do you know, that fixed it! Nice one, cheers for that. I guess the default delay is approximately 20 seconds or so, then. I was going to give you a Kudos but I can't seem to find the damn button... I'm sure it was around here somewhere...

Link to comment
Share on other sites

  • 2 weeks later...
  • Recently Browsing   0 members

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