• Little Lua Help believe its basic
    4 replies, posted
So I've heard about servers having a painstation, as a traitor you can buy it. It looks just like a health station, but does damage instead. Ive been adding custom guns on my server and I thought this would be a great/easy addition. I thought it would be as easy as stealing the ttt_health_station shared.lua and switching out "health" for "damage". I tried messing around with it however I couldn't get it to work. Any help on this would be GREATLY appreciated! Here is the code for the health station, I only switched the name/role that can buy it, everything else is back to default. Again any contribution would make my day! if SERVER then AddCSLuaFile( "shared.lua" ) end SWEP.HoldType = "normal" if CLIENT then SWEP.PrintName = "Pain Station" SWEP.Slot = 6 SWEP.ViewModelFOV = 10 SWEP.EquipMenuData = { type="Weapon", model="models/props/cs_office/microwave.mdl", desc="Allows people to heal when placed.\n\nSlow recharge. Anyone can use it, and\nit can be damaged. Can be checked for\nDNA samples of its users." }; SWEP.Icon = "VGUI/ttt/icon_health" end SWEP.Base = "weapon_tttbase" SWEP.ViewModel = "models/weapons/v_crowbar.mdl" SWEP.WorldModel = "models/props/cs_office/microwave.mdl" SWEP.DrawCrosshair = true SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = true SWEP.Primary.Ammo = "none" SWEP.Primary.Delay = 1.0 SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = true SWEP.Secondary.Ammo = "none" SWEP.Secondary.Delay = 1.0 -- This is special equipment SWEP.Kind = WEAPON_EQUIP SWEP.CanBuy = {ROLE_TRAITOR} -- only traitors can buy SWEP.LimitedStock = true -- only buyable once SWEP.WeaponID = AMMO_PAINSTATION SWEP.AllowDrop = false SWEP.NoSights = true function SWEP:OnDrop() self:Remove() end function SWEP:PrimaryAttack() self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) self:HealthDrop() end function SWEP:SecondaryAttack() self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay ) self:HealthDrop() end local throwsound = Sound( "Weapon_SLAM.SatchelThrow" ) -- ye olde droppe code function SWEP:HealthDrop() if SERVER then local ply = self.Owner if not ValidEntity(ply) then return end if self.Planted then return end local vsrc = ply:GetShootPos() local vang = ply:GetAimVector() local vvel = ply:GetVelocity() local vthrow = vvel + vang * 200 local health = ents.Create("ttt_health_station") if ValidEntity(health) then health:SetPos(vsrc + vang * 10) health:SetOwner(ply) health:Spawn() health:PhysWake() local phys = health:GetPhysicsObject() if ValidEntity(phys) then phys:SetVelocity(vthrow) end self:Remove() self.Planted = true end end self.Weapon:EmitSound(throwsound) end function SWEP:Reload() return false end function SWEP:OnRemove() if CLIENT and ValidEntity(self.Owner) and self.Owner == LocalPlayer() and self.Owner:Alive() then RunConsoleCommand("lastinv") end end if CLIENT then local hudtxt = {text="Click to place the health station", font="TabLarge", xalign=TEXT_ALIGN_RIGHT} function SWEP:DrawHUD() hudtxt.pos = {ScrW() - 80, ScrH() - 80} draw.Text(hudtxt) draw.TextShadow(hudtxt, 2) end end function SWEP:Deploy() if SERVER and IsValid(self.Owner) then self.Owner:DrawViewModel(false) end return true end function SWEP:DrawWorldModel() end function SWEP:DrawWorldModelTranslucent() end
Firstly place [lua] tags around the lua code. [lua] if SERVER then AddCSLuaFile( "shared.lua" ) end SWEP.HoldType = "normal" if CLIENT then SWEP.PrintName = "Pain Station" SWEP.Slot = 6 SWEP.ViewModelFOV = 10 SWEP.EquipMenuData = { type="Weapon", model="models/props/cs_office/microwave.mdl", desc="Allows people to heal when placed.\n\nSlow recharge. Anyone can use it, and\nit can be damaged. Can be checked for\nDNA samples of its users." }; SWEP.Icon = "VGUI/ttt/icon_health" end SWEP.Base = "weapon_tttbase" SWEP.ViewModel = "models/weapons/v_crowbar.mdl" SWEP.WorldModel = "models/props/cs_office/microwave.mdl" SWEP.DrawCrosshair = true SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = true SWEP.Primary.Ammo = "none" SWEP.Primary.Delay = 1.0 SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = true SWEP.Secondary.Ammo = "none" SWEP.Secondary.Delay = 1.0 -- This is special equipment SWEP.Kind = WEAPON_EQUIP SWEP.CanBuy = {ROLE_TRAITOR} -- only traitors can buy SWEP.LimitedStock = true -- only buyable once SWEP.WeaponID = AMMO_PAINSTATION SWEP.AllowDrop = false SWEP.NoSights = true function SWEP:OnDrop() self:Remove() end function SWEP:PrimaryAttack() self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) self:HealthDrop() end function SWEP:SecondaryAttack() self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay ) self:HealthDrop() end local throwsound = Sound( "Weapon_SLAM.SatchelThrow" ) -- ye olde droppe code function SWEP:HealthDrop() if SERVER then local ply = self.Owner if not ValidEntity(ply) then return end if self.Planted then return end local vsrc = ply:GetShootPos() local vang = ply:GetAimVector() local vvel = ply:GetVelocity() local vthrow = vvel + vang * 200 local health = ents.Create("ttt_health_station") if ValidEntity(health) then health:SetPos(vsrc + vang * 10) health:SetOwner(ply) health:Spawn() health:PhysWake() local phys = health:GetPhysicsObject() if ValidEntity(phys) then phys:SetVelocity(vthrow) end self:Remove() self.Planted = true end end self.Weapon:EmitSound(throwsound) end function SWEP:Reload() return false end function SWEP:OnRemove() if CLIENT and ValidEntity(self.Owner) and self.Owner == LocalPlayer() and self.Owner:Alive() then RunConsoleCommand("lastinv") end end if CLIENT then local hudtxt = {text="Click to place the health station", font="TabLarge", xalign=TEXT_ALIGN_RIGHT} function SWEP:DrawHUD() hudtxt.pos = {ScrW() - 80, ScrH() - 80} draw.Text(hudtxt) draw.TextShadow(hudtxt, 2) end end function SWEP:Deploy() if SERVER and IsValid(self.Owner) then self.Owner:DrawViewModel(false) end return true end function SWEP:DrawWorldModel() end function SWEP:DrawWorldModelTranslucent() end [/lua]
Where is ENT:OnUse()?
The SWEP creates an ent "ttt_health_station" (line 82). That's the ent you have to copy / edit.
[QUOTE=_nonSENSE;24909090]The SWEP creates an ent "ttt_health_station" (line 82). That's the ent you have to copy / edit.[/QUOTE] That's what I thought I had to edit but I guess I didn't know what I was doing. What do I change it to? And Nexus that code was the ttt_health_station shared.lua found in garrysmod/terrortown/entities/weapons/. Also I was wondering am I going to have to edit the ttt_health_station shared.lua found in garrysmod/terrortown/entities/entities/? I am not really sure what it is, most of the commands in it are ENT. or self.entity instead of SWEP. Is this what you are talking about? [editline]03:43AM[/editline] Ok I am pretty sure I have to edit both of these. What lines do I have to edit? Gamemode > terrortown > entities > weapons > weapon_ttt_healthstation [lua] if SERVER then AddCSLuaFile( "shared.lua" ) end SWEP.HoldType = "normal" if CLIENT then SWEP.PrintName = "Health Station" SWEP.Slot = 6 SWEP.SlotPos = 0 SWEP.ViewModelFOV = 10 SWEP.EquipMenuData = { type="Weapon", model="models/props/cs_office/microwave.mdl", desc="Allows people to heal when placed.\n\nSlow recharge. Anyone can use it, and\nit can be damaged. Can be checked for\nDNA samples of its users." }; SWEP.Icon = "VGUI/ttt/icon_health" end SWEP.Base = "weapon_tttbase" SWEP.Spawnable = true SWEP.AdminSpawnable = false SWEP.ViewModel = "models/weapons/v_crowbar.mdl" SWEP.WorldModel = "models/props/cs_office/microwave.mdl" SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false SWEP.DrawCrosshair = true SWEP.ViewModelFlip = false SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = true SWEP.Primary.Ammo = "none" SWEP.Primary.Delay = 1.0 SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = true SWEP.Secondary.Ammo = "none" SWEP.Secondary.Delay = 1.0 -- This is special equipment SWEP.Kind = WEAPON_EQUIP SWEP.CanBuy = {ROLE_DETECTIVE} -- only detectives can buy SWEP.LimitedStock = true -- only buyable once SWEP.WeaponID = AMMO_HEALTHSTATION SWEP.AllowDrop = false SWEP.NoSights = true function SWEP:OnDrop() self:Remove() end function SWEP:PrimaryAttack() self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) self:HealthDrop() end function SWEP:SecondaryAttack() self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay ) self:HealthDrop() end local throwsound = Sound( "Weapon_SLAM.SatchelThrow" ) -- ye olde droppe code function SWEP:HealthDrop() if SERVER then local ply = self.Owner if not ValidEntity(ply) then return end if self.Planted then return end local vsrc = ply:GetShootPos() local vang = ply:GetAimVector() local vvel = ply:GetVelocity() local vthrow = vvel + vang * 200 local health = ents.Create("ttt_health_station") if ValidEntity(health) then health:SetPos(vsrc + vang * 10) health:SetOwner(ply) health:Spawn() health:PhysWake() local phys = health:GetPhysicsObject() if ValidEntity(phys) then phys:SetVelocity(vthrow) end self:Remove() self.Planted = true end end self.Weapon:EmitSound(throwsound) end function SWEP:Reload() return false end function SWEP:OnRemove() if CLIENT and ValidEntity(self.Owner) and self.Owner == LocalPlayer() and self.Owner:Alive() then RunConsoleCommand("lastinv") end end if CLIENT then local hudtxt = {text="Click to place the health station", font="TabLarge", xalign=TEXT_ALIGN_RIGHT} function SWEP:DrawHUD() hudtxt.pos = {ScrW() - 80, ScrH() - 80} draw.Text(hudtxt) draw.TextShadow(hudtxt, 2) end end -- Invisible, same hacks as holstered weapon local hidden = false function SWEP:Deploy() hidden = false return true end function SWEP:DrawWorldModel() end function SWEP:DrawWorldModelTranslucent() end -- not able to do DrawModel stuff in Deploy, so here's a hack function SWEP:Think() if SERVER and not hidden and ValidEntity(self.Owner) and self.Owner:GetActiveWeapon() == self.Weapon then self.Owner:DrawViewModel(false) self.Owner:DrawWorldModel(false) hidden = true end end [/lua] Next this is the file from Gamemode > terrortown > entities > entities > ttt_healthstation [lua] ---- Health dispenser if SERVER then AddCSLuaFile("shared.lua") end if CLIENT then -- this entity can be DNA-sampled so we need some display info ENT.Icon = "VGUI/ttt/icon_health" ENT.PrintName = "Health Station" ENT.TargetIDHint = { name="Health Station", hint="USE to receive health. Charge: %d.", fmt=function(ent, str) return Format(str, IsValid(ent) and ent:GetStoredHealth() or 0) end }; end ENT.Type = "anim" ENT.Model = Model("models/props/cs_office/microwave.mdl") ENT.CanUseKey = true ENT.CanHavePrints = true ENT.MaxHeal = 25 ENT.MaxStored = 200 ENT.RechargeRate = 1 ENT.RechargeFreq = 2 -- in seconds AccessorFuncDT(ENT, "StoredHealth", "StoredHealth") function ENT:SetupDataTables() self:DTVar("Int", 0, "StoredHealth") end function ENT:Initialize() self.Entity:SetModel(self.Model) self.Entity:PhysicsInit(SOLID_VPHYSICS) self.Entity:SetMoveType(MOVETYPE_VPHYSICS) self.Entity:SetSolid(SOLID_VPHYSICS) self.Entity:SetCollisionGroup(COLLISION_GROUP_NONE) if SERVER then self.Entity:SetMaxHealth(200) local phys = self.Entity:GetPhysicsObject() if IsValid(phys) then phys:SetMass(200) end end self.Entity:SetHealth(200) self.Entity:SetColor(180, 180, 255, 255) self:SetStoredHealth(200) self.fingerprints = {} end function ENT:UseOverride(activator) if ValidEntity(activator) and activator:IsPlayer() and activator:IsActive() then self:GiveHealth(activator) end end function ENT:AddToStorage(amount) self:SetStoredHealth(math.min(self.MaxStored, self:GetStoredHealth() + amount)) end function ENT:TakeFromStorage(amount) -- if we only have 5 healthpts in store, that is the amount we heal amount = math.min(amount, self:GetStoredHealth()) self:SetStoredHealth(math.max(0, self:GetStoredHealth() - amount)) return amount end local healsound = Sound("items/medshot4.wav") local failsound = Sound("items/medshotno1.wav") function ENT:GiveHealth(ply) if self:GetStoredHealth() > 0 then local dmg = ply:GetMaxHealth() - ply:Health() if dmg > 0 then -- constant clamping, no risks local healed = self:TakeFromStorage(math.min(self.MaxHeal, dmg)) local new = math.min(ply:GetMaxHealth(), ply:Health() + healed) ply:SetHealth(new) self:EmitSound(healsound) if not table.HasValue(self.fingerprints, ply) then table.insert(self.fingerprints, ply) end else ply:ChatPrint("Your health is full.") self:EmitSound(failsound) end else ply:ChatPrint("The health station is empty!") self:EmitSound(failsound) end end -- traditional equipment destruction effects local zapsound = Sound("npc/assassin/ball_zap1.wav") function ENT:OnTakeDamage(dmginfo) self:TakePhysicsDamage(dmginfo) self:SetHealth(self:Health() - dmginfo:GetDamage()) if self:Health() < 0 then self:Remove() local effect = EffectData() effect:SetOrigin(self:GetPos()) util.Effect("cball_explode", effect) WorldSound(zapsound, self:GetPos()) if IsValid(self:GetOwner()) then TraitorMsg(self:GetOwner(), "YOUR HEALTH STATION HAS BEEN DESTROYED!") end end end if CLIENT then -- flash effect local nextflash = 0 function ENT:Think() if nextflash < CurTime() then
Sorry, you need to Log In to post a reply to this thread.