[QUOTE=Predda;52374571]Sure, but isn't only one file, I try to explain what I'm trying to do.
I created a meta function "IsSick()", it perfectly works in the server-side, I would like to make this function works also in the client-side, so I put this in a file named shared.lua in lua/autorun:
[CODE]
local meta = FindMetaTable( "Player" )
function meta:IsSick()
return self:GetNWBool( "PlayerIsSick" )
end
[/CODE]
Client-Side:
[CODE]
AddCSLuaFile( "shared.lua" )
net.Receive( "isSick", function( len, pl )
alert()
end)
local ply = LocalPlayer()
function alert()
timer.Create("unique_name", 5, 0, function()
if ply:IsSick() then print("You are sick") end
end)
end
[/CODE]
If I start the net message "isSick", in the console I can read:
[ERROR] addons/sick/lua/autorun/client/alert.lua:8: attempt to call method 'IsSick' (a nil value)
1. unknown - addons/sick/lua/autorun/client/alert.lua:8[/QUOTE]
The REAL issue is that you're using LocalPlayer before it's created. Instead, do it inside InitPostEntity. Your timer essentially gets the same result.
[QUOTE=Predda;52374589]
I fixed it putting a simple 10 seconds timer in the client-side file:
:snip:
Thank you for your help![/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/LocalPlayer]LocalPlayer[/url] returns NULL until [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/InitPostEntity]GM:InitPostEntity[/url]. Just don't store it in a local variable and it'll be fine.
Edit: Ninja'd
Hey guys is there a way to print numbers with their sign?
For example if I do this:
[CODE]
x = 170
print(x)
Output:
+170
[/CODE]
[QUOTE=Pwned231;52374773]Hey guys is there a way to print numbers with their sign?
For example if I do this:
[CODE]
x = 170
print(x)
Output:
+170
[/CODE][/QUOTE]
[code]
print(string.format("%+g", 2.1241)) -- +2.1241
[/code]
[QUOTE=bigdogmat;52374657][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/LocalPlayer]LocalPlayer[/url] returns NULL until [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/InitPostEntity]GM:InitPostEntity[/url]. Just don't store it in a local variable and it'll be fine.
Edit: Ninja'd[/QUOTE]
You explained it better than me though, and with fewer words.
So what's the best way to make a walljump/wallride script? I'm thinking of the obvious calling util.tracehull during a WASD keypress but I'm wondering if there are any special movement hooks that control things like the gravity of the player or the player's next intended position.
I'm currently trying to spawn airboats with:
[CODE] local boat = ents.Create("prop_vehicle_airboat")
boat:SetModel("models/airboat.mdl")
boat:SetKeyValue("vehiclescript","scripts/vehicles/airboat.txt")
boat:SetPos(v)
boat:Spawn()[/CODE]
It spawns, however whenever I go up to the boat to get in it instantly crashes my game/server.
I'm using Cam3D2D to had a HUD to my entity.
Is there a way I can CENTER the WordBoxes to the entity so it's aligned no matter the text's length.
Edit: Also how can i get the owner's name of the enttiy to display in the HUD too.
Edit 2: How can I draw HUD to the player's screen after they used my entity. I have the entity functional, and it can be used. How do I call for HUD to be drawn to their screen, and make the HUD drawn from the addon clear too.
(I don't want the HUD permanently on their screen, just after they use my entity for 30s then it disappears)
[QUOTE=Slimy10;52381683]I'm using Cam3D2D to had a HUD to my entity.
Is there a way I can CENTER the WordBoxes to the entity so it's aligned no matter the text's length.[/quote]Yeah. Start the 3D2D where you want the center to be, and then draw the text centered at (0, 0).
[QUOTE=Slimy10;52381683]Edit: Also how can i get the owner's name of the enttiy to display in the HUD too.[/quote]Depends on the addon you use to define the owner.
[QUOTE=Slimy10;52381683]Edit 2: How can I draw HUD to the player's screen after they used my entity. I have the entity functional, and it can be used. How do I call for HUD to be drawn to their screen, and make the HUD drawn from the addon clear too.
(I don't want the HUD permanently on their screen, just after they use my entity for 30s then it disappears)[/QUOTE]
There's a few ways:
1. [url=http://wiki.garrysmod.com/page/hook/Add]hook.Add[/url] to [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/HUDPaint]GM:HUDPaint[/url], then after 30 seconds use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/hook/Remove]hook.Remove[/url] to remove it.
2. Create a panel for it that shows up on the HUD, then use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Panel/Remove]Panel:Remove[/url] after 30 seconds to remove it.
-snip nevermind-
[QUOTE=ROFLBURGER;52380241]So what's the best way to make a walljump/wallride script? I'm thinking of the obvious calling util.tracehull during a WASD keypress but I'm wondering if there are any special movement hooks that control things like the gravity of the player or the player's next intended position.[/QUOTE]
Wallrunning I can't help with. I can help with wall kicking though. Pull my GMA apart here: [url]http://steamcommunity.com/sharedfiles/filedetails/?id=698196774[/url]
As I recall it's somewhat commented
The important part, really, is the localize the player's velocity to them so that you can negate all of their sideways velocity when they kick off. It took me forever to think of doing that and I felt stupid after not getting it for so long
[QUOTE=a1steaksa;52382345]Wallrunning I can't help with. I can help with wall kicking though. Pull my GMA apart here: [url]http://steamcommunity.com/sharedfiles/filedetails/?id=698196774[/url]
As I recall it's somewhat commented
The important part, really, is the localize the player's velocity to them so that you can negate all of their sideways velocity when they kick off. It took me forever to think of doing that and I felt stupid after not getting it for so long[/QUOTE]
Oh I already figured out most of the things, Including wallrunning using SetupMove.
I just needed to know how to control the gravity, and modifying the player's velocity properly helped with negativing gravity.
Is it possible to disable HDR/bloom on a 3D2D element? I'm drawing inside of ENT:Draw(), and on darker maps....
[t]http://zombine.me/ss/hl2_2017-06-20_16-13-14.jpg[/t]
I can solve it by adding a HUDPaint hook for the entity when it first spawns and do the rendering there, but then it draws on top of my weapons, and I don't like adding a new hook for each entity.
[QUOTE=Z0mb1n3;52383339]Is it possible to disable HDR/bloom on a 3D2D element? I'm drawing inside of ENT:Draw(), and on darker maps....
[t]http://zombine.me/ss/hl2_2017-06-20_16-13-14.jpg[/t]
I can solve it by adding a HUDPaint hook for the entity when it first spawns and do the rendering there, but then it draws on top of my weapons, and I don't like adding a new hook for each entity.[/QUOTE]
I'm sure the bloom would still be on the same 'plane' as the tv though. Unless you want to distort it with math
[QUOTE=Kevlon;52383408]I'm sure the bloom would still be on the same 'plane' as the tv though. Unless you want to distort it with math[/QUOTE]
I've tried other hooks like Pre/PostDrawEffects, PostDrawTranslucentRenderables, etc, they all factor bloom into the 3d2d rendering, and I've got no idea what to do about it except change the color of the screen to something darker if they're far away, but that's ugly and I have quite a few elements I'd need to change the colors of.
Any idea of detecting player with ents.FindInSphere every tick without keep looping through the table of result? Cuz i think it would kill the performance
[QUOTE=YoutoYokodera;52384480]Any idea of detecting player with ents.FindInSphere every tick without keep looping through the table of result? Cuz i think it would kill the performance[/QUOTE]
How would you plan on checking if something is in a list of entities without going through that list and seeing if it exists?
nvm found a way better way
i'll just gonna calc the distance from every player to the entity then if the distance is in the allowed zone then run something
I made a small script that shows the players frag count on screen, problem is that it won't update wehn new kills are added and removed, I can't figure out why.
[CODE]
local frags = LocalPlayer(1):Frags()
surface.CreateFont("totalfragsfont", {
font = "DermaDefault",
size = 45,
antialias = true,
outline = true,
})
hook.Add("HUDPaint", "totalfrags", function()
surface.SetFont("totalfragsfont")
surface.SetTextColor(255,255,255,255)
surface.SetTextPos(128,128)
surface.DrawText(frags)
print(LocalPlayer(1):Frags())
end)[/CODE]
Hello, is there any way I can capture the focus of the keyboard so people can type in something other than a DTextEntry? I'm rendering 3D2D, and I can use the vgui libraries, however more preferably I want to draw text on a surface.Rect.
Edit - I'm going to rephrase this a bit, is there a way you can get rid of everything other than the text in a DTextEntry? Or somehow get a keyboard's focus then be able to print on a editablepanel or surface.drawrect? I want something plain, like command prompt
[QUOTE=Meninist;52384540]I made a small script that shows the players frag count on screen, problem is that it won't update wehn new kills are added and removed, I can't figure out why.
[CODE]
local frags = LocalPlayer(1):Frags()
surface.CreateFont("totalfragsfont", {
font = "DermaDefault",
size = 45,
antialias = true,
outline = true,
})
hook.Add("HUDPaint", "totalfrags", function()
surface.SetFont("totalfragsfont")
surface.SetTextColor(255,255,255,255)
surface.SetTextPos(128,128)
surface.DrawText(frags)
print(LocalPlayer(1):Frags())
end)[/CODE][/QUOTE]
because you're not updating the variable "frags". you're calling it once on file load, so it's not gonna change. put it in the HUDPaint hook (if you want it to update every frame).
I am trying to create two collision bounds on a single entity, is there any solution for this? My first thought is to parent a dummy entity to the original one. Would this be my most practical solution? Any ideas?
This entity already has a custom collision area, I need a second one where the black lines are.
[thumb]https://preview.ibb.co/c3VAhk/phys.png[/thumb]
Hey so I'm trying to this particle effect from rebel1324's mounted gun addon to work on sweps. It runs without errors but the FixedParticle method doesn't seem to be creating any particles. Anyone know why?
[code]
function EFFECT:FixedParticle()
local function maxLife(min, max)
return math.Rand(math.min(min, self.lifeTime), math.min(max or self.lifeTime, self.lifeTime))
end
local p = self.emitter:Add("particle/smokesprites_000"..math.random(1,9), Vector(0, 0, 0))
p:SetVelocity(150*Vector(1, 0, 0))
p:SetDieTime(maxLife(.1, .2))
p:SetStartAlpha(math.Rand(115,215))
p:SetEndAlpha(0)
p:SetStartSize(math.random(10,20)*self.scale)
p:SetEndSize(math.random(22,44)*self.scale)
p:SetRoll(math.Rand(180,480))
p:SetRollDelta(math.Rand(-3,3))
p:SetColor(150,150,150)
p:SetGravity( Vector( 0, 0, 100 )*math.Rand( .2, 1 ) )
local max = 8
for i = 1, max do
local p = self.emitter:Add("effects/muzzleflash" .. math.random(1, 4), Vector(i*3 + i, 0, 0))
p:SetVelocity(math.Rand(120, 150)*Vector(1, 0, 0)*(self.scale*1.5))
p:SetDieTime(maxLife(.05, .07))
p:SetStartAlpha(255)
p:SetEndAlpha(150)
p:SetStartSize(math.random(6,8)*self.scale*(max - i)/2)
p:SetEndSize(math.random(6,8)*self.scale*(max - i)/1.2)
p:SetRoll(math.Rand(180,480))
p:SetRollDelta(math.Rand(-3,3))
p:SetColor(255,255,255)
end
end
function EFFECT:FreeParticle()
local p = self.freeEmitter:Add("particle/smokesprites_000"..math.random(1,9), self.origin)
local dir = self.dir
for i = 1, 11 do
p:SetVelocity(20*dir*(self.scale*2)*i*1.2)
p:SetDieTime(math.Rand(.4, .5))
p:SetStartAlpha(math.Rand(55,75))
p:SetEndAlpha(0)
p:SetStartSize(math.Rand(11,15)*self.scale)
p:SetEndSize(math.Rand(4,5)*self.scale*i*1.2)
p:SetRoll(math.Rand(180,480))
p:SetRollDelta(math.Rand(-2,2))
p:SetColor(150,150,150)
p:SetGravity( Vector( 0, 0, 100 )*math.Rand( .2, 1 ) )
p:SetAirResistance(150)
end
end
function EFFECT:Init(data)
self.ent = data:GetEntity()
--self.scale = data:GetScale()
self.scale = math.Rand(.3, 1)
self.origin = data:GetOrigin()
self.dir = data:GetNormal()
self.lifeTime = .2
self.decayTime = CurTime() + self.lifeTime
self.emitter = ParticleEmitter(Vector(0, 0, 0))
self.freeEmitter = ParticleEmitter(Vector(0, 0, 0))
local hvec = Vector(65536, 65536, 65536)
self:SetRenderBounds(-hvec, hvec)
self.fired = false
self.emitter:SetNoDraw(true)
self:FixedParticle()
self:FreeParticle()
end
function EFFECT:Render()
return false
end
function EFFECT:Think()
if (self.decayTime < CurTime()) then
-- garbage collecting process
self:Remove()
return false
end
return true
end
[/code]
Sorry for pasting so much code. I don't know a more concise way of asking for help on something like this.
[QUOTE=8bitMafia;52384566]Hello, is there any way I can capture the focus of the keyboard so people can type in something other than a DTextEntry? I'm rendering 3D2D, and I can use the vgui libraries, however more preferably I want to draw text on a surface.Rect.
Edit - I'm going to rephrase this a bit, is there a way you can get rid of everything other than the text in a DTextEntry? Or somehow get a keyboard's focus then be able to print on a editablepanel or surface.drawrect? I want something plain, like command prompt[/QUOTE]
I'm not sure what you can and can't do with a DTextEntry, and I do think your best bet is to figure out how use that. However, I'll answer your first question regardless - key trapping in the input library. It basically lets you say "the next key that gets pressed, regardless of what it is, I want to know about it". And it's a bit shitty to use, I'll edit this post with an example in a moment.
[editline]21st June 2017[/editline]
[url]https://github.com/Facepunch/garrysmod/blob/master/garrysmod/lua/vgui/dbinder.lua[/url]
Ctrl+F for 'trap' to see how it's used.
I am trying to lock the players "body_yaw" pose to make use of the dive animation. This way when the player is not sliding around, they can aim in all directions while their body is sitting in one position, the same way it's done in Double Action Boogalo. I have wOS animation extensions installed.
[CODE]--lua/autorun/test.lua
hook.Add("UpdateAnimation", "customupdate", function(ply, velocity, maxSeqGroundSpeed)
if CLIENT then
ply:SetPoseParameter( "body_yaw", 90 * math.sin(FrameTime() * 0.5) )
ply:InvalidateBoneCache()
end
end)
hook.Add("CalcMainActivity", "customplyanim", function(ply, velocity)
return -1, ply:LookupSequence("dive")
end)[/CODE]
I set the body_yaw param to different values, -90 to 90 in this case but nothing seems to change it for players.[QUOTE][video=youtube;AgW9qqSeHs8]https://www.youtube.com/watch?v=AgW9qqSeHs8[/video][/QUOTE]
I'm glad these threads still exist. I'm just curious how much control I can have over Vanilla NPC's with Lua. I'm thinking about making a stealth system somehow like something outta hitman, or other stealth games... even Fallout 4 has a stealth system [sp]Although not a good one[/sp]
I think for this I have to somehow make the player invisible to NPC's, and use Lua to check if they actually can see a player. Can this be done just by using friend/neutral/enemy relationships? I feel like that would be buggy, especially since they'll still see the player.
So... is there a way to make the player literally invisible to an NPC without disabling ai?
[b]edit[/b]
Or for that matter, how could I make a weapon that NPC's can't hear?
I'm currently trying to create a weapon selection menu, however I've ran into a few issues.
I currently use the weapon base Customizable Weaponry 2.0 and as you know you can select attachments via context menu. I want weapons to change on 1,2,3,4, etc however I don't want the change to occur when I have any additional gui on my screen open, exactly like the original weapon switcher. If anyone can give me a direct link to the weapon switcher gmod uses that might be more helpful than anything. Thanks!
[QUOTE=dannyf127;52389082]I'm currently trying to create a weapon selection menu, however I've ran into a few issues.
I currently use the weapon base Customizable Weaponry 2.0 and as you know you can select attachments via context menu. I want weapons to change on 1,2,3,4, etc however I don't want the change to occur when I have any additional gui on my screen open, exactly like the original weapon switcher. If anyone can give me a direct link to the weapon switcher gmod uses that might be more helpful than anything. Thanks![/QUOTE]
The original weapon switcher is in C++. You can modify this skeleton here to check if the context menu is open in the PlayerPressBind hook before displaying the menu: [url]https://github.com/Kefta/Weapon-Switcher-Skeleton[/url]
[QUOTE=code_gs;52389104]The original weapon switcher is in C++. You can modify this skeleton here to check if the context menu is open in the PlayerPressBind hook before displaying the menu: [url]https://github.com/Kefta/Weapon-Switcher-Skeleton[/url][/QUOTE]
Cheers, that helped a lot.
Any idea how i could find the closest entity of a certain type?
Sorry, you need to Log In to post a reply to this thread.