• Problems That Don't Need Their Own Thread v3.0
    5,003 replies, posted
Is it possible (If so, how), to hook onto a AccessorFunc? Specifically for ttt. I'm kinda stumped on this one. I've been trying to find a way to check when ever [CODE] AccessorFunc(plymeta, "role", "Role", FORCE_NUMBER) [/CODE] Is called so I can check for [CODE] ply:setRole(role) [/CODE] Edit: forgot to mention its found in player_ext_shd.lua in \gamemode\terrortown @line 11
[QUOTE=Z0mb1n3;48833906]Aaaactually, GetPData [B]always[/B] returns a string, regardless of what you set it to. If you set it to boolean true, it will return string "true". Set it to number 12, it will return string "12".[/QUOTE] Oh shit, really? Wow, thanks I guess xD
Trying to get an entity to "listen" to chat, but the hook.add doesn't seem to be doing anything. Here's what I have: [code] //variables ENT.LastHeard = nil // function ENT:Use( activator, caller ) print(self.LastHeard) return end //Get Chat hook.Add( "OnPlayerChat", "getchat", function( ply, text, public ) print("I Listened!") FlowerLoc = self:GetPos() PlayerLoc = ply:GetPos() print(FlowerLoc) print(PlayerLoc) if (FlowerLoc:Distance( PlayerLoc ) < 10) then self.LastHeard = text return text end end ) [/code] Clicking on it just prints "Nil" 5 times and typing in chat doesn't print "I listened!" each time like I expected it too. Am I making an error or just using this hook wrong to begin with?
[QUOTE=Becomeimp;48834391]Trying to get an entity to "listen" to chat, but the hook.add doesn't seem to be doing anything. Here's what I have: [code] //variables ENT.LastHeard = nil // function ENT:Use( activator, caller ) print(self.LastHeard) return end //Get Chat hook.Add( "OnPlayerChat", "getchat", function( ply, text, public ) print("I Listened!") FlowerLoc = self:GetPos() PlayerLoc = ply:GetPos() print(FlowerLoc) print(PlayerLoc) if (FlowerLoc:Distance( PlayerLoc ) < 10) then self.LastHeard = text return text end end ) [/code] Clicking on it just prints "Nil" 5 times and typing in chat doesn't print "I listened!" each time like I expected it too. Am I making an error or just using this hook wrong to begin with?[/QUOTE] OnPlayerChat is a clientside hook. You're looking for PlayerSay. (unless this entity is clientside... I don't know much about entities)
[QUOTE=roastchicken;48834406]OnPlayerChat is a clientside hook. You're looking for PlayerSay. (unless this entity is clientside... I don't know much about entities)[/QUOTE] Oops, that was because I had been using PlayerSay the whole time and checked OnPlayerChat as a last ditch attempt. PlayerSay had been giving me the same resutlts
[QUOTE=Becomeimp;48834422]Oops, that was because I had been using PlayerSay the whole time and checked OnPlayerChat as a last ditch attempt. PlayerSay had been giving me the same resutlts[/QUOTE] Well first of all you're referencing LastHeard incorrectly inside the hook, because the hook doesn't contain a reference to the entity so you'll need to reference it with ENT.LastHeard instead of self.LastHeard. This would cause the use function to print nil, but I'm not sure about the other 4 nils.
[QUOTE=roastchicken;48834457]Well first of all you're referencing LastHeard incorrectly inside the hook, because the hook doesn't contain a reference to the entity so you'll need to reference it with ENT.LastHeard instead of self.LastHeard. This would cause the use function to print nil, but I'm not sure about the other 4 nils.[/QUOTE] Alright thanks, I fixed it up a bit. I also gave the first time the variable is called a string instead of nil: [code] //variables ENT.LastHeard = "Hello" // [/code] The hook is still not called, and clicking on it prints "Hello" exactly 4 times in the console. I can't find any reason it would be acting so odd?
You're referencing "self:GetPos()" in a non-meta function. 'self' does not exist in the hook you are using.
[QUOTE=Becomeimp;48834551]Alright thanks, I fixed it up a bit. I also gave the first time the variable is called a string instead of nil: [code] //variables ENT.LastHeard = "Hello" // [/code] The hook is still not called, and clicking on it prints "Hello" exactly 4 times in the console. I can't find any reason it would be acting so odd?[/QUOTE] I think the reason it prints the ENT.LastHeard four times is that ENT.Use just runs constantly as long as the use button is held. Use Entity:SetUseType( SIMPLE_USE ) to make it so it will only run the code once every time it is used. As for why the hook isn't working, I have no idea. If it's possible, maybe add the hook outside of the entity code and find a way to set LastHeard from outside the entity?
(I'm sorry if I'm just clogging up the thread at this point) Thanks for the replies so far. "Hello" now only prints once and that's all working correctly. The only thing not working now is that the hook just isn't calling at all [QUOTE=roastchicken;48834599] If it's possible, maybe add the hook outside of the entity code and find a way to set LastHeard from outside the entity?[/QUOTE] I could do that, but it's possible to spawn multiple of these entities. The only ways I can think of for doing this would be to use FindInSphere or to loop through every entity. Either of these options would be really taxing on a server to call on every chat message, since if I do it that way it would call even when the entity isn't spawned.
[QUOTE=Becomeimp;48834903](I'm sorry if I'm just clogging up the thread at this point) Thanks for the replies so far. "Hello" now only prints once and that's all working correctly. The only thing not working now is that the hook just isn't calling at all I could do that, but it's possible to spawn multiple of these entities. The only ways I can think of for doing this would be to use FindInSphere or to loop through every entity. Either of these options would be really taxing on a server to call on every chat message, since if I do it that way it would call even when the entity isn't spawned.[/QUOTE] PlayerSay is a serverside hook, so if the hook is in a clientside file, that may be why. EDIT: Is there a way to translate a key into a key enum? Example, I supply "g" and it returns the equivalent of KEY_G?
[QUOTE=Z0mb1n3;48835313]PlayerSay is a serverside hook, so if the hook is in a clientside file, that may be why. EDIT: Is there a way to translate a key into a key enum? Example, I supply "g" and it returns the equivalent of KEY_G?[/QUOTE] okay, you can do this method [code] function ReturnEnum( key ) if tonumber(key) then return (tonumber(key) + 1) end local test = string.byte( string.lower(key) ) if( test >= 97 and test <= 122 ) then return( test - 86 ) end end [/code] Probably add some checks to it. Note, this only does 0-9 A-Z If you want more, just add more checks.
edit: ninja'd
How easily could one make a window to view PDF files or HTML files?
[QUOTE=proboardslol;48836336]How easily could one make a window to view PDF files or HTML files?[/QUOTE] [url]http://wiki.garrysmod.com/page/Category:DHTML[/url]
Getting a weird error from a loop. This: [code] for k, v in pairs( ents.GetAll ) do print(k) end [/code] is giving me this: [code] bad argument #1 to 'pairs' (table expected, got function) [/code] I've also tried this: [code] local allents = ents.GetAll for k, v in pairs( allents ) do print(k) end [/code] And got the same thing. I'm running this in the autorun folder.
[QUOTE=Becomeimp;48836945]Getting a weird error from a loop. This: [code] for k, v in pairs( ents.GetAll ) do print(k) end [/code] is giving me this: [code] bad argument #1 to 'pairs' (table expected, got function) [/code] I've also tried this: [code] local allents = ents.GetAll for k, v in pairs( allents ) do print(k) end [/code] And got the same thing. I'm running this in the autorun folder.[/QUOTE] ents.GetAll is a function, not a table. You have to call it or it will return the actual function. ents.GetAll() will fix your problem.
[QUOTE=YaYaBinks3;48836963]ents.GetAll is a function, not a table. You have to call it or it will return the actual function. ents.GetAll() will fix your problem.[/QUOTE] Thanks! I can figure out the complicated stuff but of course it's always the syntax that messes me up :v
Is there something I can use to generate nodegraphs for all maps I have on my server automatically?
i get this error [code] [ERROR] gamemodes/terrortown/entities/weapons/weapon_ttt_cloak/shared.lua:102: Tried to use a NULL entity! 1. SetMaterial - [C]:-1 2. unknown - gamemodes/terrortown/entities/weapons/weapon_ttt_cloak/shared.lua:102 [/code] but without the code generating the error, the viewmodel doesn't go back to normal when its supposed to. with the code it does, but generates errors? [code]function SWEP:Holster() if CLIENT then self.Owner:GetViewModel():SetMaterial("") end --line 102 if IsFirstTimePredicted() then --self.Owner:GetViewModel():SetMaterial("") if ( self.conceal ) then self:UnCloak() end end return true end[/code]
Try changing CLIENT to SERVER maybe?
[QUOTE=343N;48838743]i get this error [code] [ERROR] gamemodes/terrortown/entities/weapons/weapon_ttt_cloak/shared.lua:102: Tried to use a NULL entity! 1. SetMaterial - [C]:-1 2. unknown - gamemodes/terrortown/entities/weapons/weapon_ttt_cloak/shared.lua:102 [/code] but without the code generating the error, the viewmodel doesn't go back to normal when its supposed to. with the code it does, but generates errors? [code]function SWEP:Holster() if CLIENT then self.Owner:GetViewModel():SetMaterial("") end --line 102 if IsFirstTimePredicted() then --self.Owner:GetViewModel():SetMaterial("") if ( self.conceal ) then self:UnCloak() end end return true end[/code][/QUOTE] Correct me if I'm mistaken but shouldn't you use use LocalPlayer() if it's clientside?
but I want it to change just the swep owner not every single player
[QUOTE=343N;48839079]but I want it to change just the swep owner not every single player[/QUOTE] Can you confirm self.Owner is a valid entity, is it being set up in the SWEPs code correctly?
[QUOTE=PigeonPatrol;48839143]Can you confirm self.Owner is a valid entity, is it being set up in the SWEPs code correctly?[/QUOTE] [code]if SERVER then AddCSLuaFile( "shared.lua" ) resource.AddFile("materials/vgui/ttt/lykrast/icon_cloak.vmt") end if( CLIENT ) then SWEP.PrintName = "Cloaking Device"; SWEP.Slot = 7; SWEP.DrawAmmo = false; SWEP.DrawCrosshair = false; SWEP.Icon = "VGUI/ttt/lykrast/icon_cloak"; SWEP.EquipMenuData = { type = "item_weapon", desc = "Hold it to become nearly invisible.\n\nDoesn't hide your name, or\nbloodstains on your body." }; end SWEP.Author= "Lykrast" SWEP.Base = "weapon_tttbase" SWEP.Spawnable= false SWEP.AdminSpawnable= true SWEP.HoldType = "normal" SWEP.Kind = WEAPON_EQUIP2 SWEP.CanBuy = {ROLE_TRAITOR} SWEP.ViewModelFOV= 60 SWEP.ViewModelFlip= false SWEP.ViewModel = "models/weapons/v_slam.mdl" SWEP.WorldModel = "models/weapons/w_slam.mdl" SWEP.UseHands = false --- PRIMARY FIRE --- SWEP.Primary.Delay= 1 SWEP.Primary.Recoil= 0 SWEP.Primary.Damage= 0 SWEP.Primary.NumShots= 0 SWEP.Primary.Cone= 0 SWEP.Primary.ClipSize= 1 SWEP.Primary.DefaultClip= 1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.NoSights = true function SWEP:Intialize() self:SetDeploySpeed(100) end function SWEP:PrimaryAttack() if IsFirstTimePredicted() then self:SetNextPrimaryFire(CurTime() + 0.5) if self.conceal then self:UnCloak() else self:Cloak() end end end function SWEP:Cloak() if SERVER then self.Owner:ChatPrint("Cloaked!") end self.Owner:GetViewModel():SetMaterial("models/screenspace") self.Owner:SetMaterial( "sprites/heatwave" ) self.Owner:DrawShadow(false) self:EmitSound( "AlyxEMP.Charge" ) if SERVER then self.Owner:DrawWorldModel( false ) end self:SetPlaybackRate(0.2) self:SendWeaponAnim(263) self:SetPlaybackRate(0.2) self.conceal = true end function SWEP:UnCloak() self.Owner:GetViewModel():SetMaterial("") if SERVER then self.Owner:ChatPrint("Uncloaked!") end self.Owner:SetMaterial("") self:SetMaterial("") self:EmitSound( "AlyxEMP.Discharge" ) self.Owner:DrawShadow(true) if SERVER then self.Owner:DrawWorldModel( true ) end self:SetPlaybackRate(0.2) self:SendWeaponAnim(263) self:SetPlaybackRate(0.2) self.conceal = false end function SWEP:Deploy() if IsFirstTimePredicted() then self.Owner:ChatPrint("Click to toggle cloak!") end self:SetDeploySpeed(100) self:SendWeaponAnim(261) end function SWEP:Holster() if CLIENT then self.Owner:GetViewModel():SetMaterial("") end if IsFirstTimePredicted() then --self.Owner:GetViewModel():SetMaterial("") if ( self.conceal ) then self:UnCloak() end end return true end function SWEP:OwnerChanged() --self.Owner:GetViewModel():SetMaterial("") self:SetMaterial("") --self.Owner:SetMaterial("") --self.Owner:DrawShadow(true) end function SWEP:PreDrop() if ( self.conceal ) then self.UnCloak() self.conceal = false end end hook.Add("TTTPrepareRound", "UnCloakAll",function() for k, v in pairs(player.GetAll()) do v:SetMaterial("") if SERVER then timer.Simple(3, function() v:GetViewModel():SetMaterial("") end) end v:DrawShadow(true) end end)[/code]
Why are you even calling it Client-side?
because it does nothing serverside because viewmodels dont exist there
I have two rather simple questions about precaching 1) so I'm pretty sure that for the default Tool weapon I saw that in the lua file that after the models were declared, they were also precached using util.PrecacheModel; do I need to do this for any SWEPS I create? [url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/sandbox/entities/weapons/gmod_tool/shared.lua[/url] 2) If I create a local table in a SWEP and have Sound(dir) inside the table, do I still need to precache it using util.PrecacheSound?
[QUOTE=PigeonTroll;48839708]I have two rather simple questions about precaching 1) so I'm pretty sure that for the default Tool weapon I saw that in the lua file that after the models were declared, they were also precached using util.PrecacheModel; do I need to do this for any SWEPS I create? [url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/sandbox/entities/weapons/gmod_tool/shared.lua[/url] 2) If I create a local table in a SWEP and have Sound(dir) inside the table, do I still need to precache it using util.PrecacheSound?[/QUOTE] Sound() and Model() functions are a convenience functions that simply precache given sound/model and return the string back. Precaching makes it so that when you first spawn the weapon, or first shoot with it, the tiny server/client hiccup is not there, it is instead moved to the loading screen ( or at the moment when the precaching functions are called )
[QUOTE=343N;48839274]because it does nothing serverside because viewmodels dont exist there[/QUOTE] Check if self.Owner is the LocalPlayer() clientside and, if it is, do your function. I think it errors because other players don't have view models on the client.
Sorry, you need to Log In to post a reply to this thread.