This is basically the shared.lua file for the weapon. A little bit buggy.
When you first spawn it, right click once then left click to start the camera,
left click to scroll through and right click to exit once in the camera.
[code]
if SERVER then
AddCSLuaFile("shared.lua")
end
if CLIENT then
SWEP.PrintName = "Cross Cam Spectate SWEP"
SWEP.Slot = 1
SWEP.SlotPos = 3
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false
end
SWEP.Author = "Ownage"
SWEP.Instructions = "Left click to start / toggle through. Right click to stop."
SWEP.Spawnable = false
SWEP.AdminSpawnable = true
SWEP.ViewModel = "models/weapons/v_hands.mdl"
SWEP.WorldModel = "models/weapons/w_357.mdl"
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
function SWEP:Initialize()
self:SetWeaponHoldType("normal")
C=0
end
function SWEP:Deploy()
if SERVER then
self.Owner:DrawViewModel(true)
self.Owner:DrawWorldModel(false)
end
end
function StartHeadCam()
if !CLIENT then return end
local HeadCam = {}
HeadCam.angles = sp:EyeAngles()
HeadCam.origin = sp:GetShootPos()
HeadCam.x = 0
HeadCam.y = 0
HeadCam.drawviewmodel = false
HeadCam.w = ScrW()
HeadCam.h = ScrH()
render.RenderView( HeadCam )
end
function SWEP:PrimaryAttack()
if self.Owner.Spectating then
C=C+1
if player.GetAll()[C]:Team() == self.Owner:Team() then sp = player.GetAll()[C] end
if C>=#player.GetAll() then C=1 end
else
if CLIENT then
hook.Add("HUDPaint", "HeadCamera", StartHeadCam)
end
self.Owner.Spectating = true
end
end
function SWEP:SecondaryAttack()
if CLIENT then
hook.Remove("HUDPaint", "HeadCamera")
end
self.Owner.Spectating = false
end
[/code]
I'm fixing your code; there are some mistakes/areas in need of improvement.
:) Thank you. Are you going to do anything else with it? I'll test it when I've got some heads available, and thanks again.
[editline]13th November 2010[/editline]
Oh hi ZenX2. Thanks for that.
The upgraded code:
[lua]if SERVER then
AddCSLuaFile("shared.lua")
end
if CLIENT then
SWEP.PrintName = "Cross Cam Spectate SWEP"
SWEP.Slot = 1
SWEP.SlotPos = 3
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false
end
SWEP.Author = "Ownage"
SWEP.Instructions = "Left click to start / toggle through. Right click to stop."
SWEP.Spawnable = false
SWEP.AdminSpawnable = true
SWEP.ViewModel = "models/weapons/v_hands.mdl"
SWEP.WorldModel = "models/weapons/w_357.mdl"
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
function SWEP:Initialize()
self:SetWeaponHoldType("normal")
self.C=0
end
function SWEP:Deploy()
if SERVER then
self.Owner:DrawViewModel(true)
self.Owner:DrawWorldModel(false)
end
end
function StartHeadCam()
if !self.sp then return end --incase there is no spectatee
local HeadCam = {}
HeadCam.angles = self.sp:EyeAngles()
HeadCam.origin = self.sp:GetShootPos()
HeadCam.x = 0
HeadCam.y = 0
HeadCam.drawviewmodel = false
HeadCam.w = ScrW()
HeadCam.h = ScrH()
render.RenderView( HeadCam )
end
function SWEP:PrimaryAttack()
if not self.C then self.C = 0
repeat
self.C=self.C+1
until (player.GetAll()[self.C] and player.GetAll()[self.C]:Team() == self.Owner:Team() and player.GetAll()[self.C] ~= self.Owner) or self.C > #player.GetAll()
if self.C > #player.GetAll() then self.Owner:ChatPrint("There are no players you can spectate.") return end
self.sp = player.GetAll()[self.C] --if everything is good, go ahead.
if CLIENT then
hook.Add("HUDPaint", "HeadCamera", StartHeadCam)
end
end
function SWEP:SecondaryAttack()
if CLIENT then
hook.Remove("HUDPaint", "HeadCamera")
end
end[/lua]
Here are some tips:
-If you are making a swep or sent, don't declare global variables, put them in a field of self. (ex: C to self.C)
-in startheadcam, you're checking if the client is running function when it was already only hooked on the client.
-the "self.Owner.Spectating" was not really needed.
-I added a better way of cycling through players.
--It skips having to click for players that aren't on your team, that was quite a bad way to code it (no offense :P)
--You can't spectate yourself
--If there is no one you can spectate, it lets you know and doesn't hook.
-Use [lua] tags. ([code] sucks)
Hope I helped :D
[editline]13th November 2010[/editline]
I haven't tested this, but it should work. (Or garry's infinite loop protection will break it.)
That was fast. Many thanks!
[editline]13th November 2010[/editline]
It doesn't seem to show up... :(
[editline]13th November 2010[/editline]
The SWEP in the weapon menu, I mean.
Sure you saved it in the right place and set the textfile to lua?
I see an end missing on line 62.
I see improper use of self on line 46.
[QUOTE=ZenX2;26026637]The upgraded code:
function SWEP:Deploy()
if SERVER then
self.Owner:DrawViewModel(true)
self.Owner:DrawWorldModel(false)
end
end
[b]function construct()
Additional.Pylons
end[/b]
function StartHeadCam()
if !self.sp then return end --incase there is no spectatee[/QUOTE]
There is your problem.
You forgot to construct additional pylons.
[url]http://www.facepunch.com/threads/1026429-Death-Factor[/url]!
This would help me out VERY much! I would really appreciate it!
Sorry, you need to Log In to post a reply to this thread.