diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2016-05-30 14:42:09 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2016-05-30 14:42:09 -0400 |
| commit | 2736f498f30220b858fc6fac23e7ddc4a597df6d (patch) | |
| tree | 374ceadedb654b00e09dac321620a8320830f734 /entities/weapons/rad_itemplacer | |
| download | redead-2736f498f30220b858fc6fac23e7ddc4a597df6d.tar.gz redead-2736f498f30220b858fc6fac23e7ddc4a597df6d.tar.bz2 redead-2736f498f30220b858fc6fac23e7ddc4a597df6d.zip | |
Inital commit
Diffstat (limited to 'entities/weapons/rad_itemplacer')
| -rw-r--r-- | entities/weapons/rad_itemplacer/shared.lua | 295 |
1 files changed, 295 insertions, 0 deletions
diff --git a/entities/weapons/rad_itemplacer/shared.lua b/entities/weapons/rad_itemplacer/shared.lua new file mode 100644 index 0000000..12dad13 --- /dev/null +++ b/entities/weapons/rad_itemplacer/shared.lua @@ -0,0 +1,295 @@ +if SERVER then + + AddCSLuaFile( "shared.lua" ) + + SWEP.Weight = 1 + SWEP.AutoSwitchTo = false + SWEP.AutoSwitchFrom = false + +end + +if CLIENT then + + ClientItemPlacerTbl = {} + ClientItemPlacerTbl[ "teh" ] = {} + + SWEP.DrawAmmo = true + SWEP.DrawCrosshair = true + SWEP.CSMuzzleFlashes = true + + SWEP.ViewModelFOV = 74 + SWEP.ViewModelFlip = false + + SWEP.PrintName = "Item Placement Tool" + SWEP.Slot = 5 + SWEP.Slotpos = 5 + + function SWEP:DrawWeaponSelection( x, y, wide, tall, alpha ) + + end + +end + +SWEP.HoldType = "pistol" + +SWEP.ViewModel = "models/weapons/v_pistol.mdl" +SWEP.WorldModel = "models/weapons/w_pistol.mdl" + +SWEP.Primary.Swap = Sound( "weapons/clipempty_rifle.wav" ) +SWEP.Primary.Sound = Sound( "NPC_CombineCamera.Click" ) +SWEP.Primary.Delete1 = Sound( "Weapon_StunStick.Melee_Hit" ) +SWEP.Primary.Delete = Sound( "Weapon_StunStick.Melee_HitWorld" ) + +SWEP.Primary.ClipSize = 1 +SWEP.Primary.DefaultClip = 99999 +SWEP.Primary.Automatic = false +SWEP.Primary.Ammo = "pistol" + +SWEP.Secondary.ClipSize = -1 +SWEP.Secondary.DefaultClip = -1 +SWEP.Secondary.Automatic = false +SWEP.Secondary.Ammo = "none" + +SWEP.AmmoType = "Knife" + +SWEP.ItemTypes = { "info_player_zombie", +"info_player_army", +"info_lootspawn", +"info_npcspawn", +"info_evac", +"point_radiation" } + +SWEP.ServersideItems = { "info_player_zombie", +"info_player_army", +"info_lootspawn", +"info_npcspawn", +"info_evac", +"point_radiation" } + +SWEP.SharedItems = {} + +function SWEP:Initialize() + + if SERVER then + + self.Weapon:SetWeaponHoldType( self.HoldType ) + + end + +end + +function SWEP:Synch() + + for k,v in pairs( self.ServersideItems ) do + + local ents = ents.FindByClass( v ) + local postbl = {} + + for c,d in pairs( ents ) do + + table.insert( postbl, d:GetPos() ) + + end + + net.Start( "ItemPlacerSynch" ) + net.WriteString( v ) + net.WriteTable( postbl ) + net.Send( self.Owner ) + + //local tbl = { Name = v, Ents = postbl } + + //datastream.StreamToClients( { self.Owner }, "ItemPlacerSynch", tbl ) + + end + +end + +net.Receive( "ItemPlacerSynch", function( len ) + + ClientItemPlacerTbl[ net.ReadString() ] = net.ReadTable() + +end ) + +--[[function PlacerSynch( handler, id, encoded, decoded ) + + ClientItemPlacerTbl[ decoded.Name ] = decoded.Ents + +end +datastream.Hook( "ItemPlacerSynch", PlacerSynch )]] + +function SWEP:Deploy() + + if SERVER then + + self.Weapon:Synch() + + end + + self.Weapon:SendWeaponAnim( ACT_VM_DRAW ) + + return true + +end + +function SWEP:Think() + + if CLIENT then return end + + if self.Owner:KeyDown( IN_USE ) and ( ( self.NextDel or 0 ) < CurTime() ) then + + self.NextDel = CurTime() + 1 + + local tr = util.TraceLine( util.GetPlayerTrace( self.Owner ) ) + + local closest + local dist = 1000 + + for k,v in pairs( ents.FindByClass( self.ItemTypes[ self.Weapon:GetNWInt( "ItemType", 1 ) ] ) ) do + + if v:GetPos():Distance( tr.HitPos ) < dist then + + dist = v:GetPos():Distance( tr.HitPos ) + closest = v + + end + + end + + if IsValid( closest ) then + + closest:Remove() + + self.Owner:EmitSound( self.Primary.Delete1 ) + + self.Weapon:Synch() + + end + + end + +end + +function SWEP:Reload() + + if CLIENT then return end + + for k,v in pairs( ents.FindByClass( self.ItemTypes[ self.Weapon:GetNWInt( "ItemType", 1 ) ] ) ) do + + v:Remove() + + end + + self.Weapon:Synch() + + self.Owner:EmitSound( self.Primary.Delete ) + +end + +function SWEP:Holster() + + return true + +end + +function SWEP:ShootEffects() + + self.Owner:MuzzleFlash() + self.Owner:SetAnimation( PLAYER_ATTACK1 ) + + self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) + +end + +function SWEP:PlaceItem() + + local itemtype = self.ItemTypes[ self.Weapon:GetNWInt( "ItemType", 1 ) ] + + local tr = util.TraceLine( util.GetPlayerTrace( self.Owner ) ) + + local ent = ents.Create( itemtype ) + ent:SetPos( tr.HitPos + tr.HitNormal * 5 ) + ent:Spawn() + ent.AdminPlaced = true + +end + +function SWEP:PrimaryAttack() + + self.Weapon:SetNextPrimaryFire( CurTime() + 1 ) + self.Weapon:EmitSound( self.Primary.Sound, 100, math.random(95,105) ) + self.Weapon:ShootEffects() + + if SERVER then + + self.Weapon:PlaceItem() + + self.Weapon:Synch() + + end + +end + +function SWEP:SecondaryAttack() + + self.Weapon:SetNextSecondaryFire( CurTime() + 0.5 ) + + self.Weapon:EmitSound( self.Primary.Swap ) + + if SERVER then + + self.Weapon:SetNWInt( "ItemType", self.Weapon:GetNWInt( "ItemType", 1 ) + 1 ) + + if self.Weapon:GetNWInt( "ItemType", 1 ) > #self.ItemTypes then + + self.Weapon:SetNWInt( "ItemType", 1 ) + + end + + end + +end + +function SWEP:DrawHUD() + + draw.SimpleText( "PRIMARY FIRE: Place Item SECONDARY FIRE: Change Item Type +USE: Delete Nearest Item Of Current Type RELOAD: Remove All Of Current Item Type", "AmmoFontSmall", ScrW() * 0.5, ScrH() - 120, Color(255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) + draw.SimpleText( "CURRENT ITEM TYPE: "..self.ItemTypes[ self.Weapon:GetNWInt( "ItemType", 1 ) ], "AmmoFontSmall", ScrW() * 0.5, ScrH() - 100, Color(255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) + + for k,v in pairs( self.SharedItems ) do + + for c,d in pairs( ents.FindByClass( v ) ) do + + local pos = d:GetPos():ToScreen() + + if pos.visible then + + draw.SimpleText( v, "AmmoFontSmall", pos.x, pos.y - 15, Color(80,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) + draw.RoundedBox( 0, pos.x - 2, pos.y - 2, 4, 4, Color(255,255,255) ) + + end + + end + + end + + for k,v in pairs( ClientItemPlacerTbl ) do + + for c,d in pairs( v ) do + + local vec = Vector( d[1], d[2], d[3] ) + + local pos = vec:ToScreen() + + if pos.visible then + + draw.SimpleText( k, "AmmoFontSmall", pos.x, pos.y - 15, Color(80,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) + draw.RoundedBox( 0, pos.x - 2, pos.y - 2, 4, 4, Color(255,255,255) ) + + end + + end + + end + +end + + |
