[CODE] if SERVER then
AddCSLuaFile( "shared.lua" )
resource.AddFile("materials/ttt/icon_tripwire.png")
end
SWEP.HoldType = "slam"
if CLIENT then
SWEP.PrintName = "Tripwire Mine"
SWEP.Slot = 6
SWEP.ViewModelFlip = true
SWEP.ViewModelFOV = 64
SWEP.EquipMenuData = {
type = "item_weapon",
desc = "Mine used to keep someone out of somewhere./nUse to catch them by surprise./n"
};
SWEP.Icon = "tripmine/icon_tripwire.png"
end
SWEP.Base = "weapon_tttbase"
SWEP.ViewModel = "models/weapons/v_slam.mdl" -- Weapon view model
SWEP.WorldModel = "models/weapons/w_slam.mdl" -- Weapon world model
SWEP.FiresUnderwater = false
SWEP.Primary.Sound = Sound("") -- Script that calls the primary fire sound
SWEP.Primary.Delay = .5 -- This is in Rounds Per Minute
SWEP.Primary.ClipSize = 1 -- Size of a clip
SWEP.Primary.DefaultClip = 1 -- Bullets you start with
SWEP.Primary.Automatic = false -- Automatic = true; Semi Auto = false
SWEP.Primary.Ammo = "slam"
SWEP.NoSights = true
SWEP.AllowDrop = false
SWEP.Kind = WEAPON_EQUIP
SWEP.CanBuy = {ROLE_TRAITOR}
function SWEP:Deploy()
self:SendWeaponAnim( ACT_SLAM_TRIPMINE_DRAW )
return true
end
function SWEP:SecondaryAttack()
return false
end
function SWEP:OnRemove()
if CLIENT and IsValid(self.Owner) and self.Owner == LocalPlayer() and self.Owner:Alive() then
RunConsoleCommand("lastinv")
end
end
function SWEP:PrimaryAttack()
self:TripMineStick()
self.Weapon:EmitSound( Sound( "Weapon_SLAM.SatchelThrow" ) )
self.Weapon:SetNextPrimaryFire(CurTime()+(self.Primary.Delay))
end
function SWEP:TripMineStick()
if SERVER then
local ply = self.Owner
if not IsValid(ply) then return end
local ignore = {ply, self.Weapon}
local spos = ply:GetShootPos()
local epos = spos + ply:GetAimVector() * 80
local tr = util.TraceLine({start=spos, endpos=epos, filter=ignore, mask=MASK_SOLID})
if tr.HitWorld then
local mine = ents.Create("npc_tripmine")
if IsValid(mine) then
local tr_ent = util.TraceEntity({start=spos, endpos=epos, filter=ignore, mask=MASK_SOLID}, mine)
if tr_ent.HitWorld then
local ang = tr_ent.HitNormal:Angle()
ang.p = ang.p + 90
mine:SetPos(tr_ent.HitPos + (tr_ent.HitNormal * 3))
mine:SetAngles(ang)
mine:SetOwner(ply)
mine:Spawn()
mine.fingerprints = self.fingerprints
self:SendWeaponAnim( ACT_SLAM_TRIPMINE_ATTACH )
local holdup = self.Owner:GetViewModel():SequenceDuration()
timer.Simple(holdup,
function()
if SERVER then
self:SendWeaponAnim( ACT_SLAM_TRIPMINE_ATTACH2 )
end
end)
timer.Simple(holdup + .1,
function()
if SERVER then
if self.Owner == nil then return end
if self.Weapon:Clip1() == 0 && self.Owner:GetAmmoCount( self.Weapon:GetPrimaryAmmoType() ) == 0 then
self.Owner:StripWeapon(self.Gun)
RunConsoleCommand("lastinv")
else
self:Deploy()
end
end
end)
self:Remove()
self.Planted = true
end
end
end
end
end
function SWEP:Reload()
return false
end[/CODE]
So this is for the tripmine and it is in /garrysmod/gamemodes/terrortown/entities/weapons/weapon_ttt_tripmine/shared.lua
But it does not let me place it?
Give us the entity code.
[QUOTE=BFG9000;41252058]Give us the entity code.[/QUOTE]
There is no entity code
[code]local mine = ents.Create("npc_tripmine")[/code]
To help: uno momento while I check it over :P
[editline]30th June 2013[/editline]
can't find anything but, but here is mine, slightly modified:
[code]
if SERVER then
AddCSLuaFile( "shared.lua" )
end
SWEP.HoldType = "slam"
if CLIENT then
SWEP.PrintName = "Tripwire Mine"
SWEP.Slot = 7
SWEP.ViewModelFlip = true
SWEP.ViewModelFOV = 64
SWEP.EquipMenuData = {
type = "item_weapon",
desc = [[A mine, with a red laster, placeable on walls.
When the red laser is crossed by innocents or
detectives, the mine explodes. Can be shot and
destroyed by innocents and detectives.]]
};
SWEP.Icon = "VGUI/ttt/icon_tripmine"
end
SWEP.Base = "weapon_tttbase"
SWEP.ViewModel = "models/weapons/v_slam.mdl" -- Weapon view model
SWEP.WorldModel = "models/weapons/w_slam.mdl" -- Weapon world model
SWEP.FiresUnderwater = false
SWEP.Primary.Sound = Sound("") -- Script that calls the primary fire sound
SWEP.Primary.Delay = .5 -- This is in Rounds Per Minute
SWEP.Primary.ClipSize = 3 -- Size of a clip
SWEP.Primary.DefaultClip = 3 -- Bullets you start with
SWEP.Primary.Automatic = false -- Automatic = true; Semi Auto = false
SWEP.Primary.Ammo = "slam"
SWEP.LimitedStock = true
SWEP.NoSights = true
SWEP.AllowDrop = false
SWEP.Kind = WEAPON_EQUIP2
SWEP.CanBuy = {ROLE_TRAITOR}
function SWEP:Deploy()
self:SendWeaponAnim( ACT_SLAM_TRIPMINE_DRAW )
return true
end
function SWEP:SecondaryAttack()
return false
end
function SWEP:OnRemove()
if CLIENT and IsValid(self.Owner) and self.Owner == LocalPlayer() and self.Owner:Alive() then
RunConsoleCommand("lastinv")
end
end
function SWEP:PrimaryAttack()
self:TripMineStick()
self.Weapon:EmitSound( Sound( "Weapon_SLAM.SatchelThrow" ) )
self.Weapon:SetNextPrimaryFire(CurTime()+(self.Primary.Delay))
end
function SWEP:TripMineStick()
if SERVER then
local ply = self.Owner
if not IsValid(ply) then return end
local ignore = {ply, self.Weapon}
local spos = ply:GetShootPos()
local epos = spos + ply:GetAimVector() * 80
local tr = util.TraceLine({start=spos, endpos=epos, filter=ignore, mask=MASK_SOLID})
if tr.HitWorld then
local mine = ents.Create("npc_tripmine")
if IsValid(mine) then
local tr_ent = util.TraceEntity({start=spos, endpos=epos, filter=ignore, mask=MASK_SOLID}, mine)
if tr_ent.HitWorld then
local ang = tr_ent.HitNormal:Angle()
ang.p = ang.p + 90
mine:SetPos(tr_ent.HitPos + (tr_ent.HitNormal * 3))
mine:SetAngles(ang)
mine:SetOwner(ply)
mine:Spawn()
mine.fingerprints = self.fingerprints
self:SendWeaponAnim( ACT_SLAM_TRIPMINE_ATTACH )
local holdup = self.Owner:GetViewModel():SequenceDuration()
timer.Simple(holdup,
function()
if SERVER then
self:SendWeaponAnim( ACT_SLAM_TRIPMINE_ATTACH2 )
end
end)
timer.Simple(holdup + .1,
function()
if SERVER then
if self.Owner == nil then return end
if self.Weapon:Clip1() == 0 && self.Owner:GetAmmoCount( self.Weapon:GetPrimaryAmmoType() ) == 0 then
--self.Owner:StripWeapon(self.Gun)
--RunConsoleCommand("lastinv")
self:Remove()
else
self:Deploy()
end
end
end)
--self:Remove()
self.Planted = true
self:TakePrimaryAmmo( 1 )
end
end
end
end
end
function SWEP:Reload()
return false
end
[/code]
Tested above code on my server, seems to be working 100%.
woah wait so it just creates the HL2 SLAM with a laser?
[QUOTE=BFG9000;41260398]woah wait so it just creates the HL2 SLAM with a laser?[/QUOTE]
Yes. I'm going to eventually code one that uses a custom entity because the filter sucks.
Wait so how the hell are you going to make it only detect innocent and detectives and not traitors?
In any case, Swiftone's post should be of note because it might mean that something else is fucking up your addon. Do you have any large, overbearing addons that like to interfere with others?
[QUOTE=BFG9000;41266476]Wait so how the hell are you going to make it only detect innocent and detectives and not traitors?[/QUOTE]
If currently doesn't and that's the problem.
OP if you could post whether it worked or not/"solved" it would be nice.
My ent I made for the tripmines. It's kinda buggy and I haven't gotten around to fixing it but it does check for roles and it can be destroyed. The beam can also be blocked by objects. The bugs are that it doesn't always pick up when someone passes through it, kind of 50/50 chance there. The beam also vanishes when the ent goes off your screen.
This is heavily WIP and it's just slapped together codes from different entities. Hope you get some use/ideas out of how to make it right.
[CODE]
if SERVER then
AddCSLuaFile("shared.lua")
end
ENT.Type = "anim"
ENT.Model = Model("models/Items/combine_rifle_ammo01.mdl")
ENT.Stuck = false
ENT.Weaponised = false
ENT.PunchMax = 6
ENT.PunchRemaining = 6
function ENT:Initialize()
self.Entity:SetModel("models/Items/combine_rifle_ammo01.mdl")
self.Entity:PhysicsInit(SOLID_VPHYSICS)
self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
self.Entity:SetSolid(SOLID_VPHYSICS)
self.Entity:DrawShadow(false)
self.Entity:SetCollisionGroup(COLLISION_GROUP_WORLD)
local phys = self.Entity:GetPhysicsObject():EnableMotion(false)
self:SetColor(Color(25, 122, 21, 255))
--self:StartEffects()
--self:Explosive()
self.Entity:EmitSound("C4.Plant")
end
local matTripmineLaser = Material( "sprites/bluelaser1" )
local matLight = Material( "models/roller/rollermine_glow" )
local colBeam = Color( 100, 100, 210, 30 )
local colLaser = Color( 100, 100, 240, 30 )
function ENT:Think()
if not self.endpos then
local t = {}
t.start = self:GetPos()
t.endpos = t.start + self:GetUp() * 4096
t.filter = self
local tr = util.TraceLine(t)
self.endpos = tr.HitPos
if tr.HitNonWorld then
if SERVER then
local ply = self.Owner
local ignore = {ply, self}
if not IsValid(ply) then return end
for k, v in pairs(player.GetAll()) do
if v:IsActiveTraitor() or v:IsSpec() then
table.insert(ignore, v)
end
if not table.HasValue(ignore,tr.Entity) and tr.Entity:IsPlayer() then
self:Explosive()
self:Remove()
end
end
end
end
end
end
function ENT:Draw()
if not self.endpos then
return
end
render.SetMaterial( matTripmineLaser )
// offset the texture coords so it looks like it is scrolling
local TexOffset = 6
// Make the texture coords relative to distance so they are always a nice size
local Distance = self.endpos:Distance( self:GetPos() )
// Draw the beam
render.DrawBeam( self.endpos, self.Entity:GetPos(), 6, TexOffset, TexOffset+Distance, colBeam )
render.DrawBeam( self.endpos, self.Entity:GetPos(), 3, TexOffset, TexOffset+Distance, colBeam )
// Draw a quad at the hitpoint to fake the laser hitting it
render.SetMaterial( matLight )
local Size = math.Rand( 3, 5 )
local Normal = (self.Entity:GetPos()-self.endpos):GetNormal() * 0.1
render.DrawQuadEasy( self.endpos + Normal, Normal, Size, Size, colLaser, 0 )
self.Entity:DrawModel()
end
function ENT:StartEffects()
local sprite = ents.Create( "env_sprite" )
if IsValid(sprite) then
-- local angpos = self:GetAttachment(ball)
-- sometimes attachments don't work (Lua-side) on dedicated servers,
-- so have to fudge it
local ang = self:GetAngles()
local pos = self:GetPos() + self:GetAngles():Up() * 6
sprite:SetPos(pos)
sprite:SetAngles(ang)
sprite:SetParent(self.Entity)
sprite:SetKeyValue("spawnflags", "1")
sprite:SetKeyValue("scale", "0.25")
sprite:SetKeyValue("rendermode", "5")
sprite:SetKeyValue("renderfx", "7")
sprite:Spawn()
sprite:Activate()
self.BallSprite = sprite
end
local effect = EffectData()
effect:SetStart(self:GetPos())
effect:SetOrigin(self:GetPos())
effect:SetNormal(self:GetAngles():Up())
util.Effect("ManhackSparks", effect, true, true)
if SERVER then
local ball = self:LookupAttachment("attach_ball")
util.SpriteTrail(self.Entity, ball, Color(250, 250, 250), false, 30, 0, 1, 0.07, "trails/physbeam.vmt")
end
end
function ENT:Explosive()
local phexp = ents.Create("env_explosion")
if IsValid(phexp) then
phexp:SetPos(self:GetPos())
phexp:SetKeyValue("magnitude", 100)
phexp:SetKeyValue("radius", 128)
phexp:SetKeyValue("spawnflags", 1 + 2)
phexp:Spawn()
phexp:Fire("Explode", "", 0)
end
local phyexp = ents.Create("env_physexplosion")
phyexp:SetPos(self:GetPos())
phyexp:SetKeyValue("magnitude", 100)
phyexp:SetKeyValue("radius", 128)
phyexp:SetKeyValue("spawnflags", 1 + 2)
phyexp:Spawn()
phyexp:Fire("Explode", "", 0)
local norm = self:GetAngles():Up() * -1
util.BlastDamage(self, self:GetOwner(), self:GetPos(), 200, 50)
local effect = EffectData()
effect:SetStart(self:GetPos())
effect:SetOrigin(self:GetPos())
effect:SetNormal(norm * -1)
effect:SetRadius(16)
effect:SetScale(1)
util.Effect("ManhackSparks", effect, true, true)
end
[/CODE]
[QUOTE=pkhzor;41274509]My ent I made for the tripmines. It's kinda buggy and I haven't gotten around to fixing it but it does check for roles and it can be destroyed. The beam can also be blocked by objects. The bugs are that it doesn't always pick up when someone passes through it, kind of 50/50 chance there. The beam also vanishes when the ent goes off your screen.
This is heavily WIP and it's just slapped together codes from different entities. Hope you get some use/ideas out of how to make it right.
[CODE]
if SERVER then
AddCSLuaFile("shared.lua")
end
ENT.Type = "anim"
ENT.Model = Model("models/Items/combine_rifle_ammo01.mdl")
ENT.Stuck = false
ENT.Weaponised = false
ENT.PunchMax = 6
ENT.PunchRemaining = 6
function ENT:Initialize()
self.Entity:SetModel("models/Items/combine_rifle_ammo01.mdl")
self.Entity:PhysicsInit(SOLID_VPHYSICS)
self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
self.Entity:SetSolid(SOLID_VPHYSICS)
self.Entity:DrawShadow(false)
self.Entity:SetCollisionGroup(COLLISION_GROUP_WORLD)
local phys = self.Entity:GetPhysicsObject():EnableMotion(false)
self:SetColor(Color(25, 122, 21, 255))
--self:StartEffects()
--self:Explosive()
self.Entity:EmitSound("C4.Plant")
end
local matTripmineLaser = Material( "sprites/bluelaser1" )
local matLight = Material( "models/roller/rollermine_glow" )
local colBeam = Color( 100, 100, 210, 30 )
local colLaser = Color( 100, 100, 240, 30 )
function ENT:Think()
if not self.endpos then
local t = {}
t.start = self:GetPos()
t.endpos = t.start + self:GetUp() * 4096
t.filter = self
local tr = util.TraceLine(t)
self.endpos = tr.HitPos
if tr.HitNonWorld then
if SERVER then
local ply = self.Owner
local ignore = {ply, self}
if not IsValid(ply) then return end
for k, v in pairs(player.GetAll()) do
if v:IsActiveTraitor() or v:IsSpec() then
table.insert(ignore, v)
end
if not table.HasValue(ignore,tr.Entity) and tr.Entity:IsPlayer() then
self:Explosive()
self:Remove()
end
end
end
end
end
end
function ENT:Draw()
if not self.endpos then
return
end
render.SetMaterial( matTripmineLaser )
// offset the texture coords so it looks like it is scrolling
local TexOffset = 6
// Make the texture coords relative to distance so they are always a nice size
local Distance = self.endpos:Distance( self:GetPos() )
// Draw the beam
render.DrawBeam( self.endpos, self.Entity:GetPos(), 6, TexOffset, TexOffset+Distance, colBeam )
render.DrawBeam( self.endpos, self.Entity:GetPos(), 3, TexOffset, TexOffset+Distance, colBeam )
// Draw a quad at the hitpoint to fake the laser hitting it
render.SetMaterial( matLight )
local Size = math.Rand( 3, 5 )
local Normal = (self.Entity:GetPos()-self.endpos):GetNormal() * 0.1
render.DrawQuadEasy( self.endpos + Normal, Normal, Size, Size, colLaser, 0 )
self.Entity:DrawModel()
end
function ENT:StartEffects()
local sprite = ents.Create( "env_sprite" )
if IsValid(sprite) then
-- local angpos = self:GetAttachment(ball)
-- sometimes attachments don't work (Lua-side) on dedicated servers,
-- so have to fudge it
local ang = self:GetAngles()
local pos = self:GetPos() + self:GetAngles():Up() * 6
sprite:SetPos(pos)
sprite:SetAngles(ang)
sprite:SetParent(self.Entity)
sprite:SetKeyValue("spawnflags", "1")
sprite:SetKeyValue("scale", "0.25")
sprite:SetKeyValue("rendermode", "5")
sprite:SetKeyValue("renderfx", "7")
sprite:Spawn()
sprite:Activate()
self.BallSprite = sprite
end
local effect = EffectData()
effect:SetStart(self:GetPos())
effect:SetOrigin(self:GetPos())
effect:SetNormal(self:GetAngles():Up())
util.Effect("ManhackSparks", effect, true, true)
if SERVER then
local ball = self:LookupAttachment("attach_ball")
util.SpriteTrail(self.Entity, ball, Color(250, 250, 250), false, 30, 0, 1, 0.07, "trails/physbeam.vmt")
end
end
function ENT:Explosive()
local phexp = ents.Create("env_explosion")
if IsValid(phexp) then
phexp:SetPos(self:GetPos())
phexp:SetKeyValue("magnitude", 100)
phexp:SetKeyValue("radius", 128)
phexp:SetKeyValue("spawnflags", 1 + 2)
phexp:Spawn()
phexp:Fire("Explode", "", 0)
end
local phyexp = ents.Create("env_physexplosion")
phyexp:SetPos(self:GetPos())
phyexp:SetKeyValue("magnitude", 100)
phyexp:SetKeyValue("radius", 128)
phyexp:SetKeyValue("spawnflags", 1 + 2)
phyexp:Spawn()
phyexp:Fire("Explode", "", 0)
local norm = self:GetAngles():Up() * -1
util.BlastDamage(self, self:GetOwner(), self:GetPos(), 200, 50)
local effect = EffectData()
effect:SetStart(self:GetPos())
effect:SetOrigin(self:GetPos())
effect:SetNormal(norm * -1)
effect:SetRadius(16)
effect:SetScale(1)
util.Effect("ManhackSparks", effect, true, true)
end
[/CODE][/QUOTE]
The only problem with that is that his system doesn't use an entity, it spawns the default SLAM from HL2
[QUOTE=BFG9000;41274803]The only problem with that is that his system doesn't use an entity, it spawns the default SLAM from HL2[/QUOTE]
just place this into entities and give it a name and replace the hl2 slam in the code with the said entity.
The code is for an entity you place \gamemodes\terrortown\entities\entities\testent\shared.lua
then in your code you replace
[CODE]local mine = ents.Create("npc_tripmine")[/CODE]
with
[CODE]local mine = ents.Create("testent")[/CODE]
Again, this is WIP. I will at some point finish this and release it on workshop. If anyone wants to fix it and release it as their own, go for it. I'd use it.
Sorry, you need to Log In to post a reply to this thread.