• KOS Zones
    3 replies, posted
I have a JB KOS zone weapon and can equip it in game fine - ``` // Jailbreak Admin Swep if SERVER then AddCSLuaFile() end // SWEP Variables // SWEP.Base = "weapon_base" SWEP.PrintName = "KOS Zone Admin" SWEP.Category = "Jailbreak" SWEP.Author = "my_hat_stinks" SWEP.Instructions = "" SWEP.Spawnable = true SWEP.AdminOnly = true SWEP.AdminSpawnable = true SWEP.Slot = 2 SWEP.SlotPos = 1 SWEP.ViewModelFOV = 55 SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false SWEP.ViewModelFlip   = false SWEP.WorldModel = "models/weapons/w_toolgun.mdl" SWEP.ViewModel = "models/weapons/c_toolgun.mdl" SWEP.UseHands = true SWEP.Primary.Recoil = 0.1 SWEP.Primary.Damage = 1 SWEP.Primary.NumShots = 1 SWEP.Primary.Cone = 0.05 SWEP.Primary.Delay = 0.25 SWEP.Primary.Sound = Sound( "Weapon_Pistol.Empty" ) SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.Primary.ClipMax = -1 SWEP.Primary.HeldAmmo = 0 SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" SWEP.Secondary.ClipMax = -1 SWEP.Secondary.Delay = 0.25 SWEP.DeploySpeed = 1.5 SWEP.PrimaryAnim = ACT_VM_PRIMARYATTACK SWEP.ReloadAnim = ACT_VM_RELOAD SWEP.HoldType = "pistol" SWEP.CanDrop = false function SWEP:SetupDataTables() self:NetworkVar( "Vector", 0, "PosA" ) self:NetworkVar( "Vector", 1, "PosB" ) return self.BaseClass.SetupDataTables and self.BaseClass.SetupDataTables( self ) end // Standard SWEP functions // function SWEP:Initialize() self:SetWeaponHoldType( self.HoldType ) hook.Add( "PostDrawOpaqueRenderables", self, self.DrawPreview ) if CLIENT then self.ModifyingZone = 0 // 0 for new zone end end function SWEP:PrimaryAttack( isSecondary ) self:SetNextPrimaryFire( self.Primary.Delay ) self:SetNextSecondaryFire( self.Primary.Delay ) if not IsValid(self.Owner) then return end if SERVER then local shootPos = self.Owner:GetShootPos() local tr = util.TraceLine( {start=shootPos, endpos=shootPos+(self.Owner:GetAimVector()*10000), mask=MASK_SOLID, filter=player.GetAll()} ) if tr.Hit then if isSecondary then self:SetPosB( tr.HitPos ) else self:SetPosA( tr.HitPos ) end end end end function SWEP:SecondaryAttack() return self:PrimaryAttack( true ) end local zoneMenu function SWEP:Reload() if SERVER then return end if IsValid( zoneMenu ) then return end zoneMenu = vgui.Create( "DFrame" ) zoneMenu:SetTitle( "KOS Zones" ) zoneMenu:SetSize( 300,350 ) zoneMenu:SetPos( (ScrW()/2)-100, (ScrH()/2)-175 ) zoneMenu:MakePopup() // Buttons // local buttonPanel = vgui.Create( "DPanel", zoneMenu ) buttonPanel:Dock( BOTTOM ) buttonPanel:SetTall( 25 ) buttonPanel.Paint = function() end local preview = vgui.Create( "DButton", buttonPanel ) preview:Dock( LEFT ) preview:SetText( "Preview" ) preview:SetWide( 95 ) local update = vgui.Create( "DButton", buttonPanel ) update:Dock( RIGHT ) update:SetText( "Add/Update Zone" ) update:SetWide( 95 ) local delete = vgui.Create( "DButton", buttonPanel ) delete:Dock( FILL ) delete:SetText( "Delete Zone" ) delete:SetWide( 95 ) local scrollPanel = vgui.Create( "DScrollPanel", zoneMenu ) scrollPanel:Dock( FILL ) scrollPanel:DockPadding( 2,2,2,2 ) local settingsPanel = vgui.Create( "DListLayout", scrollPanel ) settingsPanel:Dock( FILL ) settingsPanel.Paint = function() end settingsPanel.PerformLayout = function( s ) s:SizeToChildren( false, true ) scrollPanel:InvalidateLayout() end settingsPanel:DockPadding( 2,2,2,2 ) // Max Co-ord Slider // local cornerMax = vgui.Create( "DForm", settingsPanel ) cornerMax:SetName( "Corner Max" ) cornerMax.XPos = cornerMax:NumberWang( "XPos", nil, -999999, 999999, 5 ) cornerMax.XPos:SetValue( self:GetPosA()[1] ) cornerMax.YPos = cornerMax:NumberWang( "YPos", nil, -999999, 999999, 5 ) cornerMax.YPos:SetValue( self:GetPosA()[2] ) cornerMax.ZPos = cornerMax:NumberWang( "ZPos", nil, -999999, 999999, 5 ) cornerMax.ZPos:SetValue( self:GetPosA()[3] ) cornerMax.GetVector = function( s ) return Vector( s.XPos:GetValue() or 0, s.YPos:GetValue() or 0, s.ZPos:GetValue() or 0 ) end // Min Co-ord Slider local cornerMin = vgui.Create( "DForm", settingsPanel ) cornerMin:SetName( "Corner Min" ) cornerMin.XPos = cornerMin:NumberWang( "XPos", nil, -999999, 999999, 5 ) cornerMin.XPos:SetValue( self:GetPosB()[1] ) cornerMin.YPos = cornerMin:NumberWang( "YPos", nil, -999999, 999999, 5 ) cornerMin.YPos:SetValue( self:GetPosB()[2] ) cornerMin.ZPos = cornerMin:NumberWang( "ZPos", nil, -999999, 999999, 5 ) cornerMin.ZPos:SetValue( self:GetPosB()[3] ) cornerMin.GetVector = function( s ) return Vector( s.XPos:GetValue() or 0, s.YPos:GetValue() or 0, s.ZPos:GetValue() or 0 ) end // Zone select Slider // local editZone = vgui.Create( "DForm", settingsPanel ) editZone:SetName( "Edit Zone" ) editZone.Modify = editZone:NumSlider(nil, 0, #GAMEMODE.KOSZones, 0 ) editZone.Modify:SetValue( self.ModifyingZone ) editZone.Modify.OnValueChanged = function( s, newVal ) self.ModifyingZone = math.Round( newVal ) end // Button functions // preview.DoClick = function() net.Start( "JB_KOSZone_UpdateWeapon" ) net.WriteVector( cornerMax:GetVector() ) net.WriteVector( cornerMin:GetVector() ) net.SendToServer() end update.DoClick = function() net.Start( "JB_KOSZone_UpdateZones" ) net.WriteVector( cornerMax:GetVector() ) net.WriteVector( cornerMin:GetVector() ) net.WriteUInt( self.ModifyingZone, 8 ) net.SendToServer() self.ModifyingZone = 0 end  delete.DoClick = function() net.Start( "JB_KOSZone_UpdateZones" ) net.WriteVector( Vector(0,0,0) ) net.WriteVector( Vector(0,0,0) ) net.WriteUInt( self.ModifyingZone, 8 ) net.SendToServer() self.ModifyingZone = 0 end  end if SERVER then net.Receive( "JB_KOSZone_UpdateWeapon", function( len, ply ) if not IsValid(ply) then return end local wep = ply:GetActiveWeapon() if not (IsValid(wep) and wep:GetClass()=="weapon_jb_kosadmin") then return end wep:SetPosA( net.ReadVector() or Vector() ) wep:SetPosB( net.ReadVector() or Vector() ) end) end local PreviewCol = Color(0,255,0) function SWEP:DrawPreview() if not (LocalPlayer()==self.Owner and self.Owner:GetActiveWeapon()==self) then return end if self:GetPosA()==Vector() or self:GetPosB()==Vector() then return end PreviewCol.a = 20 + (math.sin(CurTime()*2)*10) render.SetColorMaterial() render.DrawBox( self:GetPosA(), Angle(0,0,0), Vector(), self:GetPosB()-self:GetPosA(), PreviewCol, true ) render.DrawBox( self:GetPosB(), Angle(0,0,0), Vector(), self:GetPosA()-self:GetPosB(), PreviewCol, true ) render.DrawWireframeBox( self:GetPosB(), Angle(0,0,0), Vector(), self:GetPosA()-self:GetPosB(), PreviewCol, true ) end local crossCol = Color(0,255,0) function SWEP:DrawHUD() local w,h = ScrW(),ScrH() surface.SetDrawColor( crossCol ) surface.DrawLine( (w/2)-(h*0.01), (h/2), (w/2)+(h*0.01), (h/2) ) surface.DrawLine( (w/2), (h/2)-(h*0.01), (w/2), (h/2)+(h*0.01) ) end When I make it in game, I get the green zone fine. The when I press R to set the zone, I get this error: [ERROR] gamemodes/jailbreak/entities/weapons/weapon_jb_kosadmin.lua:165: attempt to get length of field 'KOSZones' (a nil value)   1. unknown - gamemodes/jailbreak/entities/weapons/weapon_jb_kosadmin.lua:165 I also have a sh_koszone file in my jailbreak/Gamemode/sh_koszone // KOS zones GM.KOSZones = GM.KOSZones or {} // Don't add zones here, use the tool! weapon_jb_kosadmin // Left click Min pos, right click Max pos, Reload for tweaking and setting // To remove, move the slider until your target is white, then update with values 0,0,0 and 0,0,0 function GM:GetKOSZones() return self.KOSZones or {} end if SERVER then function GM:AddKOSZone( pos1, pos2, zoneNum ) if zoneNum and zoneNum~=0  then self.KOSZones[zoneNum] = { pos1, pos2, } else table.insert( self.KOSZones, {pos1, pos2} ) end self:UpdateKOSZones() self:SaveKOSZones() end function GM:UpdateKOSZones( ply ) self.KOSZones.IsSetup = true net.Start( "JB_KOSZone_UpdateZones" ) net.WriteTable( self.KOSZones ) if ply then net.Send(ply) else net.Broadcast() end end function GM:LoadKOSZones() if not file.IsDir( "jb_data", "DATA" ) then file.CreateDir( "jb_data", "DATA" ) end if not file.IsDir( "jb_data/kos_zones", "DATA" ) then file.CreateDir( "jb_data/kos_zones", "DATA" ) end if not file.Exists( "jb_data/kos_zones/"..game.GetMap()..".txt", "DATA" ) then return end self.KOSZones = util.JSONToTable(file.Read( "jb_data/kos_zones/"..game.GetMap()..".txt", "DATA" )) self:UpdateKOSZones() end function GM:SaveKOSZones() if not file.IsDir( "jb_data", "DATA" ) then file.CreateDir( "jb_data", "DATA" ) end if not file.IsDir( "jb_data/kos_zones", "DATA" ) then file.CreateDir( "jb_data/kos_zones", "DATA" ) end file.Write( "jb_data/kos_zones/"..game.GetMap()..".txt", util.TableToJSON(self.KOSZones) ) end net.Receive( "JB_KOSZone_UpdateRequest", function( len, ply ) if not IsValid(ply) then return end GAMEMODE:UpdateKOSZones( ply ) end) net.Receive( "JB_KOSZone_UpdateZones", function( len, ply ) if not (IsValid(ply) and (ply:IsAdmin() or ply:IsSuperAdmin())) then return end local vecMin = net.ReadVector() local vecMax = net.ReadVector() local zoneEdit = net.ReadUInt( 8 ) or 0 if zoneEdit==0 then GAMEMODE:AddKOSZone( vecMin, vecMax ) else if vecMin==Vector() or vecMax==Vector or (vecMin==vecMax) then table.remove( GAMEMODE.KOSZones, zoneEdit ) GAMEMODE:UpdateKOSZones() GAMEMODE:SaveKOSZones() else GAMEMODE:AddKOSZone( vecMin, vecMax ) end end end) GM:LoadKOSZones() end if CLIENT then net.Receive( "JB_KOSZone_UpdateZones", function() GAMEMODE.KOSZones = net.ReadTable() or GAMEMODE.KOSZones end) timer.Create( "JB_InitialUpdateKOSZones", 5, 0, function() if GAMEMODE.KOSZones.Setup then timer.Destroy( "JB_InitialUpdateKOSZones" ) return end net.Start( "JB_KOSZone_UpdateRequest" ) net.SendToServer() end) local function IsInBox( vecCheck, boxMin, boxMax, col ) local vecMin = Vector( math.min(boxMin[1],boxMax[1]), math.min(boxMin[2],boxMax[2]), math.min(boxMin[3],boxMax[3]) ) local vecMax = Vector( math.max(boxMin[1],boxMax[1]), math.max(boxMin[2],boxMax[2]), math.max(boxMin[3],boxMax[3]) ) return (vecCheck[1]>=vecMin[1] and vecCheck[1]<=vecMax[1]) and (vecCheck[2]>=vecMin[2] and vecCheck[2]<=vecMax[2]) and (vecCheck[3]>=vecMin[3] and vecCheck[3]<=vecMax[3]) end local ZoneCol, GuardCol = Color(150,0,0), Color(0,0,200) local ZoneMat = Material( "gui/center_gradient" ) local ZeroVec = Vector(0,0,0) function GM:DrawKOSZones() local ply = LocalPlayer() if not IsValid(ply) then return end ply.IsInKOSZone = false local wep = ply:GetActiveWeapon() local targetNum = 0 if IsValid(wep) and wep:GetClass()=="weapon_jb_kosadmin" then targetNum = wep.ModifyingZone or 0 end if (not self.KOSZones) or #self.KOSZones==0 then return end //if GetRoundState()~=ROUND_ACTIVE then return end local col = ply:Team()==TEAM_PRISONER and ZoneCol or GuardCol //local col = GuardCol col.a = 12 + (math.sin(CurTime()*2)*10) render.SetColorMaterial() for k,zone in pairs( self.KOSZones ) do if k=="IsSetup" then continue end // Setup flag local DrawCol = targetNum==k and Color(180,180,180,50) or col if GetGlobalBool( "jb_showkoszones", true ) then // Draw one each way, it only draws the face in one direction which is weird when you're inside //render.DrawWireframeBox( zone[1], Angle(0,0,0), ZeroVec, zone[2]-zone[1], DrawCol, true ) render.DrawBox( zone[1], Angle(0,0,0), ZeroVec, zone[2]-zone[1], DrawCol, true ) render.DrawBox( zone[2], Angle(0,0,0), ZeroVec, zone[1]-zone[2], DrawCol, true ) end if ply:Team()==TEAM_PRISONER and (IsInBox( EyePos(), zone[1], zone[2] ) or IsInBox( ply:GetPos(), zone[1], zone[2] )) then ply.IsInKOSZone = true end end end end How do I fix it so I stop getting the error????
Like what the fuck dude...
sorry, my bad
Try to change #GAMEMODE.KOSZones to #GAMEMODE:GetKOSZones()
Sorry, you need to Log In to post a reply to this thread.