• Problems That Don't Need Their Own Thread v5
    4,111 replies, posted
Is there a way to check when a prop_ragdoll takes fall damage?
[QUOTE=Moat;52108713][lua] hook.Add("EntityTakeDamage", "Ragdoll Fall Damage", function(ent, dmginfo) if (ent:IsRagdoll() and dmginfo:IsFallDamage()) then -- code here end end) [/lua][/QUOTE] Oh, I already have that for bullet damage, I didn't know it worked for fall damage too. Thanks.
Hey, I'm pretty much as close as you'll get to a LUA noob.. I'm trying to create a basic prop counter that tracks the max props that the server allows, and how many props the user has spawned, but for the life of me I can't figure out how to make the counter itself work. [CODE] --font above ^^ not included. MaxProps = GetConVarNumber("sbox_maxprops") Props = 0 if ( SERVER ) then hook.Add("PlayerSpawnProp","PropCount", function(ply) Props = ply:GetCount("props") + 1 end) else hook.Add( "HUDPaint", "text", function() surface.SetFont( "font" ) surface.SetTextColor( 255, 255, 255, 255 ) surface.SetTextPos( ScrW() * 0.475, ScrH() / 100 ) surface.DrawText( Props.."/"..MaxProps) end ); end[/CODE]
Props = Props + 1 And use cvar:GetInt() instead of GetConVarNumber.
[QUOTE=txike;52109529]Props = Props + 1 And use cvar:GetInt() instead of GetConVarNumber.[/QUOTE] Your first solution still does nothing, same as mine. Second one throws up an error: [ERROR] lua/propcount.lua:21: attempt to index global 'cvar' (a nil value) 1. unknown - lua/propcount.lua:21 if I change it to ConVar instead of cvar, it says basically the same, except ConVar instead of cvar
[QUOTE=felonG;52109569]Your first solution still does nothing, same as mine. Second one throws up an error: [ERROR] lua/propcount.lua:21: attempt to index global 'cvar' (a nil value) 1. unknown - lua/propcount.lua:21 if I change it to ConVar instead of cvar, it says basically the same, except ConVar instead of cvar[/QUOTE] You need to use the cvar object. [url]http://wiki.garrysmod.com/page/Global/GetConVar[/url] Also you could use ents.FindByClass to get the number of props. [url]http://wiki.garrysmod.com/page/ents/FindByClass[/url]
[QUOTE=felonG;52109516]Hey, I'm pretty much as close as you'll get to a LUA noob.. I'm trying to create a basic prop counter that tracks the max props that the server allows, and how many props the user has spawned, but for the life of me I can't figure out how to make the counter itself work. [CODE] --font above ^^ not included. MaxProps = GetConVarNumber("sbox_maxprops") Props = 0 if ( SERVER ) then hook.Add("PlayerSpawnProp","PropCount", function(ply) Props = ply:GetCount("props") + 1 end) else hook.Add( "HUDPaint", "text", function() surface.SetFont( "font" ) surface.SetTextColor( 255, 255, 255, 255 ) surface.SetTextPos( ScrW() * 0.475, ScrH() / 100 ) surface.DrawText( Props.."/"..MaxProps) end ); end[/CODE][/QUOTE] To get the value of sbox_maxprops, you need to get the convar. Do this by using GetConvar("sbox_maxprops"). After that, you can get its value with ConVar:GetInt(). (for example's sake: [I][B]GetConVar("sbox_maxprops"):GetInt()[/B][/I]). You can get the prop count of a player by using ply:GetCount("props"). This way you don't have to do anything serverside. Also, if the following happens and you're worried: GetCount will not update when a player uses the cleanup function. It'll update right after the player spawns another prop. [CODE] local ConVar = GetConVar("sbox_maxprops") -- get the sbox_maxprops ConVar local maxProps = ConVar:GetInt() -- get the value of ConVar (integer) hook.Add("HUDPaint", "drawPropCount", function() local propCount = LocalPlayer():GetCount("props") -- prop count of the local player surface.SetFont("ChatFont") surface.SetTextColor(255, 255, 255, 255) surface.SetTextPos(ScrW() / 2, ScrH() / 100) surface.DrawText(propCount .. "/" .. maxProps) -- display it as "propCount/maxProps" end) [/CODE] Or if you want something with even less lines, you could just use draw.SimpleText(). [CODE] local ConVar = GetConVar("sbox_maxprops") local maxProps = ConVar:GetInt() hook.Add("HUDPaint", "drawPropCount", function() local propCount = LocalPlayer():GetCount("props") draw.SimpleText(propCount .. "/" .. maxProps, "ChatFont", ScrW() / 2, ScrH() / 100, Color(255, 255, 255, 255)) end) [/CODE] [T]http://imgur.com/gGnzNIY.png[/T]
Thank you both for the assist :)
I'd like to just put some text into a material via rendertarget. No text is showing up when I do this, however. [code]local tex = CreateMaterial("materialText", "UnlitGeneric", { ["$basetexture"] = "vgui/white", ["$basetexturetransform"] = "center 0 0 scale 1 1 rotate 0 translate 0 0", ["$translucent"] = 1, ["$vertexcolor"] = 1, ["$vertexalpha"] = 1, ["$ignorez"] = 0 }); local text = "HELLO WORLD" local rt = GetRenderTarget("materialText", 512, 512, false); hook.Add("RenderScene", "capture", function() cam.Start2D() render.PushRenderTarget(rt) render.OverrideAlphaWriteEnable( true, true ) render.ClearDepth() render.Clear( 0, 0, 0, 0 ) render.OverrideAlphaWriteEnable( false ) surface.SetTextColor( 255, 255, 255, 255 ) surface.SetFont("skyrim") surface.SetTextPos( 0, 0 ) surface.DrawText( text ) surface.SetDrawColor(255, 255, 0, 255) surface.DrawRect(0, 0, 512, 512) render.PopRenderTarget() cam.End2D() tex:SetTexture("$basetexture", rt); hook.Remove("RenderScene", "capture"); end); hook.Add("HUDPaint", "test", function() surface.SetMaterial(tex); surface.SetDrawColor(255, 255, 255); surface.DrawTexturedRect(0, 0, 512, 512); end);[/code]
[QUOTE=Z0mb1n3;52115202]I'd like to just put some text into a material via rendertarget. No text is showing up when I do this, however. [code]local tex = CreateMaterial("materialText", "UnlitGeneric", { ["$basetexture"] = "vgui/white", ["$basetexturetransform"] = "center 0 0 scale 1 1 rotate 0 translate 0 0", ["$translucent"] = 1, ["$vertexcolor"] = 1, ["$vertexalpha"] = 1, ["$ignorez"] = 0 }); local text = "HELLO WORLD" local rt = GetRenderTarget("materialText", 512, 512, false); hook.Add("RenderScene", "capture", function() cam.Start2D() render.PushRenderTarget(rt) render.OverrideAlphaWriteEnable( true, true ) render.ClearDepth() render.Clear( 0, 0, 0, 0 ) render.OverrideAlphaWriteEnable( false ) surface.SetTextColor( 255, 255, 255, 255 ) surface.SetFont("skyrim") surface.SetTextPos( 0, 0 ) surface.DrawText( text ) surface.SetDrawColor(255, 255, 0, 255) surface.DrawRect(0, 0, 512, 512) render.PopRenderTarget() cam.End2D() tex:SetTexture("$basetexture", rt); hook.Remove("RenderScene", "capture"); end); hook.Add("HUDPaint", "test", function() surface.SetMaterial(tex); surface.SetDrawColor(255, 255, 255); surface.DrawTexturedRect(0, 0, 512, 512); end);[/code][/QUOTE] Edit: this post is wrong. oops. 1. local tex = CreateMaterial - you are creating a Material, not a texture, so I would name this variable "mat" instead of "tex" 2. local rt = GetRenderTarget here you are creating a texture, correctly. However, you're not using this texture, because: 3. ["$basetexture"] = "vgui/white" - the material is using the vgui/white texture, and doesn't use the materialText texture. I suggest: 1. move the rt = GetRenderTarget line to the top (more sensible to create the texture before the material) 2. change "vgui/white" to "materialText" after that, you should be good to go! Edit: oh, you did set the basetexture to the new one later on. hmm. Ignore me...
So I'm rendering 48^2 pixels in 3d2d context using surface.DrawRect and trying to lower the computational cost of it. My initial idea is to somehow normalize the scene so that it faces the viewer, and then save it via render target. Finally when I want, I can apply this texture to a quad. However, the idea behind normalization of a scene like this is hurting my brain. Can anyone maybe suggest something? [IMG]https://i.imgur.com/1Ris0Vj.png[/IMG]
I'm trying to network information related to an entity. No problem syncing all data afterwards but new players who join the server would have unsync data unless I manually send a full update to them.(sent via compressed pON) The information table from the entity's init function: [CODE]self.Data = { --relevant data for playing ["_SETUP"] = false, --ready? ["_N"] = "", --name ["_P"] = {}, --players ["_C"] = {}, --classes --# ["_M"] = {v = {}, f = {}}, --mesh for level making--# ["_VAL"] = {}, --values all players and teams should have ["_R"] = { --rules ["mode"] = "", --game mode ["start"] = 0, --start time ["len"] = 0, --round length (0 = inf) ["started"] =false, --round started? ["maxp"] = 0, --max points (0 = inf) ["forceteam"] = false, --force players to choose a team if available, else they can be alone against teams }, ["_T"] = {}, --Teams ["_E"] = { --entities that belong to this ent --_X_ = {pos,ang,class,model,scale,...?--#} --[ENT] = {?} (= _X_?) }, ["_S"] = { --spawn positions spawn --{pos, ang}, --pos is relative to the box's position, ang is not relative --{pos2, ang2}, }, ["_V"] = true, -- isolate the view ["_VP"] = false, -- show players anyways --["av"] = {}, --for values a gamemode added that should get restored/removed on change --["_av"] = {}, --same but for the _VAL table --s["_M"] = false, --magnetic ["_O"] = {"", self}, --owner ["POS"] = self:GetPos(), ["SIZE"] = Vector(500,500,200), }[/CODE] The '_O' '_E' '_P' subtables contain entities. Problem is that I receive NULL entities. I broke and fixed other code just to get to know that one can't just send entities over the network at any time. :blaze: So when is the earliest time I can receive all entities? Here's how I try it: [CODE]if SERVER then --add the sting util.AddNetworkString( "YourMessageName" ) --sending via initialspawn (serverside) hook.Add("PlayerInitialSpawn","spawntest",function(ply) net.Start( "YourMessageName" ) net.WriteEntity(ply) print( "######Sending", ply ,"to", ply) net.Send( ply ) end) --sending when client requested net.Receive( "YourMessageName", function( len, ply ) net.Start( "YourMessageName" ) net.WriteEntity(ply) print( "######Sending via nethook", ply ,"to", ply) net.Send( ply ) end ) else --getting yourself net.Receive( "YourMessageName", function( len, ply ) print( "######I got it!", net.ReadEntity() ) end ) --trying some hooks to request hook.Add("PostGamemodeLoaded","requestupdate",function() net.Start( "YourMessageName" ) print( "######requesting info PostGamemodeLoaded") net.SendToServer() end) hook.Add("InitPostEntity","requestupdate",function() net.Start( "YourMessageName" ) print( "######requesting info InitPostEntity") net.SendToServer() end) hook.Add("PreRender","requestupdate",function() net.Start( "YourMessageName" ) print( "######requesting info PreRender") net.SendToServer() hook.Remove("PreRender","requestupdate") end) end[/CODE] OUTPUT: PlayerInitialSpawn via server: SV:######Sending Player [1][SirRanjid] to Player [1][SirRanjid] CL:######I got it! [NULL Entity] PostGamemodeLoaded hook via client: CL:######requesting info PostGamemodeLoaded SV:######Sending Player [1][SirRanjid] to Player [1][SirRanjid] CL:######I got it! [NULL Entity] PreRender/InitPostEntity hook via client: CL:######requesting info InitPostEntity CL:######requesting info PreRender SV:######Sending via nethook Player [1][SirRanjid] to Player [1][SirRanjid] SV:######Sending via nethook Player [1][SirRanjid] to Player [1][SirRanjid] CL:######I got it! Player [1][SirRanjid] CL:######I got it! Player [1][SirRanjid] Other options in mind: Save the entity id(or steamid) to a cache table on the client and get the entity from the id once the first hook is called where you can. [editline]17th April 2017[/editline] [QUOTE=sharknado;52115934]So I'm rendering 48^2 pixels in 3d2d context using surface.DrawRect and trying to lower the computational cost of it. My initial idea is to somehow normalize the scene so that it faces the viewer, and then save it via render target. Finally when I want, I can apply this texture to a quad. However, the idea behind normalization of a scene like this is hurting my brain. Can anyone maybe suggest something? [IMG]https://i.imgur.com/1Ris0Vj.png[/IMG][/QUOTE] Render it via cam.Start2D() first, save and apply the texture to your 3d2d rendertarget EDIT2: got it working by caching the compressed pON strings for each entity as they don't care about entities until they get decoded when entities are working. Question that remains: So when is the earliest time I can receive all entities?
[CODE] function GM:PlayerInitialSpawn( ply ) ply:Spectate(OBS_MODE_ROAMING) end [/CODE] Can anyone tell me why this code in "init.lua" doesnt work?
Use SetObserverMode.
I have been trying to get the render bounds (positions in world) of the view drawn with render.RenderView, but no luck yet. Is this even possible? If so, can anyone push me in the right direction?
I have been creating something that spawns npc in-game and sets them to follow their "owner". [code] local humanone = ents.Create( "npc_citizen" ) humanone:SetPos( ply:GetPos() + Vector( 50, 0, 30 ) ) humanone:SetModel( "models/player/Group01/Male_07.mdl" ) humanone:SetSaveValue( "m_vecLastPosition", ply:GetPos() ) humanone:SetSchedule( SCHED_FORCED_GO ) humanone:Spawn() humanone.Owner = ply [/code] In normal single player this worked, but when I tried on a local server, the NPC's doesn't seem to follow where I go? They face me sometime, and also run away if I run into them fast. So they are interactive, just doesn't do what I want them to :/ In singleplayer the "SQUAD" thing also shows on the hud, but not on the local server. I've not tried on a dedicated server though.
Is there a way to simplify this: [CODE] if x then if y then -- do some other stuff here y = false end else y = true end [/CODE] I feel like there's a way to avoid 2 if statements
[code]if x and y then y = false else y = true end[/code]
[QUOTE=Lilyxfce;52119382]x and y[/QUOTE] That makes the 'else' statment get run when BOTH x and y are false rather than just x though. I need it to ONLY run when x is false
[QUOTE=MPan1;52119385]That would work except that I need y to only be set to true if x is true, and if you do an 'and' check then you're checking BOTH to be true rather than just x.[/QUOTE] I am confused, in your original code, if x and y are both true, y is false. if x is false, then y is true. Is that not what you want? If you do not care if y is true or not and only want to set y to false if x is true, then you can do that. [code]if (x and y) then y = false elseif (!x) y = true end[/code] apologies if I am misreading you
Sorry about that, I was getting confused as well. I guess the only other way is to use elseif as you said, thanks! My brain isn't working very well [editline]18th April 2017[/editline] I was just trying to think of a way to make [URL="https://github.com/Mysterypancake1/GMod-Binding/blob/master/lua/autorun/client/bind.lua#L47-L60"]this[/URL] simpler, but I don't think there is one without checking x twice
[QUOTE=MPan1;52119378]Is there a way to simplify this: [CODE] if x then if y then -- do some other stuff here y = false end else y = true end [/CODE] I feel like there's a way to avoid 2 if statements[/QUOTE] [lua]if x and y then -- do some other stuff here end y = not x and true or y and false[/lua] [QUOTE=Rocket;52119571]I take it you missed the "do some other stuff here" part.[/QUOTE] I tried to ninja edit before it was too late :v:
[QUOTE=JasonMan34;52119570][lua]y = not x and true or y and false[/lua][/QUOTE] That literally translates to just y = not x. Looking back at the original code, I guess it really is as simple as: [lua]if x and y then -- do stuff end y = not x[/lua]
This is probably opening a new can of worms but what is the best and most client-friendly way of creating a damage-dealing projectile?
[QUOTE=Shenesis;52120232]What is client-friendly for you? A projectile that doesn't lag? What kind of damage do you want it to deal; explosive damage in a radius ([img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/util/BlastDamage]util.BlastDamage[/url]) or something else?[/QUOTE] I'm looking for a physical bullet instead of a hitscan bullet. Shooting entities is pretty shitty most of the time.
Simulate fake bullet positions in a shared tick hook.
[QUOTE=code_gs;52120639]Simulate fake bullet positions in a shared tick hook.[/QUOTE] Should I use util.TraceHull to check if it hit something?
[QUOTE=ROFLBURGER;52120589]I'm looking for a physical bullet instead of a hitscan bullet. Shooting entities is pretty shitty most of the time.[/QUOTE] I've never done this, so take this post with a grain of salt, but the way I see it you have 3 main options: 1. Make an actual physical bullet entity, same as the crossbow does it. I don't know the details of that but you can see the source for it [url=https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/game/server/hl2/weapon_crossbow.cpp]here[/url]. 2. Make a TraceLine (or several, in the shape of an arch) every tick, continuing the arch using whatever math you fancy, and checking what you hit. [Edit: and draw a visual effect for the bullet however you like.] 3. Same as 2 but with TraceHull, to give the bullet width. If the bullet is small this would be unnecessary. It also wouldn't be 100% accurate, since TraceHull can only make an axis-aligned box.
[QUOTE=ROFLBURGER;52120705]Should I use util.TraceHull to check if it hit something?[/QUOTE] I use this for some mele combat stuff at the moment, I've found it's buggy as all getout when the player is chasing and trying to hit an npc. Although you might not have the same problems if your targets don't turn on a dime and players can reasonably know where something will be to lead their shots.
[QUOTE=ROFLBURGER;52120705]Should I use util.TraceHull to check if it hit something?[/QUOTE] Use TraceLine if you want the bullets to be point sized. Use TraceHull otherwise.
Sorry, you need to Log In to post a reply to this thread.