The player is the object itself, not `self.Player`.
http://wiki.garrysmod.com/page/PLAYER/SetupDataTables is for player classes which are part of the gamemode, it isn't something you should use in an addon. Continue to use either NWVars or NW2Vars.
Yeah I know not to use that in an addon. But it's only an addon right now because I'm testing stuff in Sandbox, once I move to gamemode I'll have to re-do this stuff.
Thanks though. Something I read made me think I should use self.Player but getting rid of .Player fixed everything!
You should use `self.Player` in player manager class hooks (http://wiki.garrysmod.com/page/Category:PLAYER_Hooks), http://wiki.garrysmod.com/page/PLAYER/SetupDataTables is one of them. In your case you were creating a function on the player meta table, thus it's being used on actual player objects.
If you do create a gamemode and plan to overwrite gamemode hooks, you'll have to still call (some) baseclass functions for player manager class hooks to run. Also, if there's code that you don't want in the baseclass you'll have to pull the player manager parts out.
https://imgur.com/8LattY8
Uh. So I created a floating HUD, and now I've added some floating stuff onto an entity and this happens. Is there an easy fix for this?
I mean there probably is an easy fix, but you're going to need to post the code you use to set up rendering for both the hud and the floaty panel.
function DrawPrices()
for k, ent in pairs(ents.FindByClass( "ddl_pw_overcharge" )) do
local AttachPos = ent:GetPos()
local AttachAng = ent:GetAngles()
AttachAng:RotateAroundAxis(AttachAng:Right(),90)
AttachAng:RotateAroundAxis(AttachAng:Forward(),180)
AttachAng:RotateAroundAxis(AttachAng:Up(),270)
local Upv = AttachAng:Up()
local Fwd = AttachAng:Forward()
local Rgt = AttachAng:Right()
AttachPos = AttachPos + (Fwd*1.5) + (Upv*.8) + (Rgt*-10.7)
cam.Start3D2D( AttachPos, AttachAng, .025 )
^ That's for the HEV plate on the wall. I omitted all of the surface.SetDrawColor and surface.DrawRect, surface.SetFont, surface.SetTextColor, surface.SetTextPos, and surface.DrawText lines.
I'm sure there's a way to index all of these entities that's faster than running through a for loop of ents.FindByClass, but I forgot how.
I suppose my code for the floating HUD panel thing could be neater. It's not really a panel either I guess. Anyway, here it is (using the {} thing messed up the spacing a lot, so I just place it as a quote):
local FruitPunch = plr:GetPunchAngle()
FP_Pear = FruitPunch.p*(-3)
FP_Yellow = FruitPunch.y*6
FP_Raspberry = FruitPunch.r*6
-- print(tostring(FruitPunch))
local HPRatio = math.Clamp(HP/plr:GetMaxHealth(),0,1)
local APRatio20 = math.Clamp(AP/20,0,1)
local APRatio40 = math.Clamp((AP-20)/80,0,1)
local APRatio60 = math.Clamp((AP-100)/100,0,1)
-- print(APRatio60)
local AttachAng = plr:GetAngles() --Angle(0,0,0)
local ApproaYaw = AttachAng.y
-- if ApproaYaw < 0 then OldYaw = OldYaw-360 end
-- OldYaw = Lerp(FrameTime()*1,OldYaw,AttachAng.y)
OldYaw = math.ApproachAngle( OldYaw, ApproaYaw, FrameTime()*90 )
AttachAng.p = 0
AttachAng.r = 0
AttachAng.y = OldYaw
local AttachVec = plr:GetAimVector():Angle()
AttachVec.p = 0
AttachVec = AttachVec:Forward()
local addZ = 64
if plr:Crouching() then addZ = 28 end
local AttachPos = plr:GetPos() + AttachAng:Forward()*12 + Vector(0,0,addZ) --Vector(0,0,0)
local cumZ = plr:GetPos().z
AttachPos = Vector(Lerp(FrameTime()*250,OldX,AttachPos.x),Lerp(FrameTime()*250,OldY,AttachPos.y),Lerp(FrameTime()*7,OldZ,AttachPos.z))
OldX = AttachPos.x
OldY = AttachPos.y
OldZ = math.Clamp(AttachPos.z,cumZ+addZ-8,cumZ+addZ+8)
-- print(tostring(plr:GetPos()).." Plr")
-- print(tostring(AttachPos).." Atp")
AttachAng.p = -90
AttachAng:RotateAroundAxis(AttachVec,90+FP_Raspberry)
AttachAng.p = 0
local InvertedPear = 1
if FP_Pear < 0 then InvertedPear = -1 end
AttachAng:RotateAroundAxis(AttachVec:Angle():Up(),FP_Yellow*.1)
AttachAng:RotateAroundAxis(AttachVec:Angle():Right(),math.Clamp(((FP_Pear*FP_Pear)/90)*InvertedPear,-45,45))
What is the right way to write it please?
PrintTable(debug.getinfo( ConVar:SetInt()))
The HUD does not align with the player's pitch movement. I have yet to decide if I want to fix that or not.
What are you trying to do? ConVar is supposed to represent a ConVar object retrieved with GetConVar, and ConVar/SetInt returns nothing.
Thank you for your answer ! I'm trying to find if ConVar:SetInt() is used somewhere, but I don't think it's possible.
Your original attempt (if you didn't make it a function call) would've printed the information for the `ConVar.SetInt` function. e.g. the location of where it was made. This is useful if you want to see if it was overwritten.
If you want to see where `ConVar.SetInt` is called from you'll have to detour the original function on the `ConVar` meta table.
Something like that ? :
debug.getmetatable( ConVars )
Dunno if `ConVars` is a convar object here or not, but either way you should use FindMetaTable. The index would just be `SetInt`, you could just index it, no looping is required.
Something like this would be correct.
https://gist.github.com/bigdogmat/c72abebc17015cb33989b60e62386581
I can't see anything obvious that would cause those two hooks to interfere with each other, other than a couple of globals in the second one.
Possibly if you moved the per-entity thing into the ENTITY/DrawTranslucent on the entity itself the problem might magically go away?
Make sure you set
ENT.RenderGroup = RENDERGROUP_BOTH
Thanks for your help! The code you gave me returns the same thing I wrote above, I didn't know what gettingmetatable() was used for but thanks to you it changed thank you! I will however use "my" code because I understand it better
Both scripts you've posted will not work at all, and the first one aims to do something fundamentally different from the second. I'd suggest using my code or better explaining what it is you're doing.
Well I don't really know why you put "2" in debug.getinfo, however I saw that it prints the metatable of
Convar but I don't really know why 2 and meta are connected
PrintTable(debug.getinfo(2))
Ho and I have an another question, just before, you talk about debug.getinfo and said: This is useful if you want to see if it was overwritten. I then wondered how can we know that a function is overwritten just with this ? Is it by studying the source that we can know if the function is defined in the right file? Like if
net.Receive isn't defined in this folder: lua/includes/modules/net.lua
We can know that the function is Overwritten ?
The number is the level in the call stack we want to look at.
0 = debug.getinfo
1 = ConVar.SetInt
2 = The function that called ConVar.SetInt
My code will print information about that position in the call stack. So in my code it'll print the information about the function that called `ConVar.SetInt`, like the name, file it's in, line it's on, etc.
Just like debug.getinfo can return information about a function in the current call stack, it can also return general information about a function. If we pass a function to it it'll give us information about said function.
So yes, if we know the source of a function and then compare it to what debug.getinfo says the source is we can determine if it has been overwritten. Of course if there's malicious intent debug.getinfo could also be overwritten such that it returns the correct result. However there's many methods to get around this that would depend on the situation I won't go into in this post.
Hi, I'm having trouble retrieving material variables from objects. It is my understanding that ent:GetMaterial() function returns an empty string whenever it gets called on an entity with default material. So how would I go about retrieving a material on an object with default material set?
Great idea. Unfortunately this is what ended up happening:
https://imgur.com/a/N4bnXtL
How would I have a DModelPanel mimic the player's current animation?
I've been having a go at it for a good half hour and I still can't figure it out.
I hope not to be boring but could you explain more about the stack level please ? What is this
referring to?
Every function called creates what is known as a stack frame. If you are unfamiliar with stacks as a data structure, here is a small explanation (you can basically think of it as a stack of cards or plates in real life). debug.getinfo can be used to get information about each stack frame, and since stacks are a Last In First Out data structure, higher levels point to function calls farther from your source. 0 = the debug.getinfo call itself, and each level above that is another function call above that.
Bizarre.
If I were you, I'd try and make the absolute simplest example that causes this.
EG a completely blank SENT that spawns as that model and draws a white square and a HUD that draws a black square, simplifying all the positioning logic until this stops happening, then putting back whatever caused it.
If you still can't see what's wrong, you can then post the entire thing.
Well, after some feedback from some friends I think I'll just move the HUD to DrawHud, much simpler. Sure I won't have a floating HUD in 3D, but it's not like I was gonna make each player's floating hud visible to all other players anyway.
Is there any potential way to play an audio everywhere regardless of distance and also not effected by dsp? Certain maps or if you choose a dsp_room preset will make the sound bounce off the walls, which is not what i want it to do. I tried sound.PlayFile with "mono" but that does make the sound into mono, which i want both channels for stereo.
Hayo. At what moment should I begin to worry about database performance? I've got about 5 tables with an entry for each player, resulting to >8k entries per year. Does it make SQL operations any slower, or that system is extremely optimized and it will become slow at >1k tables with >100k entries each?
I feel embarrassed to admit this - I couldn't find this thread for a while so I ended up making a thread... I was in Garry's Mod General. I'm an idiot.
I need to figure out how to get NextBots to stop floating when on slanted surfaces. I'm sure it has to do with a vertical hull trace hitting at the edges.
https://youtu.be/ruKtG4wPjaU
I've tried disabling IK which does stop the wobbling but doesn't fix the floating.
https://youtu.be/DchBB1FPbNo
Any ideas how I might be able to get NextBots to stand on slanted surfaces?
It's okay, I didn't even notice the section when I responded
Currently still working on re-purposing crossbow bolts as physical bullets. Does anyone know how to remove/override the default effects or sounds from base entities?
Sorry, you need to Log In to post a reply to this thread.