To be simple, I'm trying to have a unit be given random weapons of a range of my choosing with probabilities of my choosing. I want this to be done through a simple execution of a script in the initialization field for each unit. Forgive the manner in which I attempted this, it was the first approach that came to mind. Prepare for if statements galore and unorganized syntax. Oh, and I'm using FFUR SLX 2007.
First off, I state that I want to execute weapon.sqs in the unit's init field. That works fine at least.
weapon.sqs:
canhaveprimary = random(100)+1; //random number that determines if the unit gets a primary
canhavepistol = random(100)+1; //random number that determines if the unit gets a secondary
canhaverpg = random(100)+1; //random number that determines if the unit gets an rpg
canhavefrag = random(100)+1; //random number that determines if the unit gets a grenade
canhavebomb = random(100)+1; //random number that determines if the unit gets a satchel charge
canhavesmoke = random(100)+1; //random number that determines if the unit gets a smoke grenade
if (canhaveprimary > 50) then {[] exec "primaryrandom.sqs"}; //50% chance to execute script to distribute a random primary
if (canhavepistol <= 25) then {[] exec "pistolrandom.sqs"}; //25% chance to execute script to distribute a random sidearm
if (canhaverpg <= 5) then [{this addweapon "rpglauncher"} , {this addmagazine "rpglauncher"}]; //5% chance to distribute an rpg
if (canhavefrag <= 10) then {this addmagazine "handgrenade"}; //10% chance to distribute a grenade
if (canhavebomb <= 5) then {this addmagazine "pipebomb"}; //5% chance to distribute a satchel charge
if (canhavesmoke <= 10) then {this addmagazine "ffur_anm8"}; //10% chance to distribute a smoke
From this script two others can be executed:
primaryrandom.sqs:
primarygun = random(202); //same crappy system as before, just bigger
if (primarygun <= 10) then [{this addweapon "G36a"} , {this addmagazine "G36amag"}];
if (primarygun > 10 and <= 20) then [{this addweapon "steyr"} , {this addmagazine "steyrmag"}];
if (primarygun > 20 and <= 30) then [{this addweapon "xms"} , {this addmagazine "m4"}];
if (primarygun > 30 and <= 40) then [{this addweapon "fal"} , {this addmagazine "falmag"}];
if (primarygun > 40 and <= 50) then [{this addweapon "hkg3"} , {this addmagazine "hkg3mag"}];
if (primarygun > 50 and <= 60) then [{this addweapon "ak74"} , {this addmagazine "ak74"}];
if (primarygun > 60 and <= 70) then [{this addweapon "ak74su"} , {this addmagazine "ak74"}];
if (primarygun > 70 and <= 80) then [{this addweapon "ak47"} , {this addmagazine "ak47"}];
if (primarygun > 80 and <= 90) then [{this addweapon "ak47cz"} , {this addmagazine "ak47"}];
if (primarygun > 90 and <= 100) then [{this addweapon "svddragunov"} , {this addmagazine "svddragunov"}];
if (primarygun > 100 and <= 110) then [{this addweapon "bizon"} , {this addmagazine "bizonmag"}];
if (primarygun > 110 and <= 120) then [{this addweapon "ak47s"} , {this addmagazine "ak47"}];
if (primarygun > 120 and <= 130) then [{this addweapon "xms2"} , {this addmagazine "m4"}];
if (primarygun > 130 and <= 140) then [{this addweapon "m16s"} , {this addmagazine "m4"}];
if (primarygun > 140 and <= 150) then [{this addweapon "m24"} , {this addmagazine "m24mag"}];
if (primarygun > 150 and <= 165) then [{this addweapon "huntingrifle"} , {this addmagazine "huntingriflemag"} , {this addmagazine "huntingriflemag"}];
if (primarygun > 165 and <= 180) then [{this addweapon "kozlice"} , {this addmagazine "kozliceball"} , {this addmagazine "kozliceshell"}];
if (primarygun > 180 and <= 187) then [{this addweapon "ak47grenadelauncher"} , {this addmagazine "ak47"} , {this addmagazine "grenadelauncher"}];
if (primarygun > 187 and <= 194) then [{this addweapon "ak74grenadelauncher"} , {this addmagazine "ak74"} , {this addmagazine
"grenadelauncher"}];
if (primarygun > 194 and <= 199) then [{this addweapon "mm1"} , {this addmagazine "mm1magazine"}];
if (primarygun == 200) then [{this addweapon "pk"} , {this addmagazine "pk"}];
if (primarygun == 201) then [{this addweapon "m60"} , {this addmagazine "m60"}];
if (primarygun >= 202) then [{this addweapon "m240g_elc"} , {this addmagazine "m240g_elcmag"}];
pistolrandom.sqs:
pistolgun = random(100);
if (pistolgun <= 10) then [{this addweapon "cz75"} , {this addmagazine "cz75mag"}];
if (pistolgun > 10 and <= 20) then [{this addweapon "tokarev"} , {this addmagazine "tokarevmag"}];
if (pistolgun > 20 and <= 30) then [{this addweapon "m1911"} , {this addmagazine "m1911mag"}];
if (pistolgun > 30 and <= 40) then [{this addweapon "p228"} , {this addmagazine "p228mag"}];
if (pistolgun > 40 and <= 50) then [{this addweapon "beretta"} , {this addmagazine "berettamag"}];
if (pistolgun > 50 and <= 60) then [{this addweapon "glock"} , {this addmagazine "glockmag"}];
if (pistolgun > 60 and <= 65) then [{this addweapon "skorpion"} , {this addmagazine "skorpionmag"}];
if (pistolgun > 65 and <= 70) then [{this addweapon "ingram"} , {this addmagazine "ingrammag"}];
if (pistolgun > 70 and <= 85) then [{this addweapon "revolver"} , {this addmagazine "revolvermag"}];
if (pistolgun >= 85) then [{this addweapon "p2a1"} , {this addmagazine "white_flare_mag"}];
The game is giving me an 'invalid number used in expression' error, which likely means there's a consistent error in every script. Any ideas? Help would be much appreciated.