PCP Weapon for TTT (help)

I’ve been working on this, but, I honestly have no clue what I’m doing here, I feel like a preschooler in middle school. Any help?
[lua]
if SERVER then
AddCSLuaFile( “shared.lua” )
end

SWEP.HoldType = “grenade”

if CLIENT then
SWEP.PrintName = “Not Drugs.”
SWEP.Slot = 3

SWEP.Icon = “VGUI/ttt/icon_nades”

SWEP.EquipMenuData = {
type = “item_weapon”,
desc = “Super PCP Man, away!”,
name = “PCP”
};
end

SWEP.Base = “weapon_tttbasegrenade”

SWEP.Spawnable = true
SWEP.AdminSpawnable = true

SWEP.WeaponID = AMMO_SMOKE
SWEP.Kind = WEAPON_NADE

SWEP.UseHands = true
SWEP.ViewModelFlip = false
SWEP.ViewModelFOV = 54
SWEP.ViewModel = “models/weapons/cstrike/c_eq_smokegrenade.mdl”
SWEP.WorldModel = “models/weapons/w_eq_smokegrenade.mdl”
SWEP.Weight = 5
SWEP.AutoSpawnable = true
SWEP.Primary.ClipSize = 1
SWEP.Primary.DefaultClip = 1
SWEP.Primary.ClipMax = 1
SWEP.Primary.Ammo = “none”
local ShootSound = Sound (“pcp.wav”);
SWEP.CanBuy = {ROLE_TRAITOR}

– really the only difference between grenade weapons: the model and the thrown
– ent.

function SWEP:PrimaryAttack()
ply:SetHealth(200);
self:EmitSound (ShootSound);
end
[/lua]

Well, any extra information? Like, what problem you’re having or what you’re trying to do.

Your thread’s a little vague, which makes it hard to help.

Pretty much, I want it to set the players health to 200, play pcp.wav then after 30 seconds I want it to set the players health back to 100. I tried a timer, and then gave up. haha

You have ply in your PrimaryAttack() function but it isn’t defined anywhere.

For the timer, you could do (don’t forget to define ply):
[lua]
timer.Create(“PCP”…ply:UniqueID(), 30, 1, function() – run it once after 30 seconds
if IsValid(ply) and ply:Alive() then
ply:SetHealth(100)
end
end)
[/lua]
But, the thing I don’t like about it is that you want the player’s health to be set to 100 after 30 seconds, even though they could of lost 180 health. Someone could be in a firefight with them and almost kill them when suddenly they regain 100 HP. I think this method would balance it better:
[lua]
timer.Create(“PCP”…ply:UniqueID(), 30, 1, function() – run it once after 30 seconds
if IsValid(ply) and ply:Alive() then
local curhealth = ply:Health()
local newhealth = curhealth - 100
if newhealth < 1 then
ply:SetHealth(1)
else
ply:SetHealth(newhealth)
end
end
end)
[/lua]
This would set their HP to 1 if they lost over 100 HP during the span of the PCP. Perhaps you’d like another alternate method:
[lua]
timer.Create(“PCP”…ply:UniqueID(), 30, 1, function() – run it once after 30 seconds
if IsValid(ply) and ply:Alive() then
local curhealth = ply:Health()
if curhealth > 100 then
ply:SetHealth(100)
end
end
end)
[/lua]
This way would keep whatever their health is if it’s less than 100, and if it’s greater than 100, sets it to 100.

However, this can carry over into the next round so upon each new round have it remove the timer if it exists.
[lua]
hook.Add(“TTTPrepareRound”, “PCPRemove”, function()
for k,v in pairs(player.GetAll()) do
if timer.Exists(“PCP”…v:UniqueID()) then
timer.Destroy(“PCP”…v:UniqueID())
end
end
end)
[/lua]

Choose whatever method you like best, I hope I helped.