[QUOTE=MaximLaHaxim;48974894]you're probably calling LocalPlayer before InitPostEntity is called, make sure this stuff is called after[/QUOTE]
Ehhh, what?
[QUOTE=SimonDEV;48976759]Ehhh, what?[/QUOTE]
LocalPlayer returns null if the client didn't fully load yet. The client fully loads after the InitPostEntity hook has been called.
[QUOTE=LegoGuy;48976880]LocalPlayer returns null if the client didn't fully load yet. The client fully loads after the InitPostEntity hook has been called.[/QUOTE]
There is no InitPostEntity hook included in the code though.
[QUOTE=SimonDEV;48977297]There is no InitPostEntity hook included in the code though.[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/LocalPlayer]Global.LocalPlayer[/url]
[QUOTE]LocalPlayer() will return NULL until all entities have been initialized.[/QUOTE]
So im making scoreboard, and i like to show there country's flag. How would i accomplish that? I already know the country code.
[QUOTE=SteppuFIN;48977641]So im making scoreboard, and i like to show there country's flag. How would i accomplish that? I already know the country code.[/QUOTE]
[CODE]local mat = Material("flags16/" .. country_code .. ".png")[/CODE]
so, I've been trying to make a first person death-type thing
but, this isn't working
[code]function GM:CalcView( ply, pos, ang, fov, nearz, farz )
if !ply:Alive() and IsValid( ply:GetRagdollEntity() ) then
local position, angle = ply:GetRagdollEntity():GetBonePosition( ply:GetRagdollEntity():LookupBone("ValveBiped.Bip01_Head1" ) )
pos = position
ang = angle
end
return pos, ang, fov
end[/code]
what did I do wrong?
[QUOTE=krekeris;48977612][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/LocalPlayer]Global.LocalPlayer[/url][/QUOTE]
So what do I have to do then? I'm confused on this I'm relatively new to Lua.
[QUOTE=SimonDEV;48979588]So what do I have to do then? I'm confused on this I'm relatively new to Lua.[/QUOTE]
Add a sanity check to the start of your script.
[CODE]if !LocalPlayer() then return end[/CODE]
How can I make a system that requires "materials" for example I use the frying pan prop as a cooking source and then it would require a cabbage (for convenience sake) how can this be done? I heard networked strings can be used as part of a method for the ents
[QUOTE=DeathWard;48980008]Add a sanity check to the start of your script.
[CODE]if !LocalPlayer() then return end[/CODE][/QUOTE]
And his script will not load at all.
[QUOTE=SimonDEV;48979588]So what do I have to do then? I'm confused on this I'm relatively new to Lua.[/QUOTE]
You should define your variable with localplayer after all entities have been initialized. Like that:
[CODE]local client
hook.Add("InitPostEntity", "1234", function()
client = LocalPlayer()
end)[/CODE]
[QUOTE=krekeris;48980168]And his script will not load at all.[/QUOTE]
His function is hooked into RenderScreenspaceEffects which is called every frame.
[QUOTE=DeathWard;48980246]His function is hooked into RenderScreenspaceEffects which is called every frame.[/QUOTE]
You said that he should add useless check at the beginning of his script that will stop executing code below this check.
[QUOTE=krekeris;48980350]You said that he should add useless check at the beginning of his script that will stop executing code below this check.[/QUOTE]
Correct, but the code is executed every frame. Once LocalPlayer becomes valid, it'll run.
It's the same way with Think or HUDPaint hooks.
[QUOTE=DeathWard;48980403]Correct, but the code is executed every frame. Once LocalPlayer becomes valid, it'll run.
It's the same way with Think or HUDPaint hooks.[/QUOTE]
His whole script isn't executing every frame, only hook's function.
[QUOTE=krekeris;48980521]His whole script isn't executing every frame, only hook's function.[/QUOTE]
Alright then, let me clarify.
[CODE]local function DrawInternal2()
local overlay = "effects/combine_binocoverlay"
if !LocalPlayer() or LocalPlayer():Team() != TEAM_POLICE then return end
DrawMaterialOverlay2( overlay, 0.3 )
end
hook.Add( "RenderScreenspaceEffects", "RenderMaterialOverlay", DrawInternal2 )[/CODE]
There's no reason to create an extra hook in InitPostEntity. Doing it that way will still return the same lua errors while in the loading screen.
[QUOTE=DeathWard;48980679]Alright then, let me clarify.
[CODE]local function DrawInternal2()
local overlay = "effects/combine_binocoverlay"
if !LocalPlayer() or LocalPlayer():Team() != TEAM_POLICE then return end
DrawMaterialOverlay2( overlay, 0.3 )
end
hook.Add( "RenderScreenspaceEffects", "RenderMaterialOverlay", DrawInternal2 )[/CODE]
There's no reason to create an extra hook in InitPostEntity. Doing it that way will still return the same lua errors while in the loading screen.[/QUOTE]
You're wrong. As far as I know, this hook isn't calling while you're in the loading screen. His problem is variable "lp", because it was defined only once, while LocalPlayer() returns null.
Does anyone know what the UNDO button's enum is?
[QUOTE=solid_jake;48981700]Does anyone know what the UNDO button's enum is?[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerBindPress]GM/PlayerBindPress[/url] and look for "undo"
-snip-
1 BroadcastLua(surface.PlaySound("mysound.mp3"))
2 BroadcastLua([[surface.PlaySound("mysound.mp3")]])
3 BroadcastLua("surface.PlaySound(\"mysound.mp3\")")
This is a highly specialized situation so security/hackers are NOT a concern. (think local server).
1 plays the sound file but only on the client. 2 and 3 do not play at all but I was told either was a proper format.
I'm playing this from a clientside button (think - soundboard)...but I want all players to hear it. Both clients can play 1 but it doesn't broadcast it to the others...what am I missing here?
EDIT : Net library works but I have like 200 buttons here and a single line command would take less time to implement.
Is PLAYER:ShowProfile() working for anybody? I.e., try in a server with CS Lua enabled:
[code]lua_run_cl LocalPlayer():ShowProfile()[/code]
I swear it stopped working within the last few months and I haven't changed anything on my end. Even the AvatarImage's button in the [URL="https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/base/gamemode/cl_scoreboard.lua#L25"]default base scoreboard[/URL] doesn't appear to be working in singleplayer.
[QUOTE=Blakestr;48982597]1 BroadcastLua(surface.PlaySound("mysound.mp3"))
2 BroadcastLua([[surface.PlaySound("mysound.mp3")]])
3 BroadcastLua("surface.PlaySound(\"mysound.mp3\")")
This is a highly specialized situation so security/hackers are NOT a concern. (think local server).
1 plays the sound file but only on the client. 2 and 3 do not play at all but I was told either was a proper format.
I'm playing this from a clientside button (think - soundboard)...but I want all players to hear it. Both clients can play 1 but it doesn't broadcast it to the others...what am I missing here?
EDIT : Net library works but I have like 200 buttons here and a single line command would take less time to implement.[/QUOTE]
the reason 1 works because you're not passing a string, you're calling the function and passing it's return value (nothing)
don't be lazy when it comes to networking, yeah you can get away with doing it here but it doesn't take a lot of these to seriously slow down a server
all it takes is
[lua]--serverside
util.AddNetworkString("playMySound")
util.AddNetworkString("playMySoundResponse")
net.Receive("playMySound", function()
net.Start("playMySoundReponse")
net.Broadcast()
end)
--clientside
net.Receive("playMySoundResponse", function()
surface.PlaySound("mysound.mp3")
end)
--to play the sound
net.Start("playMySound")
net.SendToServer()
[/lua]
[QUOTE=Mista Tea;48982973]Is PLAYER:ShowProfile() working for anybody? I.e., try in a server with CS Lua enabled:
[code]lua_run_cl LocalPlayer():ShowProfile()[/code]
I swear it stopped working within the last few months and I haven't changed anything on my end. Even the AvatarImage's button in the [URL="https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/base/gamemode/cl_scoreboard.lua#L25"]default base scoreboard[/URL] doesn't appear to be working in singleplayer.[/QUOTE]
I think gui. OpenUrl doesnt work. Been experiencing same issues.
^ Works fine for me.
Also, I have a question:
I have an overwridden panel:Paint function on a panel that takes 1 away from a number until the number is 0, then once it is 0, it resets to 30 and keeps taking away 1. This is for a simple animation (actually for a battery charging animation using a surface.DrawRect with changing width), but I have a feeling the panel:Paint function might run faster on some systems compared to others.
What function should I be using if I want something (like taking away 1) to go at the same rate on all systems?
[QUOTE=SteppuFIN;48984197]I think gui. OpenUrl doesnt work. Been experiencing same issues.[/QUOTE]
Now that you mention it, nothing with gui.OpenURL appears to be working for me either.
[QUOTE=MPan1;48984401]^ Works fine for me.[/QUOTE]
So
[code]lua_run_cl LocalPlayer():ShowProfile()
lua_run_cl gui.OpenURL( "http://www.google.com" )
lua_run_cl gui.OpenURL( "https://steamcommunity.com/id/garry" ) [/code]
work for you no problem?
I'm using as close to vanilla GMod right now (disabled all workshop addons, no legacy addons, etc) and have tried singleplayer on both main and dev branches.
[QUOTE=MPan1;48984401]^ Works fine for me.
Also, I have a question:
I have an overwridden panel:Paint function on a panel that takes 1 away from a number until the number is 0, then once it is 0, it resets to 30 and keeps taking away 1. This is for a simple animation (actually for a battery charging animation using a surface.DrawRect with changing width), but I have a feeling the panel:Paint function might run faster on some systems compared to others.
What function should I be using if I want something (like taking away 1) to go at the same rate on all systems?[/QUOTE]
[code]
value = math.max( 0, value - RealFrameTime( ) / seconds_to_take )
if value == 0 then
value = max
end
[/code]
Something like that would be the simplest way.
How can I get a variable from a string?
i.e. Assume x is "19.38"
How would I get y & z to grab the 19 and 38 but not the . from the string respectively?
[QUOTE=Silhouhat;48985127]How can I get a variable from a string?
i.e. Assume x is "19.38"
How would I get y & z to grab the 19 and 38 but not the . from the string respectively?[/QUOTE]
string.Explode by "." sign, tonumber first string in the table to y, second to z.
OR
tonumber x,
y = math.floor( tonumbered_x )
z = tonumbered_x - math.floor( tonumbered_x )
Anyone knows how can i "balance" the heights on fft? It looks pretty useless when there are the first ones that only move...
Sorry, you need to Log In to post a reply to this thread.