[CODE]local string = "TEXT STEAM_0:1:2345678 MORE TEXT";
local pattern = "(STEAM)(_)[0-9](:)[0-9](:)[0-9]{3,8}";
local steamid = string.match( string, pattern);
print( steamid );[/CODE]
Result: nil.
Can someone tell me how to put this together right? I want to extract the Steam ID.
[QUOTE=Pon-3;38531275]There you go:
-code-[/QUOTE]
You try to call functions like hud.PaintPanel. Where are those defined?
If someone out there would help me with this, I would greatly appreciate it.
I need a code that would activate when you fire a weapon. When you shoot, I need it to blur your sound, as it would in real life.
Is there any simple way to do this? I am running Novus Two on Nexus, if anyone wants to know.
[QUOTE=itkuitkzhji;38536910][CODE]local string = "TEXT STEAM_0:1:2345678 MORE TEXT";
local pattern = "(STEAM)(_)[0-9](:)[0-9](:)[0-9]{3,8}";
local steamid = string.match( string, pattern);
print( steamid );[/CODE]
Result: nil.
Can someone tell me how to put this together right? I want to extract the Steam ID.[/QUOTE]
Lua's patterns aren't regular expressions, AFAIK they don't support specific numbers of repetitions.
[lua]
local steamid = string.match(text, "(STEAM_[0-9]:[0-9]:[0-9]+)")
[/lua]
should be a reasonable equivalent
I have been raging about a thing I just can't get working. I've got 3 DCollapsiveCategory and I want only one to be able to be expanded at a time. I tried doing this:
[lua]
function modelinformation.Header:OnMousePressed()
modelinformation:SetExpanded( 1 )
if charinformation:GetExpanded() == 1 then
charinformation:SetExpanded( 0 )
end
if skillsinformation:GetExpanded() == 1 then
skillsinformation:SetExpanded( 0 )
end
end
[/lua]
(Ugly, I know)
But that just doesn't do anything.
2 Questions (Don't want to double post or anything)
Do i have to add anything when loading a font from another game (i presume its possible). Nothing loads if i just use TF2.ttf.
Second question is when loading resources for a gamemode, where would one put a custom resource like a font.
Thanks :)
(I'm still trying to get my head round gamemodes and gm13 lua)
[QUOTE=Verdict;38537851]If someone out there would help me with this, I would greatly appreciate it.
I need a code that would activate when you fire a weapon. When you shoot, I need it to blur your sound, as it would in real life.
Is there any simple way to do this? I am running Novus Two on Nexus, if anyone wants to know.[/QUOTE]
Player:SetDSP( iDspType ) is the function you're looking for. The argument is an integer, but there isn't an enum for it in gmod or the SDK, so you'll have to experiment with it until you find one you like.
Is there a way to access models in the map, which don't have an entity id?
Reason being, certain models are in a map that I'd like to remove but ents.GetAll() does not show them because their parent is set to world, I believe...
Is there any other way to target specific models in the map by name?
Further information: Remover tool can not target the model but it is a solid, but listing all models in the map shows that model being used. Also, I can't remove non-solid props...
Can you create custom hooks and call multiples of them?
function RoundStart()
end
hook.Add("RoundStart", "WeaponAdjustments"
hook.Add("RoundStart", "ToolAdjustments"
Ect?
[QUOTE=find me;38539888]Can you create custom hooks and call multiples of them?
function RoundStart()
end
hook.Add("RoundStart", "WeaponAdjustments"
hook.Add("RoundStart", "ToolAdjustments"
Ect?[/QUOTE]
Yea.
[QUOTE=Darkwater124;38536920]You try to call functions like hud.PaintPanel. Where are those defined?[/QUOTE]
They are defined earlier in the code. I didn't want to paste all of that.
[QUOTE=Luni;38538427]Lua's patterns aren't regular expressions, AFAIK they don't support specific numbers of repetitions.
[lua]
local steamid = string.match(text, "(STEAM_[0-9]:[0-9]:[0-9]+)")
[/lua]
should be a reasonable equivalent[/QUOTE]
THank you. ^^
[QUOTE=Ghor;38539685]Player:SetDSP( iDspType ) is the function you're looking for. The argument is an integer, but there isn't an enum for it in gmod or the SDK, so you'll have to experiment with it until you find one you like.[/QUOTE]
Great, thanks.
-snip-
[QUOTE=Pon-3;38540220]They are defined earlier in the code. I didn't want to paste all of that.[/QUOTE]
Well, I think the problem is with those functions.
What would make,
[lua]self.Weapon:DefaultReload( ACT_VM_RELOAD )[/lua]
work on a dedicated server (not listen) on my computer but break in an hosted dedicated server?
On the hosted one, there's a very quick (0.1 second) start of an animation and no reloading time. I can shoot after 0.05 seconds.
[B]Edit[/B]: Could be a problem with the fact that I use CS:S models and CS:S isn't installed on this other box?
Does anyone know if there is a working socket module?
The project I was working on used the gm_curly module to make some API requests to a website, but I can't seem to find a working replacement.
Anyone knows why my PNG's are getting scaled up when i try to use them in my HUD/UI ?
IE. I made a logo for on my scoreboard, but the width and height are getting stretched. making it look weird.
All help is welcome, Thanks.
When I save my GMod Lua file that is running in-game for the 2nd or 3rd time, the game crashes. It's tedious to reconnect every time I need to test the code. Does anyone know how to fix this?
[QUOTE=CrashLemon;38543403]What would make,
[lua]self.Weapon:DefaultReload( ACT_VM_RELOAD )[/lua]
work on a dedicated server (not listen) on my computer but break in an hosted dedicated server?
On the hosted one, there's a very quick (0.1 second) start of an animation and no reloading time. I can shoot after 0.05 seconds.
[B]Edit[/B]: Could be a problem with the fact that I use CS:S models and CS:S isn't installed on this other box?[/QUOTE]
CS:S would need to be installed on the client and server. If that's not working, then make sure you're calling that shared?
[QUOTE=Siniq;38543752]Anyone knows why my PNG's are getting scaled up when i try to use them in my HUD/UI ?
IE. I made a logo for on my scoreboard, but the width and height are getting stretched. making it look weird.
All help is welcome, Thanks.[/QUOTE]
It's probably being resized because it's an odd resolution - all images that you want to use have to have a width and height that are powers of two.
Hello Thread,
I have 2 Questions regarding Clientside-Lua
[B]Nr1.:[/B]
I have a question regarding ents.FindByClass()
I use this function to find Malicious E2 on a server as an admin without the need to use an E2 myself. The LUA script I have lets me see the Class of an E2 hovering over it, even through walls.
So far so good. I have noticed that on large maps the name is not instnatly displayed. Often its is neccesarry for me to be very close to the Entity for it to be detected.
the player.GetAll() function im comparision finds every player instantly. Is there like a "entity fade out of Game model" distance that I can change so my Garrysmod will find them ?
[B]Nr.2:
[/B]In Expression 2 there is the possibilty to make everything a player says visible using a method of "runOnChat" and for those of you that dont know E2 commands somethink like "if a player triggered chat anyhow, display what he typed". I am trying to redo this function in LUA.
I have all the neccesary functions to display the text but the problem is once more the detection.
Im currently hooking the function to OnPlayerChat but this will only trigger for me as Local player, meaning: Only when MY chatbox changes it will dislpay that change again (basicly useless unless you want to change the style of the chat). I however want to make chat visible that has been hidden with the E2 function "hideChat(1)" and sorts.
Are there other hooks or possibiltys to achieve this ?
As you might notice I started LUA a few days ago coming from E2 programming. I was told that everything you can do with E2 is also possible if not even better possible with LUA.
Thank you for your time and hints :)
I have an entity that other entities are derived from. I want to put the "ENT:OnTakeDamage()" on this baseclass so I don't have to implement it in all of the other iterations. Problem is, when the function is called, it gives me the "attempt to index field 'Entity' (a nil value) at line 8.
This is the function in my baseclass:
[lua]-- Damage function here.function ENT:OnTakeDamage( dinfo )
print("");
-- Check if we're alive.
if ( self.Entity.alive == false ) then return end
-- Misc Variables
local dmg = dinfo:GetDamage()
-- Damage taken is multiplied depending on the type of dmg taken.
if dinfo:IsDamageType( DMG_BULLET ) then
dmg = dmg * self.Entity.rifleDmgMult
elseif dinfo:IsDamageType( DMG_BLAST ) then
dmg = dmg * self.Entity.blastDmgMult
elseif dinfo:IsDamageType( DMG_SHOCK ) then
dmg = dmg * self.Entity.shockDmgMult
end
-- The actual health modification.
if self.Entity.health > 0 then
self.Entity.health = self.Entity.health - dmg;
end
-- Check if we're dead or not.
if self.Entity.health <= 0 then
self.Entity.alive = false
self.Entity.health = 0
end
print(self.Entity + " : " + self.Entity.health);
end[/lua]
[QUOTE=CrashLemon;38545839]I have an entity that other entities are derived from. I want to put the "ENT:OnTakeDamage()" on this baseclass so I don't have to implement it in all of the other iterations. Problem is, when the function is called, it gives me the "attempt to index field 'Entity' (a nil value) at line 8.
This is the function in my baseclass:
[lua]-- Damage function here.function ENT:OnTakeDamage( dinfo )
print("");
-- Check if we're alive.
if ( self.Entity.alive == false ) then return end
-- Misc Variables
local dmg = dinfo:GetDamage()
-- Damage taken is multiplied depending on the type of dmg taken.
if dinfo:IsDamageType( DMG_BULLET ) then
dmg = dmg * self.Entity.rifleDmgMult
elseif dinfo:IsDamageType( DMG_BLAST ) then
dmg = dmg * self.Entity.blastDmgMult
elseif dinfo:IsDamageType( DMG_SHOCK ) then
dmg = dmg * self.Entity.shockDmgMult
end
-- The actual health modification.
if self.Entity.health > 0 then
self.Entity.health = self.Entity.health - dmg;
end
-- Check if we're dead or not.
if self.Entity.health <= 0 then
self.Entity.alive = false
self.Entity.health = 0
end
print(self.Entity + " : " + self.Entity.health);
end[/lua][/QUOTE]
stop using self.Entity, just use self
Ever since the update a week or so ago, I can no longer use anything ents.* related (ents.GetAll()) ents.FindByClass() etc etc.
Is there a work around? or..?
[QUOTE=Chazin;38545109]Hello Thread,
I have 2 Questions regarding Clientside-Lua
[B]Nr1.:[/B]
I have a question regarding ents.FindByClass()
I use this function to find Malicious E2 on a server as an admin without the need to use an E2 myself. The LUA script I have lets me see the Class of an E2 hovering over it, even through walls.
So far so good. I have noticed that on large maps the name is not instnatly displayed. Often its is neccesarry for me to be very close to the Entity for it to be detected.
the player.GetAll() function im comparision finds every player instantly. Is there like a "entity fade out of Game model" distance that I can change so my Garrysmod will find them ?
[B]Nr.2:
[/B]In Expression 2 there is the possibilty to make everything a player says visible using a method of "runOnChat" and for those of you that dont know E2 commands somethink like "if a player triggered chat anyhow, display what he typed". I am trying to redo this function in LUA.
I have all the neccesary functions to display the text but the problem is once more the detection.
Im currently hooking the function to OnPlayerChat but this will only trigger for me as Local player, meaning: Only when MY chatbox changes it will dislpay that change again (basicly useless unless you want to change the style of the chat). I however want to make chat visible that has been hidden with the E2 function "hideChat(1)" and sorts.
Are there other hooks or possibiltys to achieve this ?
As you might notice I started LUA a few days ago coming from E2 programming. I was told that everything you can do with E2 is also possible if not even better possible with LUA.
Thank you for your time and hints :)[/QUOTE]
I think what you are trying to do is beyond the bounds of clientside Lua alone. In Source, the client is only informed of the existence of entities when the server decides it is appropriate; this is usually only when the player and the entity enter a region of the map where they could potentially see one another. You can transmit this kind of information to the client with serverside code, but you would need to write it and then have the server owner install it on the server.
You were able to do what you did in E2 because E2's server code did most of that work. Clientside Lua is very limited.
[QUOTE=NintendoEKS;38546193]Ever since the update a week or so ago, I can no longer use anything ents.* related (ents.GetAll()) ents.FindByClass() etc etc.
Is there a work around? or..?[/QUOTE]
You'll have to be more specific about what "can no longer use" means. If you're getting an error, you'll want to post it. If you're getting unexpected behavior, you should probably describe it.
Specific error; "attempt to call field 'GetAll' (a nil value)"
[lua]
function Test()
for k,v in pairs(ents.GetAll()) do
print(v:GetClass())
end
end
concommand.Add("testing", Test)
[/lua]
Edit: Moved to [url]http://facepunch.com/showthread.php?t=1227746[/url]
Warning, long post incoming. I've been trying to fix the dimensions addon from the gmod beta to work in a gamemode I'm making for gmod 13.
This addon/mod was made by Overv (as far as I know since that's what it says on the beta page) at some point that I'm assuming was a long time ago. I found it in the Garrysmod beta only mostly fixed and I wanted to integrate it into a gamemode I'm working on (derived from sandbox, so I have no problem using it in addon form).
The Dimensions addon is designed to separate gameplay into distinct "dimensions" or "rooms" where you can only see and interact with props, npcs, other players, etc in the same dimension as you.
The main problem I'm having is that ropes and tracer fire are still visible when you're in another dimension. The code is otherwise working and I haven't had to add anything to it except minor bug fixing. I'm just going to post the actual area of code I'm having trouble with because everything else is working fine. I'm not getting any error messages, it just isn't working as intended.
Original Code (for reference):
cl_dimensionscore.lua:
[lua]function Dimensions:SetEntityVisiblity( ent, dimension )
if ( ent:EntIndex() < 0 or !ent:IsValid() ) then return end
local visible = false
if ( ent:GetOwner():IsValid() ) then
visible = ent:GetOwner():GetDimension() == dimension
elseif ( ent:GetClass() == "class C_RopeKeyframe" ) then
visible = ent:GetNWEntity( "CEnt", ent ):GetDimension() == dimension
else
visible = ent:GetDimension() == dimension
end
if ( ent:GetClass() == "class C_RopeKeyframe" ) then
if ( visible ) then
ent:SetColor(Color(255, 255, 255, 255))
else
ent:SetColor(Color(255, 255, 255, 0))
end
else
ent:SetNoDraw( !visible )
if ( visible and !ent.DimensionVisibility ) then
ent:CreateShadow()
end
end
ent.DimensionVisibility = visible
end
function Dimensions.RenderEntities()
local localDimension = LocalPlayer():GetViewDimension()
for _, ent in ipairs( ents.GetAll() ) do
Dimensions:SetEntityVisiblity( ent, localDimension )
if ( ent.Dimension and ent.Dimension != ent:GetDimension() and ( ent.Dimension != localDimension and ent:GetDimension() == localDimension ) or ( ent.Dimension == localDimension and ent:GetDimension() != localDimension ) and !ent:GetOwner():IsValid() ) then
local ed = EffectData()
ed:SetEntity( ent )
util.Effect( "entity_remove", ed, true, true )
end
ent.Dimension = ent:GetDimension()
end
end
hook.Add( "RenderScene", "DimensionsEntityDrawing", Dimensions.RenderEntities )[/lua]
My Version. trying to fix the error (doesn't seem to make any difference) I commented out a section that was another attempt (it still didn't work):
cl_dimensionscore.lua:
[lua]function Dimensions:SetEntityVisiblity( ent, dimension )
if ( ent:EntIndex() < 0 or !ent:IsValid() ) then return end
local visible = false
local localDimension = LocalPlayer():GetViewDimension()
--if ( ent:GetOwner():IsValid() ) then
-- visible = ent:GetOwner():GetDimension() == dimension
--elseif ( ent:GetClass() == "C_RopeKeyframe" ) then
-- if ent:GetNWEntity( "CEnt", ent ):GetDimension() == localDimension then
-- visible = true
-- else
-- visible = false
-- end
-- print(visible)
-- print(ent:GetNWEntity( "CEnt", ent ):GetDimension())
--else
-- visible = ent:GetDimension() == dimension
--end
if ( ent:GetOwner():IsValid() ) then
if ent:GetOwner() == LocalPlayer() then
if ent:GetDimension() == localDimension then
visible = true
end
end
elseif ( ent:GetClass() == "class C_RopeKeyframe" ) then
if ent:GetNWEntity( "CEnt", ent ):GetDimension() == localDimension then
visible = true
print(visible)
end
else
if ent:GetDimension() == localDimension then
visible = true
else
visible = false
end
end
if ( ent:GetClass() == "C_RopeKeyframe" ) then
if ( visible ) then
ent:SetColor(255, 255, 255, 255)
else
ent:SetColor(255,255,255,0)
ent:SetRenderMode(RENDERMODE_TRANSALPHA)
end
else
ent:SetNoDraw( !visible )
if ( visible and !ent.DimensionVisibility ) then
ent:CreateShadow()
end
end
ent.DimensionVisibility = visible
end
function Dimensions.RenderEntities()
local localDimension = LocalPlayer():GetViewDimension()
for _, ent in ipairs( ents.GetAll() ) do
Dimensions:SetEntityVisiblity( ent, localDimension )
if ( ent.Dimension and ent.Dimension != ent:GetDimension() and ( ent.Dimension != localDimension and ent:GetDimension() == localDimension ) or ( ent.Dimension == localDimension and ent:GetDimension() != localDimension ) and !ent:GetOwner():IsValid() ) then
local ed = EffectData()
ed:SetEntity( ent )
util.Effect( "entity_remove", ed, true, true )
end
ent.Dimension = ent:GetDimension()
end
end
hook.Add( "RenderScene", "DimensionsEntityDrawing", Dimensions.RenderEntities )[/lua]
If there isn't anything obvious there then here's the full code. This includes the serverside stuff for the Networked Entity, which I checked and seems to be working.
original code (I just added "_R = debug.getregistry()"):
cl_dimensionscore.lua
[lua]--[[------------------------------------------------------------------------------------------------------------------
Clientside dimensions core
------------------------------------------------------------------------------------------------------------------]]--
Dimensions = {}
--for debugging purposes -Zyler
_R = debug.getregistry()
--[[------------------------------------------------------------------------------------------------------------------
Get dimension function
------------------------------------------------------------------------------------------------------------------]]--
function _R.Entity:GetDimension()
if ( !self:IsValid() ) then return 1 end
local val = self:GetDTInt( 3 )
if ( val == 0 and self != LocalPlayer() ) then val = LocalPlayer():GetDimension() end
return val
end
function _R.Entity:GetViewDimension()
local val = self:GetDTInt( 2 )
if ( val == 0 ) then val = LocalPlayer():GetDimension() end
return val
end
--[[------------------------------------------------------------------------------------------------------------------
Collision prediction
------------------------------------------------------------------------------------------------------------------]]--
function Dimensions.ShouldCollide( ent1, ent2 )
if ( ent1:GetDimension() != ent2:GetDimension() && !ent1:IsWorld() && !ent2:IsWorld() ) then
return false
end
end
hook.Add( "ShouldCollide", "DimensionsCollisionHandling", Dimensions.ShouldCollide )
--[[------------------------------------------------------------------------------------------------------------------
Trace modification
------------------------------------------------------------------------------------------------------------------]]--
Dimensions.OriginalTraceLine = util.TraceLine
function util.TraceLine( td, dimension )
if ( !dimension ) then dimension = LocalPlayer():GetDimension() end
local originalResult = Dimensions.OriginalTraceLine( td )
if ( !originalResult.Entity:IsValid() or originalResult.Entity:GetDimension() == dimension ) then
return originalResult
else
if ( td.filter ) then
if ( type( td.filter ) == "table" ) then
[QUOTE=NintendoEKS;38546437]Specific error; "attempt to call field 'GetAll' (a nil value)"
[lua]
function Test()
for k,v in pairs(ents.GetAll()) do
print(v:GetClass())
end
end
concommand.Add("testing", Test)
[/lua][/QUOTE]
Something might be writing over the 'ents' library. Try [lua]PrintTable( ents )[/lua] Maybe it will provide some clues.
Sorry, you need to Log In to post a reply to this thread.