• Problems That Don't Need Their Own Thread v5
    4,111 replies, posted
[QUOTE=code_gs;52405799]Because CreateMove is before the server ever sees the keys, hence the server will never know the difference between a player actually holding down forward or not. StartCommand should be used for things that need to be predicted in both realms and you don't want to trust the client.[/QUOTE] Exactly, you don't want to trust the client to slow the player down. [editline]27th June 2017[/editline] I mean, the snippet references ply.brokenLegs. I don't trust the client to break the player's legs.
[QUOTE=NeatNit;52405831]Exactly, you don't want to trust the client to slow the player down.[/QUOTE] Yeah, plus I don't think the speeds are properly updated in the ucmd until StartCommand anyway [editline]27th June 2017[/editline] Oh, then yes, I would use StartCommand in that brokenLegs instance.
[code] function ENT:Think() if SERVER then for key, ply in ipairs(player.GetAll()) do if ply:Alive() then local dist = ply:GetPos():Distance(self:GetPos()) if dist <= self.captureDistance then if ply:Team() == 1 then self.blueinzone = true else self.blueinzone = false end if ply:Team() == 2 then self.redinzone = true else self.redinzone = false end [/code] So i'm having this test to see if my flag can detect player inside of it, but it just return false for some reason
I am planning on making an entity levitate above the ground. How should i approach this? What I am most unsure about is how I should calculate the levitation position. Should a trace be used or is another method better?
[QUOTE=YoutoYokodera;52406229][code] function ENT:Think() if SERVER then for key, ply in ipairs(player.GetAll()) do if ply:Alive() then local dist = ply:GetPos():Distance(self:GetPos()) if dist <= self.captureDistance then if ply:Team() == 1 then self.blueinzone = true else self.blueinzone = false end if ply:Team() == 2 then self.redinzone = true else self.redinzone = false end [/code] So i'm having this test to see if my flag can detect player inside of it, but it just return false for some reason[/QUOTE] Use enums for your Team comparison -- the code looks fine to me otherwise. As a note, you can localise self:GetPos() outside of the loop so you don't call it for every player, and you can use DistToSqr instead of Distance by changing captureDistance to captureDistanceSqr (changing the value to num^2).
[QUOTE=code_gs;52406371]Use enums for your Team comparison -- the code looks fine to me otherwise. As a note, you can localise self:GetPos() outside of the loop so you don't call it for every player, and you can use DistToSqr instead of Distance by changing captureDistance to captureDistanceSqr (changing the value to num^2).[/QUOTE] It still printing false even if i stand inside the zone or not
[QUOTE=YoutoYokodera;52406395]It still printing false even if i stand inside the zone or not[/QUOTE] Can you show the full code with the print?
For some reason my c_ viewmodels are invisible. I used a finished SWEP base before and everything worked fine and the c_ viewmodels were visible in my gamemode. Now I made my own simple SWEP script but the viewmodels are invisible now. I guess I'm missing something that should be inside of my SWEP script? [code] if (SERVER) then AddCSLuaFile( "shared.lua" ) SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false end if ( CLIENT ) then SWEP.PrintName = "USP" SWEP.Author = "rapps" SWEP.DrawAmmo = false SWEP.DrawCrosshair = false SWEP.ViewModelFOV = 70 SWEP.ViewModelFlip = false SWEP.ShowViewModel = true SWEP.ShowWorldModel = true SWEP.CSMuzzleFlashes = true SWEP.IconLetterCSS = "a" killicon.AddFont( "weapon_usp", "CSKillIcons", SWEP.IconLetterCSS, Color( 255, 80, 0, 255 ) ) end SWEP.Category = "Left Behind Weapons" SWEP.Spawnable = false SWEP.AdminSpawnable = false SWEP.Slot = 1 // Slot in the weapon selection menu SWEP.SlotPos = 1 // Position in the slot SWEP.ViewModel = "models/weapons/cstrike/c_pist_usp.mdl" SWEP.WorldModel = "models/weapons/w_pist_usp.mdl" SWEP.IronSightsPos = Vector( -5.9, -5, 2.7 ) SWEP.IronSightsAng = Vector( -0.5, 0, 0 ) SWEP.Primary.Sound = Sound( "Weapon_usp.Single" ) SWEP.Primary.Recoil = 1.5 SWEP.Primary.ClipSize = 18 SWEP.Primary.DefaultClip = 18 SWEP.Primary.Automatic = false SWEP.Primary.Delay = 0.35 SWEP.Primary.Damage = 30 SWEP.Primary.NumShots = 1 SWEP.Primary.Cone = 0.01 SWEP.Primary.Ammo = "pistol" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" SWEP.Secondary.ClipSize = 0 SWEP.Secondary.DefaultClip = 0 /*--------------------------------------------------------- ---------------------------------------------------------*/ function SWEP:Initialize() self.HoldType = "pistol" //Sets their holdtype to that of the AR2 self:SetWeaponHoldType( self.HoldType ) self.Weapon:SetNetworkedBool( "Ironsights", false ) end function SWEP:Deploy() self:SendWeaponAnim(ACT_VM_DRAW) self:SetIronsights( false ) end /*--------------------------------------------------------- Reload does nothing ---------------------------------------------------------*/ function SWEP:Reload() if ( self.Weapon:Clip1() < self.Primary.ClipSize && self.Owner:GetAmmoCount( self.Primary.Ammo ) > 0 ) then self.Weapon:DefaultReload( ACT_VM_RELOAD ); self:EmitSound("Weapon_Pistol.Reload") self:SetIronsights( false ) self.Owner:SetFOV( 0, 0.2 ) scope = 0 end end /*--------------------------------------------------------- Think does nothing ---------------------------------------------------------*/ function SWEP:Think() end /*--------------------------------------------------------- PrimaryAttack ---------------------------------------------------------*/ function SWEP:PrimaryAttack() self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay ) self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) if ( !self:CanPrimaryAttack() ) then return end // Play shoot sound self.Weapon:EmitSound( self.Primary.Sound ) // Shoot the bullet self:RealShootBullet( self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self.Primary.Cone ) // Remove 1 bullet from our clip self:TakePrimaryAmmo( 1 ) if ( self.Owner:IsNPC() ) then return end // Punch the player's view self.Owner:ViewPunch( Angle( math.Rand(-0.3,-0.2) * self.Primary.Recoil, math.Rand(-0.2,0.2) *self.Primary.Recoil, 0 ) ) // In singleplayer this function doesn't get called on the client, so we use a networked float // to send the last shoot time. In multiplayer this is predicted clientside so we don't need to // send the float. /* if ( (SinglePlayer() && SERVER) || CLIENT ) then self.Weapon:SetNetworkedFloat( "LastShootTime", CurTime() ) end */ end /*--------------------------------------------------------- Name: SWEP:PrimaryAttack( ) Desc: +attack1 has been pressed ---------------------------------------------------------*/ function SWEP:RealShootBullet( dmg, recoil, numbul, cone ) numbul = numbul or 1 cone = cone or 0.01 local bullet = {} bullet.Num = numbul bullet.Src = self.Owner:GetShootPos() // Source bullet.Dir = self.Owner:GetAimVector() // Dir of bullet bullet.Spread = Vector( cone, cone, 0 ) // Aim Cone bullet.Tracer = 4 // Show a tracer on every x bullets bullet.Force = 5 // Amount of force to give to phys objects bullet.Damage = dmg self.Owner:FireBullets( bullet ) self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) // View model animation self.Owner:MuzzleFlash() // Crappy muzzle light self.Owner:SetAnimation( PLAYER_ATTACK1 ) // 3rd Person Animation if ( self.Owner:IsNPC() ) then return end // CUSTOM RECOIL ! /* if ( (SinglePlayer() && SERVER) || ( !SinglePlayer() && CLIENT ) ) then local eyeang = self.Owner:EyeAngles() eyeang.pitch = eyeang.pitch - recoil self.Owner:SetEyeAngles( eyeang ) end */ end local IRONSIGHT_TIME = 0.2 /*--------------------------------------------------------- Name: GetViewModelPosition Desc: Allows you to re-position the view model ---------------------------------------------------------*/ function SWEP:GetViewModelPosition( pos, ang ) if ( !self.IronSightsPos ) then return pos, ang end local bIron = self.Weapon:GetNetworkedBool( "Ironsights" ) if ( bIron != self.bLastIron ) then self.bLastIron = bIron self.fIronTime = CurTime() if ( bIron ) then self.SwayScale = 0.3 self.BobScale = 0.1 else self.SwayScale = 1.0 self.BobScale = 1.0 end end local fIronTime = self.fIronTime or 0 if ( !bIron && fIronTime < CurTime() - IRONSIGHT_TIME ) then return pos, ang end local Mul = 1.0 if ( fIronTime > CurTime() - IRONSIGHT_TIME ) then Mul = math.Clamp( (CurTime() - fIronTime) / IRONSIGHT_TIME, 0, 1 ) if (!bIron) then Mul = 1 - Mul end end local Offset = self.IronSightsPos if ( self.IronSightsAng ) then ang = ang * 1 ang:RotateAroundAxis( ang:Right(), self.IronSightsAng.x * Mul ) ang:RotateAroundAxis( ang:Up(), self.IronSightsAng.y * Mul ) ang:RotateAroundAxis( ang:Forward(), self.IronSightsAng.z * Mul ) end local Right = ang:Right() local Up = ang:Up() local Forward = ang:Forward() pos = pos + Offset.x * Right * Mul pos = pos + Offset.y * Forward * Mul pos = pos + Offset.z * Up * Mul return pos, ang end /*--------------------------------------------------------- SetIronsights ---------------------------------------------------------*/ function SWEP:SetIronsights( b ) self.Weapon:SetNetworkedBool( "Ironsights", b ) end SWEP.NextSecondaryAttack = 0 scope = 0 /*--------------------------------------------------------- SecondaryAttack ---------------------------------------------------------*/ function SWEP:SecondaryAttack() if ( !self.IronSightsPos ) then return end if ( self.NextSecondaryAttack > CurTime() ) then return end bIronsights = !self.Weapon:GetNetworkedBool( "Ironsights", false ) self:SetIronsights( bIronsights ) self.NextSecondaryAttack = CurTime() + 0.3 if scope == 0 then self.Owner:SetFOV( 60, 0.2 ) scope = 1 elseif scope == 1 then self.Owner:SetFOV( 0, 0.2 ) scope = 0 end end /*--------------------------------------------------------- onRestore Loaded a saved game (or changelevel) ---------------------------------------------------------*/ function SWEP:OnRestore() self.NextSecondaryAttack = 0 self:SetIronsights( false ) end [/code]
[QUOTE=code_gs;52406428]Can you show the full code with the print?[/QUOTE] i have deleted that part cuz i think that is a bad idea the rest is here (ugly as hell) [code]-- Put your Lua here AddCSLuaFile() ENT.Type = "anim" ENT.Base = "base_gmodentity" ENT.PrintName = "Flag" ENT.Author = "Yukinya" ENT.Contact = "Facepunch" ENT.Purpose = "Contain dank meme" ENT.Instructions = "" ENT.Spawnable = true ENT.AdminSpawnable = false ENT.captureDistance = 200 ^ 2 function ENT:Initialize() if SERVER then self:SetModel("models/props_c17/oildrum001.mdl") self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) local phys = self:GetPhysicsObject() if phys:IsValid() then phys:Wake() end self.point = 0 self.spam = true self.capturestate = 0 self.id = 0 for key, entt in ipairs(ents.GetAll()) do if entt:GetClass() == "zone" then self.id = self.id + 1 end end print("id is", self.id) end end function ENT:Think() if SERVER then local entpos = self:GetPos() for key, ply in ipairs(player.GetAll()) do if ply:Alive() then local dist = ply:GetPos():DistToSqr(entpos) print(dist) if dist <= self.captureDistance then if ply:Team() == 1 and self.point < 50 then self.point = self.point + 1 self.spam = true elseif ply:Team() == 2 and self.point > -50 then self.point = self.point - 1 self.spam = true end end if self.point == 50 and self.spam then for key, ply in ipairs(player.GetAll()) do ply:PrintMessage(HUD_PRINTCENTER, "TEAM BLUE HAS CAPTURED THE FLAG") end self.spam = false self.capturestate = 1 elseif self.point == -50 and self.spam then for key, ply in ipairs(player.GetAll()) do ply:PrintMessage(HUD_PRINTCENTER, "TEAM RED HAS CAPTURED THE FLAG") end self.spam = false self.capturestate = 2 elseif self.point == 0 and self.spam then for key, ply in ipairs(player.GetAll()) do ply:PrintMessage(HUD_PRINTCENTER, "THE FLAG IS NEUTRALIZED") end self.spam = false self.capturestate = 0 end end end print(self.point) self:NextThink(CurTime() + 0.2) return true end end function ENT:OnRemove() if SERVER then point = 0 end end if CLIENT then function ENT:Draw() self:DrawModel() end end[/code]
Do anyone knows why OnTakeDamage is not working? [url]https://pastebin.com/Jk36ZnLz[/url] I really don't understand why it seems perfect
[QUOTE=code_gs;52405839]Yeah, plus I don't think the speeds are properly updated in the ucmd until StartCommand anyway [editline]27th June 2017[/editline] Oh, then yes, I would use StartCommand in that brokenLegs instance.[/QUOTE] I've given that a go and I'm still getting the exact same issue as before. It's just tapping crouch very quickly without holding it. [video=youtube;zmOajB3Rp3k]https://www.youtube.com/watch?v=zmOajB3Rp3k[/video]
[QUOTE=YoutoYokodera;52406472]i have deleted that part cuz i think that is a bad idea the rest is here (ugly as hell) [code]-- Put your Lua here AddCSLuaFile() ENT.Type = "anim" ENT.Base = "base_gmodentity" ENT.PrintName = "Flag" ENT.Author = "Yukinya" ENT.Contact = "Facepunch" ENT.Purpose = "Contain dank meme" ENT.Instructions = "" ENT.Spawnable = true ENT.AdminSpawnable = false ENT.captureDistance = 200 ^ 2 function ENT:Initialize() if SERVER then self:SetModel("models/props_c17/oildrum001.mdl") self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) local phys = self:GetPhysicsObject() if phys:IsValid() then phys:Wake() end self.point = 0 self.spam = true self.capturestate = 0 self.id = 0 for key, entt in ipairs(ents.GetAll()) do if entt:GetClass() == "zone" then self.id = self.id + 1 end end print("id is", self.id) end end function ENT:Think() if SERVER then local entpos = self:GetPos() for key, ply in ipairs(player.GetAll()) do if ply:Alive() then local dist = ply:GetPos():DistToSqr(entpos) print(dist) if dist <= self.captureDistance then if ply:Team() == 1 and self.point < 50 then self.point = self.point + 1 self.spam = true elseif ply:Team() == 2 and self.point > -50 then self.point = self.point - 1 self.spam = true end end if self.point == 50 and self.spam then for key, ply in ipairs(player.GetAll()) do ply:PrintMessage(HUD_PRINTCENTER, "TEAM BLUE HAS CAPTURED THE FLAG") end self.spam = false self.capturestate = 1 elseif self.point == -50 and self.spam then for key, ply in ipairs(player.GetAll()) do ply:PrintMessage(HUD_PRINTCENTER, "TEAM RED HAS CAPTURED THE FLAG") end self.spam = false self.capturestate = 2 elseif self.point == 0 and self.spam then for key, ply in ipairs(player.GetAll()) do ply:PrintMessage(HUD_PRINTCENTER, "THE FLAG IS NEUTRALIZED") end self.spam = false self.capturestate = 0 end end end print(self.point) self:NextThink(CurTime() + 0.2) return true end end function ENT:OnRemove() if SERVER then point = 0 end end if CLIENT then function ENT:Draw() self:DrawModel() end end[/code][/QUOTE] player.GetAll() loop inside player.GetAll() loop inside Think :suicide:
[QUOTE=rebel1324;52406524]Do anyone knows why OnTakeDamage is not working? [url]https://pastebin.com/Jk36ZnLz[/url] I really don't understand why it seems perfect[/QUOTE] I think you have to set the ENT.Base. ENT.Base = "base_gmodentity"
[QUOTE=YoutoYokodera;52406472]i have deleted that part cuz i think that is a bad idea the rest is here (ugly as hell) [/QUOTE] Did try to clean it up a bit. (PrintMessage is also a global function btw.) It should also support stalemates too [code]function ENT:FlagCaptured(str_message) PrintMessage(HUD_PRINTCENTER,str_message) end function ENT:Think() local teamsOnPoint = {[1] = 0,[2] = 0} -- Count the players who're close to the flag for _, ply in ipairs(player.GetAll()) do if ply:Alive() then local dist = ply:GetPos():DistToSqr(entpos) if dist <= self.captureDistance then -- Put them in a table teamsOnPoint[ply:Team()] = teamsOnPoint[ply:Team()] + 1 end end end -- Check what team is biggest and give 'point's if teamsOnPoint[1] > teamsOnPoint[2] then -- Team 1 is winning if self.capturestate != 1 then -- .. and they don't own it self.point = self.point + 1 end elseif teamsOnPoint[1] < teamsOnPoint[2] then -- Team 2 is winning if self.capturestate != 2 then -- .. and they don't own it self.point = self.point - 1 end end -- Update and check stuff if self.capturestate == 1 then -- Blue owns it if self.point <= 0 then -- Neutral self.capturestat = 0 self:FlagCaptured("THE FLAG IS NEUTRALIZED") end elseif self.capturestat == 2 then -- Red owns it if self.point >= 0 then -- Neutral self.capturestat = 0 self:FlagCaptured("THE FLAG IS NEUTRALIZED") end elseif self.capturestat == 0 then -- Noone owns it if self.point >= 50 then self.capturestat = 1 self:FlagCaptured("TEAM BLUE HAS CAPTURED THE FLAG") elseif self.point <= -50 then self.capturestat = 2 self:FlagCaptured("TEAM RED HAS CAPTURED THE FLAG") end end end[/code] Not tested, as I'm going for food. Generally, you don't want to loop heavy code, this only counts the players who're close.
[QUOTE=Nak;52406685]Did try to clean it up a bit. (PrintMessage is also a global function btw.) It should also support stalemates too [code]function ENT:FlagCaptured(str_message) PrintMessage(HUD_PRINTCENTER,str_message) end function ENT:Think() local teamsOnPoint = {[1] = 0,[2] = 0} -- Count the players who're close to the flag for _, ply in ipairs(player.GetAll()) do if ply:Alive() then local dist = ply:GetPos():DistToSqr(entpos) if dist <= self.captureDistance then -- Put them in a table teamsOnPoint[ply:Team()] = teamsOnPoint[ply:Team()] + 1 end end end -- Check what team is biggest and give 'point's if teamsOnPoint[1] > teamsOnPoint[2] then -- Team 1 is winning if self.capturestate != 1 then -- .. and they don't own it self.point = self.point + 1 end elseif teamsOnPoint[1] < teamsOnPoint[2] then -- Team 2 is winning if self.capturestate != 2 then -- .. and they don't own it self.point = self.point - 1 end end -- Update and check stuff if self.capturestate == 1 then -- Blue owns it if self.point <= 0 then -- Neutral self.capturestat = 0 self:FlagCaptured("THE FLAG IS NEUTRALIZED") end elseif self.capturestat == 2 then -- Red owns it if self.point >= 0 then -- Neutral self.capturestat = 0 self:FlagCaptured("THE FLAG IS NEUTRALIZED") end elseif self.capturestat == 0 then -- Noone owns it if self.point >= 50 then self.capturestat = 1 self:FlagCaptured("TEAM BLUE HAS CAPTURED THE FLAG") elseif self.point <= -50 then self.capturestat = 2 self:FlagCaptured("TEAM RED HAS CAPTURED THE FLAG") end end end[/code] Not tested, as I'm going for food. Generally, you don't want to loop heavy code, this only counts the players who're close.[/QUOTE] Bear in mind this method means the capture time depends on the server's tickrate and won't be the fixed
[QUOTE=Benn20002;52403928]Do you want the job to have ESP for all players? So he can see everyone? Then use [code] if LocalPlayer():Team() != TEAM_VORT then return end halo.Add(player.GetAll(), Color( 0, 255, 0 ), 1, 1, 2, true, true ) [/code][/QUOTE] No, I want it so the player can only see other players within that team. I also need a way to open the script automatically when they change to that specific team as well as closing it upon changing to another team.
[QUOTE=Nak;52406685]Did try to clean it up a bit. (PrintMessage is also a global function btw.) It should also support stalemates too [code]function ENT:FlagCaptured(str_message) PrintMessage(HUD_PRINTCENTER,str_message) end function ENT:Think() local teamsOnPoint = {[1] = 0,[2] = 0} -- Count the players who're close to the flag for _, ply in ipairs(player.GetAll()) do if ply:Alive() then local dist = ply:GetPos():DistToSqr(entpos) if dist <= self.captureDistance then -- Put them in a table teamsOnPoint[ply:Team()] = teamsOnPoint[ply:Team()] + 1 end end end -- Check what team is biggest and give 'point's if teamsOnPoint[1] > teamsOnPoint[2] then -- Team 1 is winning if self.capturestate != 1 then -- .. and they don't own it self.point = self.point + 1 end elseif teamsOnPoint[1] < teamsOnPoint[2] then -- Team 2 is winning if self.capturestate != 2 then -- .. and they don't own it self.point = self.point - 1 end end -- Update and check stuff if self.capturestate == 1 then -- Blue owns it if self.point <= 0 then -- Neutral self.capturestat = 0 self:FlagCaptured("THE FLAG IS NEUTRALIZED") end elseif self.capturestat == 2 then -- Red owns it if self.point >= 0 then -- Neutral self.capturestat = 0 self:FlagCaptured("THE FLAG IS NEUTRALIZED") end elseif self.capturestat == 0 then -- Noone owns it if self.point >= 50 then self.capturestat = 1 self:FlagCaptured("TEAM BLUE HAS CAPTURED THE FLAG") elseif self.point <= -50 then self.capturestat = 2 self:FlagCaptured("TEAM RED HAS CAPTURED THE FLAG") end end end[/code] Not tested, as I'm going for food. Generally, you don't want to loop heavy code, this only counts the players who're close.[/QUOTE] But what about when people leave the zone [editline]27th June 2017[/editline] And the msg will be displayed every tick right?
[lua] hook.Add("KeyPress", "KeyPressTest", function(ply, key) print("[DEBUG] Keypress by "..ply:Name()) if key == IN_USE then print("[DEBUG] IN_USE activated by "..ply:Name()) end end) [/lua] [quote=] *Spamming keys in game, IN_USE, IN_FORWARD, etc. Nothing.* [/quote] [b]solved[/b] [del]Having a problem getting KeyPress to work. This is in the equivalent of "sv_init.lua" (in a server-side gamemode Lua file). Pressing all keys on the keyboard does nothing to activate the hook.[/del] Had to use KeyPress hook on the client, dispatch a message to the server to run the functions and checks, and then dispatch it back to the client. Works now. I.E: Had to run it clientside, and have the server run the sensitive functions.
[QUOTE=YoutoYokodera;52406782]But what about when people leave the zone [editline]27th June 2017[/editline] And the msg will be displayed every tick right?[/QUOTE] Points will only change if the total number of players around the flag is more than the other teams. It will only display the message if the capturestat changes
[QUOTE=Rory;52406866][lua] hook.Add("KeyPress", "KeyPressTest", function(ply, key) print("[DEBUG] Keypress by "..ply:Name()) if key == IN_USE then print("[DEBUG] IN_USE activated by "..ply:Name()) end end) [/lua] [b]solved[/b] [del]Having a problem getting KeyPress to work. This is in the equivalent of "sv_init.lua" (in a server-side gamemode Lua file). Pressing all keys on the keyboard does nothing to activate the hook.[/del] Had to use KeyPress hook on the client, dispatch a message to the server to run the functions and checks, and then dispatch it back to the client. Works now. I.E: Had to run it clientside, and have the server run the sensitive functions.[/QUOTE] Why not just make the hook shared, then? Also, [lua] if SERVER then hook.Add( "KeyPress", "Test", function( ply, key ) print("Test") end ) end [/lua] Worked exactly as expected, printing test once when a key was pressed. I don't mean to question your intelligence, but double check you're including the file on the server
[QUOTE=Wepl123;52406921] Worked exactly as expected, printing test once when a key was pressed. I don't mean to question your intelligence, but double check you're including the file on the server [/QUOTE] All the files are included perfectly. Made a processing function to AddCSLuaFile and Include all relevant files within the directories. Moving the hook from the server to the client fixed it. All the functions are still on the server so the client can't mess with it. Made the KeyPress hook send a message to the server, to check if the client can utilize the server side functions, and then send the result back to the client.
[QUOTE=Shadow02;52406753]No, I want it so the player can only see other players within that team. I also need a way to open the script automatically when they change to that specific team as well as closing it upon changing to another team.[/QUOTE] If I understand you right this should work [code] if LocalPlayer():Team() != TEAM_VORT then return end halo.Add(team.GetPlayers(TEAM_VORT), Color( 0, 255, 0 ), 1, 1, 2, true, true ) [/code] Its only showing the Halos if the LocalPlayer is in TEAM_VORT and it only shows other players that are in the team.
[QUOTE=Rory;52407224]All the files are included perfectly. Made a processing function to AddCSLuaFile and Include all relevant files within the directories. Moving the hook from the server to the client fixed it. All the functions are still on the server so the client can't mess with it. Made the KeyPress hook send a message to the server, to check if the client can utilize the server side functions, and then send the result back to the client.[/QUOTE] Your solution works, but it is not efficient. See this quote by garry: [QUOTE=garry;39919712]You should only be using the net library to send messages - not to keep variables in sync.[/QUOTE] While you're not nessecarily using the net library to keep a variable in sync, you are using it to check a variable on the server. And also, only checking something on the server AFTER receiving a message from the client can be dangerous, what if the client found a way to get that message to never send? Instead, you should use networked variables: [url]http://wiki.garrysmod.com/page/Networking_Entities[/url] In your player class: [lua]--You said this was a part of the gamemode, so you'd want to do this in the player class. --If you can't use the player class for some reason, just use wiki.garrysmod.com/page/Entity/SetNWBool on the player instead. function PLAYER:SetupDataTables() self.Player:NetworkVar( "Bool", 0, "Busy" ) end[/lua] Gamemode: [lua] function GM:PlayerPostThink( ply ) ply:SetBusy( ply:WaterLevel() == 3 ) --If the player is fully underwater, they're considered 'busy'. --ply:SetNWBool( "Busy", ply:WaterLevel() == 3 ) --The alternative way to do it, you don't get the pretty get and set functions if you didn't setup 'Busy' in SetupDataTables end function GM:KeyPress( ply, key ) if key == IN_USE and !ply:GetBusy() --If they're pressing use, and they're not busy (in this case, fully submerged in water) ply:Kill() --Kill them. end --Alternative way again, just for example --if key == IN_USE and !ply:GetNWBool( "Busy" ) then --ply:Kill() --end end [/lua] Unless you have a really good reason not to, I would HIGHLY RECCOMEND making this all shared, as networked variables come bundled with clientside prediction (without having to do anything on your end, except making it shared) which can make 400 ping unnoticeable in certain aspects: [video=youtube;8uRn9-_ONpI]https://www.youtube.com/watch?v=8uRn9-_ONpI&lc=z13dfzmhnlrkcdqq204chlnyjs25j145z3w[/video] While you should read the wiki for more specifics on networked variables, keep in mind that they have the server>client interaction that you want, in which the client can NOT mess with the networked variable, and the server's value is absolute. (you can actually set a networked variable clientside, but it will only be set on THAT client, on the client. Again, the specifics on the wiki.) Other than the wiki, here is a thread in which garry gives some more helpful info on when to use networked stuff, I reccomend reading it all (only about 2 pages): [url]https://facepunch.com/showthread.php?t=1253834&[/url]
[QUOTE=Wepl123;52407605]Welp123's Post[/QUOTE] Excellent information thank you, well received and I will dig through that now. Before I do though, in my case I am using net.Send to trigger the menus and such. To show what I'm talkin about, here's a very brief psuedo of what I'm currently doing (and it's fully functional as of right now) [lua] -- Note this is not in proper Lua ----------------- -- CLIENT FILE -- ----------------- hook.Add KeyPress if key == IN_USE then net.Start("cl_msg") SendToServer() end end local function OpenMenu -- various drawing and variables in here to work the menu end net.Receive "msg" OpenMenu ----------------- -- SERVER FILE -- ----------------- net.Receive "cl_msg" function() --is the player close enough to the prop to use this menu? net.Start("msg") net.Send(cl) end)[/lua] The idea is to have the player press E on a gamemode item to pull up a menu. The menu can only be opened if the server's criterias are met, and then a final check is conducted when the player spawns/buys an item from the menu, to make sure they're allowed to do it. That way, clients who are trying to cheat/mess with the code to benefit themselves, would still have to request these actions from the server. They might be able to get the menu open with client coding, but they won't be able to do anything with it. The other idea I had was to move ALL of it to a single shared file, and have all of it run by the server except for the keypress hook... Would probably be cleaner, but since shared files are downloaded to the client, they would see all the variables, keywords, and functions that it's checking against.
[QUOTE=Rory;52407790]Excellent information thank you, well received and I will dig through that now. Before I do though, in my case I am using net.Send to trigger the menus and such. To show what I'm talkin about, here's a very brief psuedo of what I'm currently doing (and it's fully functional as of right now) [lua] -- Note this is not in proper Lua ----------------- -- CLIENT FILE -- ----------------- hook.Add KeyPress if key == IN_USE then net.Start("cl_msg") SendToServer() end end local function OpenMenu -- various drawing and variables in here to work the menu end net.Receive "msg" OpenMenu ----------------- -- SERVER FILE -- ----------------- net.Receive "cl_msg" function() --is the player close enough to the prop to use this menu? net.Start("msg") net.Send(cl) end)[/lua] The idea is to have the player press E on a gamemode item to pull up a menu. The menu can only be opened if the server's criterias are met, and then a final check is conducted when the player spawns/buys an item from the menu, to make sure they're allowed to do it. That way, clients who are trying to cheat/mess with the code to benefit themselves, would still have to request these actions from the server. They might be able to get the menu open with client coding, but they won't be able to do anything with it.[/QUOTE] Ah, then keeping KeyPress clientside should be fine. Just create a networked variable 'CanUseMenu' or hell, even 'Busy' and lets say the server criteria is being alive: [lua] --Shared function GM:PlayerPostThink( ply ) ply:SetBusy( !ply:Alive() ) --Considered busy if dead end [/lua] [lua] --Clientside hook.Add( "KeyPress", "OpenClientMenu", function( ply, key ) if key == IN_USE and !ply:GetBusy() then --Even though this is clientside, Busy is a networked variable in sync with the server, and grabs it immediately instead of having to wait for two net messages --Open the menu here end end ) [/lua] This removes the unnessecary net message in place of a networked variable, which should be done whenever and wherever possible, because net messages are pretty heavily effected by latency. For example, if you used the current system where it sends a message to the server, and waits for the message back before opening the menu, if the player had ~150 ping it could take anywhere from 0.5-1 seconds before opening, if at all. However, with a networked variable being kept in sync with the server every tick, as well as with clientside prediction (assuming you're setting Busy in a shared function), the menu will open up immediately and without any delay.
Alright, now I'm really having issues. The script makes me blind... Here is the code: [lua] if LocalPlayer():Team() ~= TEAM_VORT then return end hook.Add( "PreDrawHalos", "AddHalos", function() for k, v in pairs( player.GetAll() ) do local vorts = {} if v:Team() == TEAM_VORT then table.insert( vorts, v ) end end halo.Add( vorts, Color( 0, 255, 0 ), 1, 1, 2, true, true ) end) timer.Simple(15, function() hook.Remove("PreDrawHalos", "AddHalos") end) [/lua] Here is the script error: [ERROR] lua/includes/modules/halo.lua:71: bad argument #1 to 'pairs' (table expected, got nil) 1. pairs - [C]:-1 2. Render - lua/includes/modules/halo.lua:71 3. v - lua/includes/modules/halo.lua:153 4. unknown - lua/includes/modules/hook.lua:84
[QUOTE=Shadow02;52407968]Alright, now I'm really having issues. The script makes me blind... Here is the code: [lua] if LocalPlayer():Team() ~= TEAM_VORT then return end hook.Add( "PreDrawHalos", "AddHalos", function() for k, v in pairs( player.GetAll() ) do local vorts = {} if v:Team() == TEAM_VORT then table.insert( vorts, v ) end end halo.Add( vorts, Color( 0, 255, 0 ), 1, 1, 2, true, true ) end) timer.Simple(15, function() hook.Remove("PreDrawHalos", "AddHalos") end) [/lua] Here is the script error: [ERROR] lua/includes/modules/halo.lua:71: bad argument #1 to 'pairs' (table expected, got nil) 1. pairs - [C]:-1 2. Render - lua/includes/modules/halo.lua:71 3. v - lua/includes/modules/halo.lua:153 4. unknown - lua/includes/modules/hook.lua:84[/QUOTE] Because you create a local table inside a loop and try to index it outside.
I am trying to use this text effect inside of a dframe but it doesn't seem to be working and there are no errors, am I doing something wrong? [CODE]local killstreak = 0 net.Receive("GetKillStreak",function(length) killstreak = net.ReadInt(32) print("Successfully received player killstreaks from server!", killstreak) end) local next_electric_effect = CurTime() + 0 local electric_effect_a = 0 function DrawElectricText(intensity, text, font, x, y, color, xalign, yalign) local xalign = xalign or TEXT_ALIGN_LEFT local yalign = yalign or TEXT_ALIGN_TOP surface.SetFont(font); local charw, charh = surface.GetTextSize(text) draw.SimpleText(text, font, x, y, color, xalign, yalign) if (electric_effect_a > 0) then electric_effect_a = electric_effect_a - (1000 * FrameTime()) end surface.SetDrawColor(102, 255, 255, electric_effect_a) for i = 1, math.random(5) do line_x = math.random(charw) line_y = math.random(charh) line_x2 = math.random(charw) line_y2 = math.random(charh) surface.DrawLine(x + line_x, y + line_y, x + line_x2, y + line_y2) end local effect_min = 0.5 + (1 - intensity) local effect_max = 1.5 + (1 - intensity) if (next_electric_effect <= CurTime()) then next_electric_effect = CurTime() + math.Rand(effect_min, effect_max) electric_effect_a = 255 end end hook.Add("HUDPaint", "killstreak_DrawKills", function(pl) DrawElectricText(8, "Killstreak : "..(killstreak||0), "DermaLarge", 128, 128, Color(0, 0, 255)) end) local killstreak_panel = vgui.Create("DFrame","killstreak_panel") killstreak_panel:ShowCloseButton(false) killstreak_panel:SetTitle("") killstreak_panel:SetSize(200,100) killstreak_panel:SetPos(-200,200) killstreak_panel:MakePopup() killstreak_panel:MoveTo(0,200,2,1,-1) function killstreak_panel:Paint(w,h) draw.RoundedBox(8,0,0,200,100,Color(255,255,255)) DrawElectricText(8, "Killstreak : "..(killstreak||0), "DermaLarge", 128, 128, Color(0, 0, 255)) end timer.Simple(3, function() killstreak_panel:MoveTo(-200,200,2,1,-1) timer.Simple(6, function() killstreak_panel:Close() end) end)[/CODE]
I'm trying to make a poison zombie torso. and the code is at the bottom. and my problem is that first off the torso is slightly floating? and when disable ai is on it goes to T animation instead of idle animation. Help? function ENT:RunBehaviour() while ( true ) do timer.Simple(1.7,function() end) local ent = ents.Create("npc_poisonzombie") ent:SetPos(self:GetPos() + Vector(0,0,20)) ent:SetAngles(self:GetAngles()) ent:Spawn() ent:SetModel("models/zombie/poison_torso.mdl") ent:SetKeyValue( "crabcount", 0 ) ent:SetSaveValue("m_fIsTorso", true) ent:SetName("Poison Zombie Torso") undo.Create( "Poison Zombie Torso" ) local k, v for k, v in ipairs( ents.GetAll( ) ) do if v:IsPlayer() then undo.AddEntity( ent ) undo.SetPlayer( v ) undo.Finish() SafeRemoveEntity(self) coroutine.yield() end end end end
[QUOTE=Nak;52406881]Points will only change if the total number of players around the flag is more than the other teams. It will only display the message if the capturestat changes[/QUOTE] No i mean the player leave the flag the teamsOnPoint does not decrease [editline]28th June 2017[/editline] [code]function ENT:FlagCaptured(str_message) PrintMessage(HUD_PRINTCENTER, str_message) end function ENT:Think() local entpos = self:GetPos() for _, ply in ipairs(player.GetAll()) do if ply:Alive() then local dist = ply:GetPos():DistToSqr(entpos) if dist <= self.captureDistance then if self.capturestat ~= 1 then -- .. and they don't own it self.point = self.point + 1 end if self.capturestat ~= 2 then -- .. and they don't own it self.point = self.point - 1 end -- Update and check stuff if self.capturestat == 1 then if self.point <= 0 then -- Neutral self.capturestat = 0 self:FlagCaptured("THE FLAG IS NEUTRALIZED") end elseif self.capturestat == 2 then if self.point >= 0 then self.capturestat = 0 self:FlagCaptured("THE FLAG IS NEUTRALIZED") end elseif self.capturestat == 0 then if self.point >= 50 then self.capturestat = 1 self:FlagCaptured("TEAM BLUE HAS CAPTURED THE FLAG") elseif self.point <= -50 then self.capturestat = 2 self:FlagCaptured("TEAM RED HAS CAPTURED THE FLAG") end end end end end print("why ", self.point) self:NextThink(CurTime() + 2) return true end[/code] Again this keep printing every tick despite i put the nextthink there
Sorry, you need to Log In to post a reply to this thread.