• Problems That Don't Need Their Own Thread v5
    4,111 replies, posted
Am I only one who gets weird trace if you do more than two trace simultaneously? It can't detect the displacements. [editline]27th May 2017[/editline] Warning, Spaghetti ahead: [url]https://pastebin.com/0PMEMfGn[/url]
How can I force npc_metropolice to holster his stunstick?
[QUOTE=dannyf127;52280510]What's the best way to get the distance from the player to the ground beneath them?[/QUOTE] Use a [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/util/TraceLine]util.TraceLine[/url] going down from their feet and get the distance from the origin position and the hit position.
[QUOTE=dannyf127;52280510]What's the best way to get the distance from the player to the ground beneath them?[/QUOTE] util.TraceLine downwards.
[QUOTE=dannyf127;52280510]What's the best way to get the distance from the player to the ground beneath them?[/QUOTE] What others said + Also, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/IsOnGround]Entity:IsOnGround[/url] first to know that the distance is 0. I haven't tested but it might be possible for a traceline from the feet downwards to miss the floor surface.
Do a trace directly downward from the player's position [editline]27th May 2017[/editline] ninja'd a billion times in a row
Is there a way to automatically clear the text inside a DTextEntry, once the user clicks it?
-snip-
-snip- :/
[QUOTE=SkitZz;52280706]Is there a way to automatically clear the text inside a DTextEntry, once the user clicks it?[/QUOTE] Try overriding [URL="https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/vgui/dtextentry.lua#L319-L331"]OnGetFocus[/URL] [editline]27th May 2017[/editline] [CODE] function sometextentry:OnGetFocus() self:SetText( "" ) end [/CODE]
[QUOTE=MPan1;52280868]Try overriding [URL="https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/vgui/dtextentry.lua#L319-L331"]OnGetFocus[/URL] [editline]27th May 2017[/editline] [CODE] function sometextentry:OnGetFocus() self:SetText( "" ) end [/CODE][/QUOTE] That worked like a dream. Thank you, MPan. Have a rating. :yarr:
[QUOTE=SkitZz;52281251]That worked like a dream. Thank you, MPan. Have a rating. :yarr:[/QUOTE] You'll probably wanna be careful with this. Every time you select the text entry again it will set the text to nothing. You should probably check for a "IsUsed" variable and set it to true upon the first use. [lua]function sometextentry:OnGetFocus() if self.IsUsed then return end self:SetText( "" ) self.IsUsed = true end[/lua]
So I'm writing a script that changes map lighting on the fly with engine.LightStyle, and I've come across a problem - while props change their lighting somewhat consistently according to engine.LightStyle, the difference in lighting between sleeping objects to woken objects is way too visible, especially in dark environments. On r_radiosity 2, this is the difference between sleeping objects: [T]https://cdn.discordapp.com/attachments/316871149491322881/318119436446072832/poster-17-05-27_23-12-31.png[/T] And woken objects: [T]https://cdn.discordapp.com/attachments/316871149491322881/318119447778951168/poster-17-05-27_23-12-29.png[/T] Is there a (none r_radiosity related) way of reducing this difference or standardizing it so all props are lit as if they were asleep without actually waking them every couple of ticks?
so i was creating custom entity that randomizes 1 item out of 3 BUT it spawns 2 of them on middle of map and not in top of entity i didnt get any errors heres code [lua]function ENT:Use( activator, caller ) local Rand = math.random(1, 3) local SpawnHeight = 50 local Drop if Rand == 1 then Drop = ents.Create("item_ammo_ar2") Drop:Spawn() Drop:Activate() elseif Rand == 2 then Drop = ents.Create("item_ammo_pistol") Drop:Spawn() Drop:Activate() elseif Rand == 3 then Drop = ents.Create("item_ammo_smg1_large") Drop:Spawn() Drop:Activate() end end [/lua] did i forgot something?
You didn't set the position, and I think ENT:Use may be getting called twice for some reason [editline]28th May 2017[/editline] Also, I would rewrite the code to be a little simpler like so: [CODE] local drops = { "item_ammo_ar2", "item_ammo_pistol", "item_ammo_smg1_large" } function ENT:Use( activator, caller ) local drop = ents.Create( drops[ math.random( 1, 3 ) ] ) drop:SetPos( self:GetPos() + Vector( 0, 0, 50 ) ) drop:Spawn() drop:Activate() end [/CODE]
[QUOTE=MPan1;52283758]You didn't set the position, and I think ENT:Use may be getting called twice for some reason [editline]28th May 2017[/editline] Also, I would rewrite the code to be a little simpler like so: [CODE] local drops = { "item_ammo_ar2", "item_ammo_pistol", "item_ammo_smg1_large" } function ENT:Use( activator, caller ) local drop = ents.Create( drops[ math.random( 1, 3 ) ] ) drop:SetPos( self:GetPos() + Vector( 0, 0, 50 ) ) drop:Spawn() drop:Activate() end [/CODE][/QUOTE] thanks but i got error from that [lua][ERROR] lua/entities/gun_safe/init.lua:29: ')' expected near ']' 1. unknown - lua/entities/gun_safe/init.lua:0 [/lua]
[QUOTE=RasmusG5;52283774]thanks but i got error from that [lua][ERROR] lua/entities/gun_safe/init.lua:29: ')' expected near ']' 1. unknown - lua/entities/gun_safe/init.lua:0 [/lua][/QUOTE] Code looks fine to me, did you copy the parenthesis after the table closure? [editline]28th May 2017[/editline] [QUOTE=MPan1;52283758]You didn't set the position, and I think ENT:Use may be getting called twice for some reason [editline]28th May 2017[/editline] Also, I would rewrite the code to be a little simpler like so: [CODE] local drops = { "item_ammo_ar2", "item_ammo_pistol", "item_ammo_smg1_large" } function ENT:Use( activator, caller ) local drop = ents.Create( drops[ math.random( 1, 3 ) ] ) drop:SetPos( self:GetPos() + Vector( 0, 0, 50 ) ) drop:Spawn() drop:Activate() end [/CODE][/QUOTE] Just thought I'd throw something in while I was doing some object debugging: adding the numbers to the cached vector element manually reduces the number of vectors created from three (GetPos, Vector(0,0,50), addition vector) to one. Ex. [code]local vPos = self:GetPos() vPos[3] = vPos[3] + 50 self:SetPos(self:GetPos())[/code] Slightly longer code, but saves rapid object creation/deletion.
[QUOTE=code_gs;52283778]Code looks fine to me, did you copy the parenthesis after the table closure? [editline]28th May 2017[/editline] Just thought I'd throw something in while I was doing some object debugging: adding the numbers to the cached vector element manually reduces the number of vectors created from three (GetPos, Vector(0,0,50), addition vector) to one. Ex. [code]local vPos = self:GetPos() vPos[3] = vPos[3] + 50 self:SetPos(self:GetPos())[/code] Slightly longer code, but saves rapid object creation/deletion.[/QUOTE] i fixed error but it spawns all 3 items
[QUOTE=RasmusG5;52283786]i fixed error but it spawns all 3 items[/QUOTE] Make sure you have set the use type to SIMPLE_USE.
[QUOTE=code_gs;52283804]Make sure you have set the use type to SIMPLE_USE.[/QUOTE] how do i do that i am new to lua
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetUseType]Entity:SetUseType[/url]
[QUOTE=RasmusG5;52283813]how do i do that i am new to lua[/QUOTE] [QUOTE=MPan1;52283816][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetUseType]Entity:SetUseType[/url][/QUOTE] And run it in [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ENTITY/Initialize]ENT:Initialize[/url]
[QUOTE=code_gs;52283817]And run it in [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ENTITY/Initialize]ENT:Initialize[/url][/QUOTE] so like this? [lua]function ENT:Initialize() self:SetModel( "models/props_c17/oildrum001.mdl" ) Entity:SetUseType( SIMPLE_USE ) self:SetMoveType( MOVETYPE_VPHYSICS ) self:SetSolid( SOLID_VPHYSICS ) if ( SERVER ) then self:PhysicsInit( SOLID_VPHYSICS ) end local phys = self:GetPhysicsObject() if ( IsValid( phys ) ) then phys:Wake() end end[/lua] i got error [lua][ERROR] lua/entities/gun_safe/init.lua:26: attempt to index global 'Entity' (a function value) 1. unknown - lua/entities/gun_safe/init.lua:26 2. Spawn - [C]:-1 3. SpawnFunction - gamemodes/base/entities/entities/base_entity/init.lua:70 4. Spawn_SENT - gamemodes/sandbox/gamemode/commands.lua:655 5. unknown - gamemodes/sandbox/gamemode/commands.lua:720 6. unknown - lua/includes/modules/concommand.lua:54 [/lua]
Use self instead of entity. It's an entity function, but you need to provide it a variable
could anyone hook me up with simple lua code I could use to change a models texture using the entitys name (for lua_run entity in hammer)
[QUOTE=Rocketsurgery;52283924]could anyone hook me up with simple lua code I could use to change a models texture using the entitys name (for lua_run entity in hammer)[/QUOTE] [code]local t=ents.FindByName("name")for i=1,#t do t[i]:SetMaterial("some/material", true) end[/code]
If there's only one entity with the target name this should work: [CODE]ents.FindByName( "STICK THE NAME HERE" )[1]:SetMaterial( "MATERIAL IN HERE", true )[/CODE] EDIT: Brain fart with lua tables.
[QUOTE=cpone;52283967]If there's only one entity with the target name this should work: [CODE]ents.FindByName( "STICK THE NAME HERE" )[0]:SetMaterial( "MATERIAL IN HERE", true )[/CODE][/QUOTE] Lua tables start from 1, not 0.
So i have this table structure, where i want to select stuff from. [code] local prize = {} prize[1] = { item = "Blah1", amount = {"1000"} } prize[2] = { item = "Blah2", amount = {"2000"} } local pickPrize = prize[ math.random( #prize) ] local generatedCode = generateCode(pickPrize.item, pickPrize.amount, "1") [/code] But for some reason, the pickPrize.amount does not work? pickPrize.item works just fine. I am obviously selecting it wrong, but what is the correct way?
[QUOTE=SkitZz;52283991]So i have this table structure, where i want to select stuff from. [code] local prize = {} prize[1] = { item = "Blah1", amount = {"1000"} } prize[2] = { item = "Blah2", amount = {"2000"} } local pickPrize = prize[ math.random( #prize) ] local generatedCode = generateCode(pickPrize.item, pickPrize.amount, "1") [/code] But for some reason, the pickPrize.amount does not work? pickPrize.item works just fine. I am obviously selecting it wrong, but what is the correct way?[/QUOTE] [img]http://i.imgur.com/bQshWcL.png[/img] Looks fine to me; the only thing is that you're putting "amount" in a table in your prize element declaration, which means you'll have to do pickPrize_amount_variable[1] inside the function.
Sorry, you need to Log In to post a reply to this thread.