[QUOTE=Spamppa2;52402638]can someone point out right direction how i could make entities spawn on cordinates on server start[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/InitPostEntity]GM:InitPostEntity[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ents/Create]ents.Create[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetPos]Entity:SetPos[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/Spawn]Entity:Spawn[/url]
[editline]26th June 2017[/editline]
[QUOTE=YoutoYokodera;52402640]How do i make the player spawn with sandbox chosen model? (my gamemode base is sandbox)
Where is that event hooked to cuz i may have overrided the PlayerIntinialSpawn and PlayerSpawn[/QUOTE]
[url]https://github.com/Facepunch/garrysmod/blob/784cd57576d85712fa13a7cea3a9523b4df966b0/garrysmod/gamemodes/base/gamemode/player_class/player_default.lua#L67-L68[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerSetModel]GM:PlayerSetModel[/url]
[quote]
[url]https://github.com/Facepunch/garrysmod/blob/784cd57576d85712fa13a7cea3a9523b4df966b0/garrysmod/gamemodes/base/gamemode/player_class/player_default.lua#L67-L68[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerSetModel]GM:PlayerSetModel[/url][/QUOTE]
What exactly i have to do in that hook to achive it?
[QUOTE=YoutoYokodera;52402968]What exactly i have to do in that hook to achive it?[/QUOTE]
Set the model and return true/non-nil.
This is for a custom weapon for Zombie survival, For the medic gun, you can heal and speed up your teammates when you shoot them with a dart, does anyone out there have an idea of what part of code causes the player to speedup?
edit : I ended up finding out what it was,
[CODE]function ENT:Move(pl, move)
if pl ~= self:GetOwner() then return end
move:SetMaxSpeed(move:GetMaxSpeed() + 50)
move:SetMaxClientSpeed(move:GetMaxSpeed())
end
[/CODE]
any idea on how to implement this into SWEP.BulletCallback?
Hey. I'm making an ESP type thing for a certain job in a server, but I can't figure out how to get it to check the user that is using the script's team. It is run on client side, because it's using Halos. Please tell me how to check the user's team, preferably in a lag-free way. This is what I've got so far;
[lua]
hook.Add( "PreDrawHalos", "AddHalos", function()
local vorts = {}
for k, v in pairs( player.GetAll() ) do
if v:Team() == TEAM_VORT then
table.insert( vorts, v )
end
end
halo.Add( vorts, Color( 0, 255, 0 ), 1, 1, 2, true, true )
end )
[/lua]
Many thanks!
Anyone any idea what could cause this weird shadow bug to appear?
[url]https://i.gyazo.com/231914c83f51a3bcb0a2bf93ba3ccd56.png[/url]
Any function or hook that could cause this?
Thanks.
[editline]26th June 2017[/editline]
[QUOTE=Shadow02;52403217]Hey. I'm making an ESP type thing for a certain job in a server, but I can't figure out how to get it to check the user that is using the script's team. It is run on client side, because it's using Halos. Please tell me how to check the user's team, preferably in a lag-free way. This is what I've got so far;
[lua]
hook.Add( "PreDrawHalos", "AddHalos", function()
local vorts = {}
for k, v in pairs( player.GetAll() ) do
if v:Team() == TEAM_VORT then
table.insert( vorts, v )
end
end
halo.Add( vorts, Color( 0, 255, 0 ), 1, 1, 2, true, true )
end )
[/lua]
Many thanks![/QUOTE]
I don't think you can use PreDrawHalos, use HUDPaint.
To get the players in a specific team you can use
[code]
local vorts = team.GetPlayers(TEAM_VORT)
[/code]
I'm messing around with creating a custom entity but when set to some models such as "models/props_junk/Wheebarrow01a.mdl", it spawns half way in the ground. Anyone know a fix? Thanks!
-snip-
Problem was right in my face, no mre help needed, ty code_gs :)
[QUOTE=Hackcraft;52403635]I'm messing around with creating a custom entity but when set to some models such as "models/props_junk/Wheebarrow01a.mdl", it spawns half way in the ground. Anyone know a fix? Thanks![/QUOTE]
Use [url]http://wiki.garrysmod.com/page/ENTITY/SpawnFunction[/url] and set its position a bit higher.
[QUOTE=Benn20002;52403397]Anyone any idea what could cause this weird shadow bug to appear?
[url]https://i.gyazo.com/231914c83f51a3bcb0a2bf93ba3ccd56.png[/url]
Any function or hook that could cause this?
Thanks.
[editline]26th June 2017[/editline]
I don't think you can use PreDrawHalos, use HUDPaint.
To get the players in a specific team you can use
[code]
local vorts = team.GetPlayers(TEAM_VORT)
[/code][/QUOTE]
PreDrawHalos is working fine for me. That line of code didn't work. I've tried using everything I know, but it just doesn't like it. I should probably find a way to use LocalPlayer() but I haven't figured it out yet.
Do you want the job to have ESP for all players? So he can see everyone?
Then use
[code]
if LocalPlayer():Team() != TEAM_VORT then return end
halo.Add(player.GetAll(), Color( 0, 255, 0 ), 1, 1, 2, true, true )
[/code]
I'm trying to pick a random player on the server and change them to another team, this is the code I've written but it's not working:
[CODE]local randomply = table.Random(player.GetAll())
function teams(ply, text, team)
if text == "!startround" then
for k , v in pairs(randomply) do
if v == table.Random(randomply) then
v:SetTeam( 3 )
v:SetWalkSpeed( 300 )
v:SetRunSpeed( 350 )
v:SetHealth(100)
v:Give( "weapon_crowbar" )
end
end
end
end
hook.Add("PlayerSay", "test", teams)[/CODE]
I've spent ages trying to figure out how to do it but nothing works, any help would be appreciated.
[QUOTE=asgloki;52403950]I'm trying to pick a random player on the server and change them to another team, this is the code I've written but it's not working:
[CODE]local randomply = table.Random(player.GetAll())
function teams(ply, text, team)
if text == "!startround" then
for k , v in pairs(randomply) do
if v == table.Random(randomply) then
v:SetTeam( 3 )
v:SetWalkSpeed( 300 )
v:SetRunSpeed( 350 )
v:SetHealth(100)
v:Give( "weapon_crowbar" )
end
end
end
end
hook.Add("PlayerSay", "test", teams)[/CODE]
I've spent ages trying to figure out how to do it but nothing works, any help would be appreciated.[/QUOTE]
Just use v = table.Random(player.GetAll()) after your first if-statement, remove the other if-statement and the loop.
[QUOTE=Benn20002;52403976]Just use v = table.Random(player.GetAll()) after your first if-statement and remove the other if statement and the loop.[/QUOTE]
Side note: Don't use table.Random on sequential tables.Use [B]math.Random([url=http://wiki.garrysmod.com/page/player/GetCount]player.GetCount()[/url])[/B] instead
[QUOTE=Benn20002;52403976]Just use v = table.Random(player.GetAll()) after your first if-statement, remove the other if-statement and the loop.[/QUOTE]
Oh damn, yeah that makes much more sense. I'll try it out, thanks.
There's no need to loop through all players, and storing the table outside of the function doesn't allow it to update. Also, using table.Random for sequential tables is more inefficient than using math.random to select a numerical element since it loops internally. Lastly, use enums for your SetTeam and local/implicit functions where applicable. Ex.
[Code]hook.Add ("PlayerSay", "test", function(_, sText)
if (sText:lower() == "!startround") then
local iCount = player.GetCount()
-- Could have been console that said it to an empty server, make sure there is a player
if (iCount ~= 0) then
local pRandomPlayer = player.GetAll()[1, iCount]
pRandomPlayer:SetTeam(TEAM_BLAH)
-- etc.
end
end
end)[/code]
[editline]26th June 2017[/editline]
Ultra ninja'd, typing code from a phone is slow :p
How can I make a DFrame slide in from the top?
I have tried the below but nothing happens
[LUA]
invf.frame:SetPos((ScrW()/2)-(invf.frame:GetWide()/2), -55)
invf.frame:MoveTo((ScrW()/2)-(invf.frame:GetWide()/2), 0, 0.1, 0, 0.75)
[/LUA]
Do I need to use AddCSLuaFile on clientside files in lua/autorun/client? Every tutorial I've ever read says you need to use AddCSLuaFile on files for them to work on servers, but I can't tell if it's needed for autorun files
[QUOTE=MPan1;52404808]Do I need to use AddCSLuaFile on clientside files in lua/autorun/client? Every tutorial I've ever read says you need to use AddCSLuaFile on files for them to work on servers, but I can't tell if it's needed for autorun files[/QUOTE]
No
Hey, I need to force someone to move like they're holding +walk without them actually holding that. How would I go about that?
[QUOTE=a1steaksa;52404850]Hey, I need to force someone to move like they're holding +walk without them actually holding that. How would I go about that?[/QUOTE]
Add IN_MOVEFORWARD to the CUserCMD keys in CreateMove or StartCommand
[QUOTE=code_gs;52404989]Add IN_MOVEFORWARD to the CUserCMD keys in CreateMove or StartCommand[/QUOTE]
This works, but whenever I try it it's very stuttery
[QUOTE=a1steaksa;52405082]This works, but whenever I try it it's very stuttery[/QUOTE]
Can you post your code?
[QUOTE=code_gs;52405083]Can you post your code?[/QUOTE]
Sure. I've swapped walk for duck as it's more visually apparent. I don't get any change from using IN_WALK, I suspect because it's toggling on and off fast enough to not make a significant difference.
Also to be clear, I get the same issue with SetupMove, Move, etc.
[code]
hook.Add( "SetupMove", "BrokenLegsMove", function( ply, dat )
if ( not ply or not IsValid( ply ) or not dat ) then return end
if ( ply.brokenLegs and ply:Alive() ) then
//dat:AddKey( IN_WALK )
dat:AddKey( IN_DUCK )
return true
end
end )
[/code]
[QUOTE=code_gs;52403073]Set the model and return true/non-nil.[/QUOTE]
No i mean i dont want a specific model, i want to set the model to the one they choose in sandbox model selection
[QUOTE=YoutoYokodera;52405288]No i mean i dont want a specific model, i want to set the model to the one they choose in sandbox model selection[/QUOTE]
Yes, and I linked you on how to do that.
[editline]26th June 2017[/editline]
[QUOTE=a1steaksa;52405113]Sure. I've swapped walk for duck as it's more visually apparent. I don't get any change from using IN_WALK, I suspect because it's toggling on and off fast enough to not make a significant difference.
Also to be clear, I get the same issue with SetupMove, Move, etc.
[code]
hook.Add( "SetupMove", "BrokenLegsMove", function( ply, dat )
if ( not ply or not IsValid( ply ) or not dat ) then return end
if ( ply.brokenLegs and ply:Alive() ) then
//dat:AddKey( IN_WALK )
dat:AddKey( IN_DUCK )
return true
end
end )
[/code][/QUOTE]
Use CreateMove clientside. SetupMove and Move are too late. Also, there's no need to check the validity of the player and if the usercmd exists: those are guaranteed.
[CODE]hook.Add("TTTEndRound", "killstreak_ResetOnEnd", function()
local pls = player.GetAll();
for i = 1, #pls do
local pl = pls[i];
// Reset kill streak here
// pl:SetKillStreak(0); -- Example
end
end)
[/CODE]
This seems to keep the killstreak variable at 0, but when I remove it the code works just fine.
[CODE]hook.Add("OnKillStreakChange", "player_KillStreakChange", function(pl, newNum)
print("Player: "..pl:Nick())
print("Killstreak: "..newNum)
end)
local _R = debug.getregistry()
local PLAYER = _R.Player
function PLAYER:GetKillStreak() // Use this function to see how many kills a user currently killstreak is.
return (CLIENT && self:GetNWInt("kill_streak", 0)) || (self.kill_streak||0) || 0
end
if(SERVER)then
function PLAYER:SetKillStreak(num)
self.kill_streak = num
self:SetNWInt("kill_streak", num) // This is for clientside stuff.
hook.Call("OnKillStreakChange", nil, self, num)
end
end
hook.Add("PlayerDeath", "kill_streak_counter", function(victim, _, attacker)
victim:SetKillStreak(0) // Reset the person who died kill streak to 0.
if(victim != attacker && attacker:IsValid() && attacker:IsPlayer())then // Wasn't suicide
attacker:SetKillStreak(attacker:GetKillStreak() + 1)
end
if(victim:IsTraitor() == attacker:IsTraitor()) then
attacker:SetKillStreak(0)
end
end)
hook.Add("TTTEndRound", "killstreak_ResetOnEnd", function()
local pls = player.GetAll();
for i = 1, #pls do
local pl = pls[i];
pl:SetKillStreak(0)
end
end)
util.AddNetworkString("GetKillStreak")
hook.Add("OnKillStreakChange", "player_KillStreakChange", function(pl, newNum)
net.Start("GetKillStreak")
net.WriteInt(newNum, 32)
net.Send(pl)
end)
[/CODE]
[QUOTE=a1steaksa;52405113]Sure. I've swapped walk for duck as it's more visually apparent. I don't get any change from using IN_WALK, I suspect because it's toggling on and off fast enough to not make a significant difference.
Also to be clear, I get the same issue with SetupMove, Move, etc.
[code]
hook.Add( "SetupMove", "BrokenLegsMove", function( ply, dat )
if ( not ply or not IsValid( ply ) or not dat ) then return end
if ( ply.brokenLegs and ply:Alive() ) then
//dat:AddKey( IN_WALK )
dat:AddKey( IN_DUCK )
return true
end
end )
[/code][/QUOTE]
Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/StartCommand]GM:StartCommand[/url] shared (not sure why gs said CreateMove clientside), [b]and don't return anything.[/b] It's very important that you get the same result clientside and serverside.
[QUOTE=Moat;52404365]override think on your dframe
[lua]DFrame.Think = nil -- or function() end[/lua][/QUOTE]
Thanks that worked great, but any idea why because to me that seems pointless
[editline]27th June 2017[/editline]
Ah nvm worked it out
[URL="https://github.com/Facepunch/garrysmod/blob/master/garrysmod/lua/vgui/dframe.lua"]https://github.com/Facepunch/garrysmod/blob/master/garrysmod/lua/vgui/dframe.lua[/URL]
[LUA]
-- Don't allow the frame to go higher than 0
if ( self.y < 0 ) then
self:SetPos( self.x, 0 )
end
[/LUA]
[QUOTE=NeatNit;52405774]Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/StartCommand]GM:StartCommand[/url] shared (not sure why gs said CreateMove clientside), [b]and don't return anything.[/b] It's very important that you get the same result clientside and serverside.[/QUOTE]
Because CreateMove is before the server ever sees the keys, hence the server will never know the difference between a player actually holding down forward or not. StartCommand should be used for things that need to be predicted in both realms and you don't want to trust the client.
Sorry, you need to Log In to post a reply to this thread.