hey guys i was just curious if anyone could help me out i want to make a mapping entity that i can place that will spawn a weapon at random. ive been out of QC for a long time so ive been feeling a bit confused. i know i should probably start in items.qc but past that i'm drawing a blank any tips / pointers?

currently this is what i have... but it does nothing...

thanks to shpuld this has been addressed!

currently this is what i have... but it does nothing...

Code:

void() weapon_rando = { local float r; r = random(); if (r == 1) { weapon_lightning();} if (r == 2) { weapon_rocketlauncher();} if (r == 3) { weapon_grenadelauncher();} if (r == 4) { weapon_supernailgun();} if (r == 5) { weapon_nailgun();} if (r == 6) { weapon_supershotgun();} else return; };

<+Shpuld> random() returns a float between 0 and 1

<+ceriux> so use decimals?

<+ceriux> 0, 0.1, 0.2, 0.3 ect

<+Shpuld> so you'd want to do r = random() * numberofweapons;

<+Shpuld> and then if(r < 1) { ... } else if(r < 2) { ... } ...

<+ceriux> ahh

<+ceriux> okay lemme try that thanks

<+Shpuld> you could use if(r<1/6) etc but that's not quite as readable if you ask me

<+ceriux> so use decimals?

<+ceriux> 0, 0.1, 0.2, 0.3 ect

<+Shpuld> so you'd want to do r = random() * numberofweapons;

<+Shpuld> and then if(r < 1) { ... } else if(r < 2) { ... } ...

<+ceriux> ahh

<+ceriux> okay lemme try that thanks

<+Shpuld> you could use if(r<1/6) etc but that's not quite as readable if you ask me

## Comment