Ok so i posted this code before and i was told to look into where the code ran, client, server and shared. so i did that and i think it fixed some things, the purpose of this code is to switch you with someone who you have selected, makes a great traitor weapon, still needs balancing. The problem i'm having is this code only works some of the time, when you have selected the person you want to switch with the crosshair updates and says you can now switch, but sometimes it doesn't. Any ideas :/?, i've tried a few solutions such as getting the ent of the other player in a different way but they haven't worked so far/
[LUA]
if SERVER then
AddCSLuaFile( "shared.lua" )
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
elseif CLIENT then
SWEP.PrintName = "Switchatron"
SWEP.Author = "Skillz"
SWEP.Slot = 7
SWEP.IconLetter = "w"
SWEP.DrawAmmo = false
end
SWEP.HoldType = "melee"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.Base = "weapon_tttbase"
SWEP.Kind = WEAPON_EQUIP2
SWEP.Primary.Delay = 0
SWEP.Primary.Recoil = 0
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = nil
SWEP.Primary.Damage = 0
SWEP.Primary.Cone = 0
SWEP.Primary.ClipSize = -1
SWEP.Primary.ClipMax = -1
SWEP.Primary.DefaultClip = -1
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = nil
SWEP.AutoSpawnable = false
SWEP.ViewModel = "models/weapons/v_crowbar.mdl"
SWEP.WorldModel = "models/props_lab/huladoll.mdl"
SWEP.CanBuy = {ROLE_TRAITOR}
SWEP.AllowDrop = true
SWEP.CSMuzzleFlashes = false
--zap = Sound("ambient/levels/labs/electric_explosion4.wav")
function SWEP:PrimaryAttack()
if victim~=nil and victim:Alive() then
if CLIENT then
surface.PlaySound("buttons/blip2.wav")
end
ply =self.Owner
ent_view =victim:EyeAngles()
ent_position =victim:GetPos()
ent_velocity =victim:GetVelocity()
self_view =ply:EyeAngles()
self_position =ply:GetPos()
self_velocity =ply:GetVelocity()
victim:Freeze(true)
victim:SetPos(self_position)
victim:SetEyeAngles(self_view)
victim:SetVelocity(self_velocity)
victim:Freeze(false)
ply:Freeze(true)
ply:SetPos(ent_position)
ply:SetEyeAngles(ent_view)
ply:SetVelocity(ent_velocity)
ply:Freeze(false)
if SERVER then
self:Remove()
end
end
end
function SWEP:SecondaryAttack()
local tr = self.Owner:GetEyeTrace(MASK_SHOT)
if tr.Hit and tr.Entity:IsValid() and tr.Entity:IsPlayer() and tr.Entity:Alive() and (self.Owner:EyePos() - tr.HitPos):Length() < 200 then
local victim = tr.Entity
if CLIENT then
surface.PlaySound("buttons/blip2.wav")
end
else
if CLIENT then
surface.PlaySound("player/suit_denydevice.wav")
end
end
end
if CLIENT then
function SWEP:DrawHUD()
local tr = self.Owner:GetEyeTrace(MASK_SHOT)
local x = ScrW() / 2.0
local y = ScrH() / 2.0
if tr.Hit and tr.Entity:IsValid() and tr.Entity:IsPlayer() and (self.Owner:EyePos() - tr.HitPos):Length() < 200 then
surface.SetDrawColor(255, 0, 0, 255)
draw.SimpleText("Select Victim", "TabLarge", x, y - 30, COLOR_RED, TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM)
else
surface.SetDrawColor(1, 1, 1, 255)
draw.SimpleText("Out Of Range", "TabLarge", x, y - 30, COLOR_WHITE, TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM)
end
if victim~=nil and victim:Alive() then
surface.SetDrawColor(0, 255, 0, 255)
draw.SimpleText("Switch With Victim", "TabLarge", x, y - 45, COLOR_GREEN, TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM)
end
local outer = 20
local inner = 10
surface.DrawLine(x - outer, y - outer, x - inner, y - inner)
surface.DrawLine(x + outer, y + outer, x + inner, y + inner)
surface.DrawLine(x - outer, y + outer, x - inner, y + inner)
surface.DrawLine(x + outer, y - outer, x + inner, y - inner)
return self.BaseClass.DrawHUD(self)
end
end
function SWEP:Deploy()
if CLIENT then
self.Owner:DrawViewModel(false)
end
return true
end
function SWEP:OnRemove()
if CLIENT and IsValid(self.Owner) and self.Owner == LocalPlayer() and self.Owner:Alive() then
RunConsoleCommand("lastinv")
end
victim=nil
end
if CLIENT then
function SWEP:DrawWorldModel()
if not IsValid(self.Owner) then
self:DrawModel()
end
end
end
[/LUA]
[editline]16th April 2013[/editline]
I could also do with some help making it so that when a person dies because of this weapon, it registers that the owner of this weapon killed the victim.
Sorry, you need to Log In to post a reply to this thread.