Jump to content

Photo

Scripting assist requested


  • Please log in to reply
4 replies to this topic

#1
ghowriter

ghowriter

    Journeyman

  • Supporter
  • Pip
  • 31 posts

So I made a custom script that randomly generates a weapon and randomly applies properties. I plan to set the power of the weapon that is created as variables that can be set on the placable calling the script. Right now I have the weapon's power based on a 1d20 roll with 1 being a simple +1 or energy damage boost or other misc property. The more powerful weapons this has created has boggled even my mind but I found a flaw I thought I had scripted to prevent.

 

On the more powerful items it can draw 1, 2, or even three random misc properties and I considered and tried to script a routine to prevent duplicates but... well, on my test chest and out of 30 draws I saw duplicates at least twice. My guess is the script is running so fast, it's applying two powers at the same time or something like that. Anyway, I wonder if anyone might suggest a way to help prevent the doubling of properties.

 

So far, I saw keen doubled and Massive Crit 3 doubled.

 

I am also looking for a naming routine to name the created weapons... as is, they keep the exact name as the base item the script generated.

 

note: this script uses a custom 2da to draw the tags of the base item from.


Edited by ghowriter, 06 September 2018 - 08:50 AM.


#2
4760

4760

    Enthusiast

  • Members
  • PipPip
  • 121 posts

I see two easy ways of doing this:

  • option 1: you split the properties in three sets of ten, and take one property only per set. But then some properties will only exist on highly magical weapons.
  • option 2: before applying the selected property, you check if it's already existing on the weapon. If yes, you select another one (or increase the value? So a +1 will become +2); if no obviously you apply it.


#3
ghowriter

ghowriter

    Journeyman

  • Supporter
  • Pip
  • 31 posts

I split the +x enhancements and +damage bonuses out of the misc group so they're never duplicated. I like the idea of splitting the misc group though. I would have to weigh which properties are for higher level weapons but I think I can handle that. This way no duplicates. After I posted this I saw what I assumed was a duplicate draw: Bonus damage Electrical 1 but then realized the script selected electrical bonus damage and the weapon was adamantine which adds 1 electrical damage. I changed this so now if the script randomly selects electrical bonus damage on an adamantine weapon it upgrades the damage instead of duplicating it.

 

As to the option 2, I have the script checking for the property and I had assumed I had the script set to select a new property and keep checking until one is selected that doesn't exist. The logic is sound, no duplicate properties should manifest. the script, however is likely running so fast that it is selecting a fourth property before the third property is actually added to the item thus bypassing the duplicate check because at the exact moment the item is checked the property doesn't yet exist on the item. I am considering a small delay routine after adding the misc properties that will loop until the property is finished being added thus making the rest of the script wait until the property is actually written. I am not sure if this will lag the creation process though.

 

is it better practice to keep frequently access functions inside the main script or the include?



#4
ghowriter

ghowriter

    Journeyman

  • Supporter
  • Pip
  • 31 posts

I asked that last question because the toolset script editor has taken to do something rather odd. I had (it's been changed) a function that would assign 3 variables to the selected weapon for use later in the main script. These were the item property id numbers for the improved critical, weapon focus, and weapon specialization bonus feats for that specific weapon. My function assigned these values after I went through the ip_feats 2da to get the values since the toolset actually lacks those constants (and many other bonus feat constants). Now, when I select the text of the function in the main script it normally shows the function parameters so we know how it needs to be called. In my toolset, when I select the function, random text appeared that had nothing to do with the actual function. I assumed this was my fault so I removed the function and again made a custom 2da from which the script draws the information from if those bonus feats are chosen. I am now considering instead to make another include that simply has the constants as I think accessing a 2da slows the game, especially if its accessed a lot. A constant file include file would be more efficient, in my opinion.



#5
4760

4760

    Enthusiast

  • Members
  • PipPip
  • 121 posts

That's right, constants in an include file are accessed faster than opening a file, reading data, and closing the file!






IPB skins by Skinbox
Page loaded in: 1.155 seconds