• Please note: In an effort to ensure that all of our users feel welcome on our forums, we’ve updated our forum rules. You can review the updated rules here: http://forums.wolflair.com/showthread.php?t=5528.

    If a fellow Community member is not following the forum rules, please report the post by clicking the Report button (the red yield sign on the left) located on every post. This will notify the moderators directly. If you have any questions about these new rules, please contact support@wolflair.com.

    - The Lone Wolf Development Team

Altering weapon classes via script

scibat

Well-known member
I am in the middle of coding a class ability that is supposed to allow this gunslinger archetype to use two two-handed firearms as per conventional two-handed fighting with the Two-Weapon Fighting feat under certain circumstances. Essentially, it would make the main hand gun the equivalent of a One-Handed weapon and the off-hand gun a Light weapon.

My idea to try to accomplish this was with the following code snippet:

Code:
Pre-levels/5000

foreach pick in hero from BaseWep where "wProfReq.Firearm2"
if (eachpick.tagis[Hero.MainHand] + eachpick.tagis[Hero.OffHand] = 2) then
   perform hero.assign[Hero.TwoWep]
   if (eachpick.tagis[Hero.MainHand] = 1) then
      perform eachpick.delete[wClass.TwoHanded]
      perform eachpick.assign[wClass.OneHanded]
   endif
   if (eachpick.tagis[Hero.OffHand] = 1) then
      perform eachpick.delete[wClass.TwoHanded]
      perform eachpick.assign[wClass.OneHanded]
      if (eachpick.field[gSizeMod].value = 0) then
         perform eachpick.delete[wClass.OneHanded]
         perform eachpick.assign[wClass.Light]
      endif
   endif
endif
nexteach

The idea being that, after checking to see if two 2-handed firearms are being wielded, to alter the wClass tags on each directly. So far, while not giving an error, this code is not altering the tags of items on a character appropriately equipped. It may be a timing error ... I set the timing based on the timing of the field calculation for wClass, but I don't know for sure.

At the *worst*, I could simply add bonuses with the right weapon equipped configuration to make up for the penalties, but if anyone can find the error in this more elegant solution, please let me know! Thank you!
 
It may very well being a timing issue as you have allot of different values being checked pretty early. I would add "debug" statements and then go to "Develop->Display Debug Output". (Note I am not near HL but I think that is the right name.) :D

Code:
foreach pick in hero from BaseWep where "wProfReq.Firearm2"
[B]debug "In Foreach Loop"
debug "Hero.MainHand " & eachpick.tagis[Hero.MainHand]
debug "Hero.OffHand " & eachpick.tagis[Hero.OffHand][/B]
if (eachpick.tagis[Hero.MainHand] + eachpick.tagis[Hero.OffHand] = 2) then
   perform hero.assign[Hero.TwoWep]
   if (eachpick.tagis[Hero.MainHand] = 1) then
      perform eachpick.delete[wClass.TwoHanded]
      perform eachpick.assign[wClass.OneHanded]
   endif
   if (eachpick.tagis[Hero.OffHand] = 1) then
      perform eachpick.delete[wClass.TwoHanded]
      perform eachpick.assign[wClass.OneHanded]
      if (eachpick.field[gSizeMod].value = 0) then
         perform eachpick.delete[wClass.OneHanded]
         perform eachpick.assign[wClass.Light]
      endif
   endif
endif
nexteach
I am pretty sure those "tags" are not set until very late. Their is a pair of "fields" that I think can be used instead that are set much earlier. I don't remember what they are called but you can look at the "Debug Fields" for a gun and equip/unequipped it to find the right ones.

The above debug statements will help you narrow down your timing and issues.
 
Thanks for the info! I'll check it out and see what I can figure. I'm with you that I feel this is probably a timing error. I'll run the debugs and see what it tells me.
 
Update: adding the debug tags and having debug output turned on did, well, nothing. The Debug Output field remains empty, which is puzzling.

Looking at fields, I then tried this:
Code:
Pre-levels/5000
foreach pick in hero from BaseWep where "wProfReq.Firearm2"
if (eachpick.field[gIsEquip].value = 1) then
   if (eachpick.field[wMenuEquip].value = 1) then
      perform eachpick.delete[wClass.TwoHanded]
      perform eachpick.assign[wClass.OneHanded]
   endif
   if (eachpick.field[wMenuEquip].value = 2) then
      perform eachpick.delete[wClass.TwoHanded]
      perform eachpick.assign[wClass.OneHanded]
      if (eachpick.field[gSizeMod].value = 0) then
         perform eachpick.delete[wClass.OneHanded]
         perform eachpick.assign[wClass.Light]
      endif
   endif
endif

That too hasn't worked. I also tried it at First/5000 and likewise nothing. Is it worthwhile to try and sift through the task list to find the field and tag timings or is there an easier reference to check?
 
