math.random help

So I’m trying to make this SWep I made shoot 2 different props with secondary fire, like 50% chance it’ll shoot a saw blade, and 50% chance it’ll shoot a glass bottle. Here’s the code for the secondary fire.

[lua]
function SWEP:SecondaryAttack()
self.Weapon:EmitSound(“weapons/iceaxe/iceaxe_swing1.wav”)
self.Weapon:SetNextSecondaryFire(CurTime() + 0.3)
self.Weapon:SendWeaponAnim(ACT_VM_MISSCENTER)
if SERVER then
local bar = ents.Create(“prop_physics”)
local int1 = math.random(2)
if int1 = (1) then
bar:SetModel(“models/props_junk/sawblade001a.mdl”)
else
bar:SetModel(“models/props_junk/garbage_glassbottle001a.mdl”)
bar:SetAngles(self.Owner:EyeAngles())-- Angle(0,90,0))
bar:SetPos(self.Owner:GetShootPos())
bar:SetOwner(self.Owner)
bar:SetPhysicsAttacker(self.Owner)
bar:Spawn()
local phys = bar:GetPhysicsObject()
bar:Ignite(90)
phys:ApplyForceCenter(self.Owner:GetAimVector() * 1999999999)
phys:AddAngleVelocity(Vector(0,5000000,0))
bar:Fire(“kill”, “”, 5)
end
end
end
[/lua]
The code worked perfectly fine before I added the math.random.
And the error I get is weapons/my_gun/shared.lua:104: ‘then’ expected near ‘=’

Please help. :slight_smile:

the correct usage would be

[lua]
math.random(min,max)
[/lua]
for example:
[lua]
math.random(0,1)
[/lua]

Your if statement is also wrong. It should be:
[lua]
if( int1 == 1 ) then

else

end
[/lua]

-.- I knew most of this.
Thanks!

Passing a single argument to math.random returns a number between 0 and that argument.

[lua]math.random(1)[/lua]

[editline]09:19AM[/editline]

You obviously know this, I’m just letting the OP know.