[lua]if SERVER then
-- DISABLED
AddCSLuaFile( "shared.lua" )
end
SWEP.HoldType = "normal"
if CLIENT then
SWEP.PrintName = "HeartBeatBomb"
SWEP.Slot = 8
SWEP.SlotPos = 0
SWEP.ViewModelFOV = 55
SWEP.EquipMenuData = {
type="Weapon",
name = "HeartBeatBomb",
desc="A HeartBeatBomb.. Can regenerate\nhealth when low, blows\nup OnDeath, and\nexplodes in 3 minutes."
};
SWEP.Icon = "VGUI/ttt/icon_heartbeatbomb"
end
SWEP.Base = "weapon_tttbase"
SWEP.Instructions = "Left Click Sets Timer for Bomb. Right Click injects Health Syrum when Health is <40."
SWEP.Spawnable = true
SWEP.AdminSpawnable = false
SWEP.ViewModel = "models/weapons/v_c4.mdl"
SWEP.WorldModel = "models/weapons/v_c4.mdl"
SWEP.AutoSwitchTo = true
SWEP.AutoSwitchFrom = true
SWEP.DrawCrosshair = false
SWEP.ViewModelFlip = false
SWEP.Primary.Delay = 50.0
SWEP.Primary.ClipSize = 1
SWEP.Primary.Damage = 0
SWEP.Primary.Delay = 5.0
SWEP.Primary.Recoil = 0.5
SWEP.Primary.ClipMax = 1
SWEP.Primary.DefaultClip = 1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.Secondary.Delay = 5.0
SWEP.Kind = WEAPON_EQUIP
-- DISABLED
SWEP.CanBuy = {ROLE_TRAITOR} -- T's are the only ones who can purchase this.
SWEP.LimitedStock = true -- Limits to only be bought once.
SWEP.WeaponID = NONE
SWEP.AllowDrop = false
SWEP.NoSights = true
function SWEP:OnDrop()
self:Remove()
end
function SWEP:PrimaryAttack()
if self:CanPrimaryAttack() then
self.Owner:FireBullets( bullet )
--self.Owner:SelectWeapon("weapon_ttt_unarmed")
RunConsoleCommand("lastinv")
self.Owner:ChatPrint("HeartBeatBomb Planted on Yourself!")
hook.Add( "DoPlayerDeath", "TerroristDeath15", function( ply, attacker, dmg )
if ply == self.Owner and ply:IsValid() then --Checks if dead player has this bomb.
self:SetParent( self.Owner )
explode = ents.Create( "env_explosion" )
explode:SetOwner ( self:GetParent() )
explode:SetKeyValue( "iMagnitude", "400" )
explode:Fire( "Explode", 0, 0 )
explode:EmitSound( "weapon_BaseGrenade.Explode", 500, 500 )
explode:SetPos( self:GetParent():GetPos() )
explode:Spawn()
end
end)
timer.Create("EXPLOSION", 10, 1, function()
if self.Owner:Alive() then
self.Owner:Kill()
end
end)
end
end
function SWEP:SecondaryAttack()
if self:GetParent():Health() < 40 and self:GetParent():Health() > 0 then
x = 40 - self:GetParent():Health()
timer.Create("HealingT2", 1, x, function()
self:GetParent():SetHealth(self:GetParent():Health() +1)end)
--self.Owner:SelectWeapon("weapon_ttt_unarmed")
RunConsoleCommand("lastinv")
else self.Owner:ChatPrint("Your health is above 40. Syrum is ineffective.")
end
end
[/lua]
Alright guys, the only problem I have here is SWEP delay NOT working. I have this SWEP set up for the gamemode Trouble in Terrorist down, but if I leftclick (PrimaryAttack), it will start the timer twice for some reason, and kill the player. However, it will message "HeartBeatBomb Planted on Yourself" At LEAST twice. I have it to swep.Automatic to false, but it still does the same problem. Would you guys know a solution?
Also, I've tried Setting the Delay to something absurd, but that didn't work either.
What happens in detail:
PrimaryAttack is called, and then, timer is called twice / four times.
Then, 10 seconds later, the player dies, and an explosion is called via hook.
However, because it did it twice, it also displays an error message.
Another alternative is just getting it to NOT display any error messages, but I'd love to also get it to only print to chat once.
*bump*
Help would be nice. D:
It runs shared, meaning it runs on both server and client. If you want something to run once, use an if statement to see if it is running serverside or clientside depending on what you need.
[QUOTE=Chessnut;36970560]It runs shared, meaning it runs on both server and client. If you want something to run once, use an if statement to see if it is running serverside or clientside depending on what you need.[/QUOTE]
Ahh, thank you!
It works!
That would explain why it would print things multiple times!
Thank you! I'm not familiar with Gmod lua as much as I am with other games that use LUA.
:D
When you press +attack you must wait 5secs. change this to another value eg. 0.05
[QUOTE=KarBoy2314PL;36972987]When you press +attack you must wait 5secs. change this to another value eg. 0.05[/QUOTE]
It would still run the function twice. Also, the matter would be even worse. I wanted this "gun" to only work once with one "bullet"
But thanks.
Sorry, you need to Log In to post a reply to this thread.