I am going to apologize in advance because there are probably a few threads out there that would answer my question, but I am stating to want to burn my computer because this LUA will not work! What I want to do is have a re-skinned .357 magnum called the golden gun to be given to all players when they spawn (like the crowbar). This gun would have a 50% chance of killing you when fired and a 50% chance of a one hit kill (if you hit your target). I have gotten the kill down just getting anything that would make it so there was a 50/50 chance is not working at all. Please post any further questions below and thank you for any help you can provide.
[CODE]resource.AddFile("materials/models/weapons/357_sheet.vdf")
if SERVER then
AddCSLuaFile( "shared.lua" )
end
SWEP.HoldType = "pistol"
if CLIENT then
SWEP.PrintName = "Golden Gun"
SWEP.Author = "Dr.Gusta"
SWEP.Slot = 10
SWEP.Icon = "VGUI/ttt/icon_deagle"
end
SWEP.Base = "weapon_tttbase"
SWEP.Spawnable = false
SWEP.AdminSpawnable = true
SWEP.Kind = WEAPON_PISTOL
SWEP.WeaponID = AMMO_DEAGLE
SWEP.Primary.Ammo = "" -- hijack an ammo type we don't use otherwise
SWEP.Primary.Recoil = 0
SWEP.Primary.Damage = 0
SWEP.Primary.Delay = 0.6
SWEP.Primary.Cone = 0
SWEP.Primary.ClipSize = 1
SWEP.Primary.ClipMax = 1
SWEP.Primary.DefaultClip = 1
SWEP.Primary.Automatic = false
SWEP.DrawCrosshair = true
SWEP.HeadshotMultiplier = 1
SWEP.AutoSpawnable = false
SWEP.AmmoEnt = ""
SWEP.Primary.Sound = Sound( "Weapon_Elite.Single" )
SWEP.UseHands = true
SWEP.ViewModelFlip = false
SWEP.ViewModelFOV = 54
SWEP.ViewModel = "models/weapons/c_357.mdl"
SWEP.WorldModel = "models/weapons/w_357.mdl"
SWEP.IronSightsPos = Vector(-6.361, -3.701, 2.15)
SWEP.IronSightsAng = Vector(0, 0, 0)
function SWEP:Initialize()
if ( SERVER ) then
self:SetWeaponHoldType( "pistol" )
end
if ( CLIENT ) then
self.Owner:GetViewModel( ):SetMaterial("materials/models/weapons/357_sheet.vdf")
end
end
function SWEP:Reload()
end
function SWEP:Think()
end
function SWEP:PrimaryAttack()
if not self:CanPrimaryAttack() then return end
x = math.random(1,100)
if x < 50 then
self.Owner:Kill(1)
else
--code here that would equal a one hit kill
end
[/CODE]
It's probably because you're missing an extra "end" on the end?
Also you could just do like,
[LUA]
if math.random(2) == 2 then
-- do stuff
else
-- do other stuff
end[/lua]
I don't understand what the actual problem you are having is since all you said is that you're having problems with a random chance and didn't even specify what problem(s) you were having (errors?, nothing happening?)
If you're looking for the other part of the code to be a one hit kill just set the SWEP's Damage to like 2000 and then put the normal bullet firing code in there.
HOLY SHIT thank you! The extra "end" fixed my biggest problem, the math random BS. My second big problem is being able to have this appear in everyone inventory when they spawn in. I have yet to attempt this but have no idea where to start. Thanks again
[QUOTE=Dr.Gusta;41778980]HOLY SHIT thank you! The extra "end" fixed my biggest problem, the math random BS. My second big problem is being able to have this appear in everyone inventory when they spawn in. I have yet to attempt this but have no idea where to start. Thanks again[/QUOTE]
Something like:
[lua]if SERVER then
function PassOutDeagles(ply)
if ply:IsTerror() then
ply:Give("weapon_mygun")
end
end
hook.Add("PlayerSpawn", "GiveColoredDeagles", PassOutDeagles)
end[/lua]
Just change "weapon_mygun" to your gun entity name and paste it at the end of the file.
One last question. How can I set the cause of death so when you use the golden gun and it kills you instead of the cause of death saying "Cause of death unknown". It would say something like "He gabled at a desperate time and lost." Thanks for all the help so far I will post my final code when done.
Sorry, you need to Log In to post a reply to this thread.