A way to make this into a function?
Posted: Sat Feb 01, 2014 5:54 pm
If those that are more experienced with functions could lend a hand, could this script be turned into a function?
This is the production script for zoric buildings.
Var explanation:
$gBuildingVar20 = item # being made (bvar 24, 28, 32, and 36 for slots 2, 3, 4, and 5)
$gBuildingVar21 = the total qty set to produce if $gBuildingVar2 = 2. Or a var that counts production cycles between producing if $gBuildingVar2 = 0.
$gBuildingVar22 = qty produced since production was started
$gBuildingVar23 = status of the production slot. full, no supplies, broken, finished making what it was set to make
$gBuildingVar127 - power, besides being needed to create things, it's also needed by default just to run production
$gBuildingVar124 - lubrication, without it, the building has a high chance of breaking down and be unusable until repaired
$prod1 = bvar for qty of item # being made
$prod1qty= the qty being made in the recipe
$prod1d#= bvar for the qty of the first demanded item
$prod1d#qty=qty needed of the first demanded item
the 1 in the temp vars is due to this example being for production slot 1.
other slots would have a 2, 3, 4, or 5 (so yes, the below script is replicated for each of the 5 production lines buildings can have)
additional notes for each part of the script are in the script below
This is the production script for zoric buildings.
Var explanation:
$gBuildingVar20 = item # being made (bvar 24, 28, 32, and 36 for slots 2, 3, 4, and 5)
$gBuildingVar21 = the total qty set to produce if $gBuildingVar2 = 2. Or a var that counts production cycles between producing if $gBuildingVar2 = 0.
$gBuildingVar22 = qty produced since production was started
$gBuildingVar23 = status of the production slot. full, no supplies, broken, finished making what it was set to make
$gBuildingVar127 - power, besides being needed to create things, it's also needed by default just to run production
$gBuildingVar124 - lubrication, without it, the building has a high chance of breaking down and be unusable until repaired
$prod1 = bvar for qty of item # being made
$prod1qty= the qty being made in the recipe
$prod1d#= bvar for the qty of the first demanded item
$prod1d#qty=qty needed of the first demanded item
the 1 in the temp vars is due to this example being for production slot 1.
other slots would have a 2, 3, 4, or 5 (so yes, the below script is replicated for each of the 5 production lines buildings can have)
additional notes for each part of the script are in the script below
Code: Select all
Event( "BuildingProductionRun", "30" )
{
if ($gBuildingVar23=0) //------no pre-existing issues, assign temp vars for production script
{
if ($gBuildingVar20=29)
{
$prod1=85
$prod1qty=1
$prod1d1=127
$prod1d1qty=250
$prod1d2=121
$prod1d2qty=50
$prod1d3=115
$prod1d3qty=25
$prod1d4=112
$prod1d4qty=25
$prod1d5=118
$prod1d5qty=50
}
if ($gBuildingVar20=30)
{
$prod1=82
$prod1qty=1
$prod1d1=127
$prod1d1qty=100
$prod1d2=121
$prod1d2qty=25
$prod1d3=115
$prod1d3qty=50
$prod1d4=112
$prod1d4qty=25
}
if ($gBuildingVar20=31)
{
$prod1=79
$prod1qty=1
$prod1d1=127
$prod1d1qty=500
$prod1d2=121
$prod1d2qty=100
$prod1d3=115
$prod1d3qty=10
$prod1d4=112
$prod1d4qty=50
$prod1d5=118
$prod1d5qty=25
}
if ($gBuildingVar20=32)
{
$prod1=56
$prod1qty=1
$prod1d1=127
$prod1d1qty=100
$prod1d2=121
$prod1d2qty=50
$prod1d3=115
$prod1d3qty=50
$prod1d4=109
$prod1d4qty=1000
}
if ($gBuildingVar20=33)
{
$prod1=73
$prod1qty=1
$prod1d1=127
$prod1d1qty=100
$prod1d2=121
$prod1d2qty=50
$prod1d3=115
$prod1d3qty=50
$prod1d4=106
$prod1d4qty=1000
}
if ($gBuildingVar20=47)
{
$prod1=76
$prod1qty=10
$prod1d1=127
$prod1d1qty=25
$prod1d2=121
$prod1d2qty=5
$prod1d3=115
$prod1d3qty=5
$prod1d4=112
$prod1d4qty=5
$prod1d5=118
$prod1d5qty=5
}
if ($gBuildingVar20=141)
{
$prod1=70
$prod1qty=1
$prod1d1=127
$prod1d1qty=250
$prod1d2=121
$prod1d2qty=100
$prod1d3=118
$prod1d3qty=100
$prod1d4=112
$prod1d4qty=10
$prod1d5=115
$prod1d5qty=10
}
if ($gBuildingVar20=142)
{
$prod1=67
$prod1qty=1
$prod1d1=127
$prod1d1qty=250
$prod1d2=121
$prod1d2qty=100
$prod1d3=118
$prod1d3qty=100
$prod1d4=112
$prod1d4qty=10
$prod1d5=115
$prod1d5qty=10
}
if ($gBuildingVar20=209)
{
$prod1=61
$prod1qty=1
$prod1d1=127
$prod1d1qty=25
$prod1d2=121
$prod1d2qty=50
$prod1d3=103
$prod1d3qty=250
}
if ($gBuildingVar20=210)
{
$prod1=58
$prod1qty=1
$prod1d1=127
$prod1d1qty=100
$prod1d2=121
$prod1d2qty=50
$prod1d3=118
$prod1d3qty=50
$prod1d4=112
$prod1d4qty=10
$prod1d5=115
$prod1d5qty=100
}
if ($gBuildingVar20=215)
{
$prod1=64
$prod1qty=1
$prod1d1=127
$prod1d1qty=25
$prod1d2=121
$prod1d2qty=50
$prod1d3=103
$prod1d3qty=250
}
if ($prod1qty=5) //----random qty variation, to make it impossible to exactly predict item costs
{
$rand=sysRand(5)
if ($rand=1)
{
$prod1qty=$prod1qty+1
}
if ($rand=4)
{
$prod1qty=$prod1qty-1
}
}
if ($prod1qty=10) //----random qty variation, to make it impossible to exactly predict item costs
{
$rand=sysRand(10)
if ($rand=2)
{
$prod1qty=$prod1qty-2
}
if ($rand=4)
{
$prod1qty=$prod1qty+1
}
if ($rand=6)
{
$prod1qty=$prod1qty-1
}
if ($rand=8)
{
$prod1qty=$prod1qty+2
}
}
if ($prod1qty=25) //----random qty variation, to make it impossible to exactly predict item costs
{
$rand=sysRand(15)
if ($rand=2)
{
$prod1qty=$prod1qty-5
}
if ($rand=4)
{
$prod1qty=$prod1qty+3
}
if ($rand=6)
{
$prod1qty=$prod1qty-1
}
if ($rand=9)
{
$prod1qty=$prod1qty+1
}
if ($rand=11)
{
$prod1qty=$prod1qty-3
}
if ($rand=13)
{
$prod1qty=$prod1qty+5
}
}
if ($prod1qty=50) //----random qty variation, to make it impossible to exactly predict item costs
{
$rand=sysRand(25)
if ($rand=2)
{
$prod1qty=$prod1qty-10
}
if ($rand=4)
{
$prod1qty=$prod1qty+8
}
if ($rand=6)
{
$prod1qty=$prod1qty-6
}
if ($rand=8)
{
$prod1qty=$prod1qty+4
}
if ($rand=11)
{
$prod1qty=$prod1qty-2
}
if ($rand=14)
{
$prod1qty=$prod1qty+2
}
if ($rand=17)
{
$prod1qty=$prod1qty-4
}
if ($rand=20)
{
$prod1qty=$prod1qty+6
}
if ($rand=22)
{
$prod1qty=$prod1qty-8
}
if ($rand=24)
{
$prod1qty=$prod1qty+10
}
}
if ($prod1qty>99) //----random qty variation, to make it impossible to exactly predict item costs
{
$rand=sysRand(40)
$bon10=$prod1qty/10
$bon20=$prod1qty/20
$bon30=$prod1qty/30
$bon40=$prod1qty/40
$bon50=$prod1qty/50
$bon60=$prod1qty/60
$bon70=$prod1qty/70
$bon80=$prod1qty/80
$bon90=$prod1qty/90
if ($rand=2)
{
$prod1qty=$prod1qty-$bon10
}
if ($rand=4)
{
$prod1qty=$prod1qty+$bon20
}
if ($rand=6)
{
$prod1qty=$prod1qty-$bon30
}
if ($rand=8)
{
$prod1qty=$prod1qty+$bon40
}
if ($rand=10)
{
$prod1qty=$prod1qty-$bon50
}
if ($rand=12)
{
$prod1qty=$prod1qty+$bon60
}
if ($rand=14)
{
$prod1qty=$prod1qty-$bon70
}
if ($rand=16)
{
$prod1qty=$prod1qty+$bon80
}
if ($rand=18)
{
$prod1qty=$prod1qty-$bon90
}
if ($rand=22)
{
$prod1qty=$prod1qty+$bon90
}
if ($rand=24)
{
$prod1qty=$prod1qty-$bon80
}
if ($rand=26)
{
$prod1qty=$prod1qty+$bon70
}
if ($rand=28)
{
$prod1qty=$prod1qty-$bon60
}
if ($rand=30)
{
$prod1qty=$prod1qty+$bon50
}
if ($rand=32)
{
$prod1qty=$prod1qty-$bon40
}
if ($rand=34)
{
$prod1qty=$prod1qty+$bon30
}
if ($rand=36)
{
$prod1qty=$prod1qty-$bon20
}
if ($rand=38)
{
$prod1qty=$prod1qty+$bon10
}
}
$storelim=$gBuildingVar17-$prod1qty //----make sure there is space to store everythign that is produced
if ($gBuildingVar2=1)
{
if ($gBuildingVar[$prod1]>=$storelim)
{
$gBuildingVar23=1 //----no space, stop line from running
}
}
if ($gBuildingVar2=2) //----if automation is upgraded to level 2 (fully programmable)
{
if ($gBuildingVar22>=$gBuildingVar21)
{
$gBuildingVar23=5 //----line produced all it was told to produce, stop line from running
}
if ($gBuildingVar22<=$gBuildingVar21)
{
if ($gBuildingVar[$prod1]>=$storelim)
{
$gBuildingVar23=7 //----not finished producing, but not enough space to produce
// pause line and resume if space becomes available
}
}
}
if ($gBuildingVar23=0) //----this is where the script makes sure the demanded items exist
{
if ($gBuildingVar[$prod1d1]<$prod1d1qty)
{
$gBuildingVar23=2 //----stop line if the demanded item isn't in stock
}
if ($gBuildingVar[$prod1d2]<$prod1d2qty)
{
$gBuildingVar23=2
}
if ($gBuildingVar[$prod1d3]<$prod1d3qty)
{
$gBuildingVar23=2
}
if ($gBuildingVar[$prod1d4]<$prod1d4qty)
{
$gBuildingVar23=2
}
if ($gBuildingVar[$prod1d5]<$prod1d5qty)
{
$gBuildingVar23=2
}
if ($gBuildingVar[$prod1d6]<$prod1d6qty)
{
$gBuildingVar23=2
}
if ($gBuildingVar[$prod1d7]<$prod1d7qty)
{
$gBuildingVar23=2
}
if ($gBuildingVar23=2)
{
if ($gBuildingVar2=0) //----if automation is at level 0, line stops completely and settingsreset
{
$gBuildingVar23=4
$gBuildingVar20=0
}
}
}
if ($gBuildingVar23=0) //----if this var is *still* 0, then no problems exist and the building can actually produce
{
$gBuildingTimeVar1=$gServerVar9 //----activity counter, if building is inactive for too long, it shuts down
$gBuildingVar[$prod1]=$gBuildingVar[$prod1]+$prod1qty //----add produced items, remove demanded items
if ($prod1i2>0)
{
$gBuildingVar[$prod1i2]=$gBuildingVar[$prod1i2]-$prod1i2qty //----a few recipies make a 2nd item
}
if ($prod1d1qty>0)
{
$gBuildingVar[$prod1d1]=$gBuildingVar[$prod1d1]-$prod1d1qty
}
if ($prod1d2qty>0)
{
$gBuildingVar[$prod1d2]=$gBuildingVar[$prod1d2]-$prod1d2qty
}
if ($prod1d3qty>0)
{
$gBuildingVar[$prod1d3]=$gBuildingVar[$prod1d3]-$prod1d3qty
}
if ($prod1d4qty>0)
{
$gBuildingVar[$prod1d4]=$gBuildingVar[$prod1d4]-$prod1d4qty
}
if ($prod1d5qty>0)
{
$gBuildingVar[$prod1d5]=$gBuildingVar[$prod1d5]-$prod1d5qty
}
if ($prod1d6qty>0)
{
$gBuildingVar[$prod1d6]=$gBuildingVar[$prod1d6]-$prod1d6qty
}
if ($prod1d7qty>0)
{
$gBuildingVar[$prod1d7]=$gBuildingVar[$prod1d7]-$prod1d7qty
}
if ($gBuildingVar2=0) //----more checks after production to see if the line is good to produce next cycle
{
if ($gBuildingVar[$prod1]>=$storelim)
{
$gBuildingVar23=4
$gBuildingVar20=0
}
}
if ($gBuildingVar2=1)
{
if ($gBuildingVar[$prod1]>=$storelim)
{
$gBuildingVar23=1
}
}
if ($gBuildingVar2=2)
{
$gBuildingVar22=$gBuildingVar22+$prod1qty
if ($gBuildingVar22>=$gBuildingVar21)
{
$gBuildingVar23=5
}
if ($gBuildingVar22<=$gBuildingVar21)
{
if ($gBuildingVar[$prod1]>=$storelim)
{
$gBuildingVar23=7
}
}
}
}
}