I'd try:
Code:
debug "start"
even before the foreach. That'll tell you if your problem lies in the expression you've written for your foreach
 
OK, I don't know what is wrong (or right), but even debug "start" generate no debug output in the Debug Output window. Or should I feel dumb and am looking in the wrong place for the debug info?
 
OK, I don't know what is wrong (or right), but even debug "start" generate no debug output in the Debug Output window. Or should I feel dumb and am looking in the wrong place for the debug info?
Guess need to ask what "Thing" is this script attached too as it sounds like its not getting onto the hero. If this is on a Class/Archetype are you adding that Class/Archetype to the character? Sorry if that is a dumb question but its very strange that your not even getting "Start". That means the script is not firing at all. :(
 
There's no code before what you've posted?

To see the debug output, Develop...Floating Info Windows...Show Debug Output

You've added this archetype to your test character, and verified that the class special you're working on shows up on the Gunslinger tab?
 
Yep on all counts. I created a test character, added the class and Archetype, and the ability did add at the right level.

There actually is two lines of code ahead of the 'debug "start"'. Moving the debug to there finally generates some output, but it isn't much. Here is the full code, as well as the debug output. Important to note that the first if/then script bit works exactly as intended.

Code:
debug "start"
~ If we're not shown, just get out now
doneif (tagis[Helper.ShowSpec] = 0)

if (hero.childlives[gSaddRack] <> 0) then
   hero.child[gSaddRack].field[usrCandid2].text = "component.BaseWep & wProfReq.Firearm2"
endif

foreach pick in hero from BaseWep where "wProfReq.Firearm2"
debug "In Foreach Loop"
debug "gIsEquip " & eachpick.field[gIsEquip].value
debug "wMenuEquip " & eachpick.field[wMenuEquip].value
if (eachpick.field[gIsEquip].value = 1) then
   if (eachpick.field[wMenuEquip].value = 1) then
      perform eachpick.delete[wClass.TwoHanded]
      perform eachpick.assign[wClass.OneHanded]
   endif
   if (eachpick.field[wMenuEquip].value = 2) then
      perform eachpick.delete[wClass.TwoHanded]
      perform eachpick.assign[wClass.OneHanded]
      if (eachpick.field[gSizeMod].value = 0) then
         perform eachpick.delete[wClass.OneHanded]
         perform eachpick.assign[wClass.Light]
      endif
   endif
endif
nexteach

Here's the debug output:
Code:
********* Start Evaluation Cycle *********

start

Forgot to clarify: This is a Class Special attached to the Archetype. No odd bootstrap conditions or anything past the usual ClSpecWhen tag.
 
Last edited:
The Helper.ShowSpec test will ALWAYS exit your script before ~ Post-Levels/300, because until then, Helper.ShowSpec has not been added.
 
Oh, wow, well, that might have a lot to do with it. Thank you, I'll take that out and give it a test!
 
Taking out the cancel and moving the priority just ahead of the wClass assign has pushed things forward, thanks for the help!
 
But, by taking out the Helper.ShowSpec, does your ability now activate no matter what level your character is at? Whether he's reached the correct level to gain that ability or not?

Also, if you add the skeleton template, or something else that shuts down lots of abilities on a character, does this ability still apply its effects?
 
Good question. Let me investigate!

EDIT: Yep. That is a problem. I have an idea though ... I'm going to try tying the script to an in-play toggle, if the timing works. It's an added step for a player to have to take, but it will then at least work properly. Hopefully, anyway! Let me test this.
 
Last edited:
OK, adding an Activate Ability toggle fixed it entirely. It won't activate the ability early and it will turn it off again on removal ASSUMING you have the activation off. Not perfect but far closer to a usable solution.

This is workable for my purposes, but I still wouldn't mind finding a way to clean it up more, if anyone has any thoughts.
 
You're certain you have to run this before Post-Levels/1000? If not, then you can use the standard test.

If you do need it earlier, there are other ways to test that you've reached the correct level, and that you haven't been disabled. They simply take more than one line of code, so they're not normally used.
 
Code:
~we're earlier than the normal test for whether we've reached the correct level, so we'll recreate that test here
doneif (root.linkage[varies].field[cTotalLev].value + field[xExtraLev].value + field[xEffectLev].value < tagvalue[ClSpecWhen.?])
 
~if we're disabled, don't proceed
doneif (tagis[Helper.SpcDisable] <> 0)
 
Thanks, I'll give it a try! I am not 100 percent certain, so I will try re-timing it. If that doesn't work, then I'll use the extended code you provided.

EDIT: I couldn't change the timing as wClass is resolved very early, but the extended code snippet did the charm beautifully. Thank you again for the help!
 
Last edited:
Back
Top