You might need to run [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetNextClientThink]Entity:SetNextClientThink[/url] as well.
[QUOTE=code_gs;52409383]You might need to run [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetNextClientThink]Entity:SetNextClientThink[/url] as well.[/QUOTE]
Nvm i forgot to add if SERVER then cuz i put all of them in shared
My serverside code is giving me an error I don't understand. Any help is appreciated! :)
[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
-------------------------------------------------------------
--The function to use to see what the user's killstreak is.--
-------------------------------------------------------------
function PLAYER:GetKillStreak()
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
--------------------------------------------------------------------------------------------------------------------
--Resets players killstreak after they die. Checks if the player suicided. Checks if traitor kills another traitor--
--------------------------------------------------------------------------------------------------------------------
hook.Add("PlayerDeath", "kill_streak_counter", function(victim, _, attacker)
victim:SetKillStreak(0)
end
if(victim != attacker && attacker:IsValid() && attacker:IsPlayer())then
attacker:SetKillStreak(attacker:GetKillStreak() + 1)
end
if victim:IsTraitor() == attacker:IsTraitor() then
attacker:SetKillStreak(0)
util.AddNetworkString("KillstreakReset")
net.Start("KillStreakReset")
net.WriteBool(true)
end
end
------------------------------------------------------------------------------------------
hook.Add("TTTEndRound", "killstreak_ResetOnEnd", function(pl)
local pls = player.GetAll();
for i = 1, #pls do
local pl = pls[i];
pl:SetKillStreak(0)
end
end)
---------------------------------------------------------------------------------
--This is the net message sent to the user containing their current killstreak.--
---------------------------------------------------------------------------------
util.AddNetworkString("GetKillStreak")
hook.Add("OnKillStreakChange", "player_KillStreakChange", function(pl, newNum)
net.Start("GetKillStreak")
net.WriteInt(newNum, 32)
net.Send(pl)
end)
---------------------------------------------------------------------------------[/CODE]
[CODE][ERROR] addons/manlykillstreaks/lua/autorun/server/sv_manlykillstreaks.lua:31: ')' expected (to close '(' at line 27) near 'if'
1. unknown - addons/manlykillstreaks/lua/autorun/server/sv_manlykillstreaks.lua:0
[/CODE]
[QUOTE=a1steaksa;52406530]I've given that a go and I'm still getting the exact same issue as before. It's just tapping crouch very quickly without holding it.
[video=youtube;zmOajB3Rp3k]https://www.youtube.com/watch?v=zmOajB3Rp3k[/video][/QUOTE]
The clientside doesn't know that the legs are broken, or the hook isn't running clientside.
[editline]28th June 2017[/editline]
Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetNWBool]Entity:SetNWBool[/url] instead of whatever you're using now
[QUOTE=Meninist;52409783]My serverside code is giving me an error I don't understand. Any help is appreciated! :)
-snip-[/QUOTE]
[code]
--------------------------------------------------------------------------------------------------------------------
--Resets players killstreak after they die. Checks if the player suicided. Checks if traitor kills another traitor--
--------------------------------------------------------------------------------------------------------------------
hook.Add("PlayerDeath", "kill_streak_counter", function(victim, _, attacker)
victim:SetKillStreak(0)
end
if(victim != attacker && attacker:IsValid() && attacker:IsPlayer())then
attacker:SetKillStreak(attacker:GetKillStreak() + 1)
end
if victim:IsTraitor() == attacker:IsTraitor() then
attacker:SetKillStreak(0)
util.AddNetworkString("KillstreakReset")
net.Start("KillStreakReset")
net.WriteBool(true)
end
end
[/code]
should be:
[code]
--------------------------------------------------------------------------------------------------------------------
--Resets players killstreak after they die. Checks if the player suicided. Checks if traitor kills another traitor--
--------------------------------------------------------------------------------------------------------------------
hook.Add("PlayerDeath", "kill_streak_counter", function(victim, _, attacker)
victim:SetKillStreak(0)
if(victim != attacker && attacker:IsValid() && attacker:IsPlayer())then
attacker:SetKillStreak(attacker:GetKillStreak() + 1)
end
if victim:IsTraitor() == attacker:IsTraitor() then
attacker:SetKillStreak(0)
util.AddNetworkString("KillstreakReset")
net.Start("KillStreakReset")
net.WriteBool(true)
net.Send(attacker)
end
end)
[/code]
[QUOTE=Benn20002;52408054]Because you create a local table inside a loop and try to index it outside.[/QUOTE]
I've fixed the Lua error, but now the halo doesn't even appear around the player. This is getting really confusing.
[lua]
if LocalPlayer():Team() ~= TEAM_VORT then return end
hook.Add( "PreDrawHalos", "VortalHalo", function()
for k, v in pairs( player.GetAll() ) do
vorts = {}
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)
timer.Simple(15, function()
hook.Remove("PreDrawHalos", "VortalHalo")
end)
[/lua]
[code]function GM:PlayerShouldTakeDamage(victim, pl)
if pl:IsPlayer() then
if pl:Team() == victim:Team() then
return false
else
return true
end
end
end[/code]
Again im making friendly fire option, but is there a way to make explosion still dmg teammate?
[QUOTE=YoutoYokodera;52409865]Again im making friendly fire option, but is there a way to make explosion still dmg teammate?[/QUOTE]
Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/EntityTakeDamage]GM:EntityTakeDamage[/url] instead.
Anyone who knows how i can attach an effect to an entity? I thought i could use ParticleEffectAttach but it it only works for particles. Im trying to make an entity have the standard ar2 tracer. Figured i needed to use util.Effect but i don't know how to make the effect spawn and attach to the entity.
I'm trying to make a poison zombie torso. and the code is at the bottom. and my problem is that first off the torso is slightly floating? and when disable ai is on it goes to T animation instead of idle animation. Help?
function ENT:RunBehaviour()
while ( true ) do
timer.Simple(1.7,function()
end)
local ent = ents.Create("npc_poisonzombie")
ent:SetPos(self:GetPos() + Vector(0,0,20))
ent:SetAngles(self:GetAngles())
ent:Spawn()
ent:SetModel("models/zombie/poison_torso.mdl")
ent:SetKeyValue( "crabcount", 0 )
ent:SetSaveValue("m_fIsTorso", true)
ent:SetName("Poison Zombie Torso")
undo.Create( "Poison Zombie Torso" )
local k, v
for k, v in ipairs( ents.GetAll( ) ) do
if v:IsPlayer() then
undo.AddEntity( ent )
undo.SetPlayer( v )
undo.Finish()
SafeRemoveEntity(self)
coroutine.yield()
end
end
end
end
[QUOTE=Shadow02;52409848]I've fixed the Lua error, but now the halo doesn't even appear around the player. This is getting really confusing.
[lua]
if LocalPlayer():Team() ~= TEAM_VORT then return end
hook.Add( "PreDrawHalos", "VortalHalo", function()
for k, v in pairs( player.GetAll() ) do
vorts = {}
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)
timer.Simple(15, function()
hook.Remove("PreDrawHalos", "VortalHalo")
end)
[/lua][/QUOTE]
Just replace
[code]halo.Add( vorts, Color( 0, 255, 0 ), 1, 1, 2, true, true )[/code]
with
[code]halo.Add( team.GetPlayers(TEAM_VORT), Color( 0, 255, 0 ), 1, 1, 2, true, true )[/code]
(Does the same as your code, but why dont use a function that exists?).
And place the
[code]if LocalPlayer():Team() ~= TEAM_VORT then return end[/code]
inside the hook before the halo.Add().
And you're still resetting the table for every player, you'd have to place it outside the loop.
[QUOTE=Benn20002;52410835]Just replace
[code]halo.Add( vorts, Color( 0, 255, 0 ), 1, 1, 2, true, true )[/code]
with
[code]halo.Add( team.GetPlayers(TEAM_VORT), Color( 0, 255, 0 ), 1, 1, 2, true, true )[/code]
(Does the same as your code, but why dont use a function that exists?).
And place the
[code]if LocalPlayer():Team() ~= TEAM_VORT then return end[/code]
inside the hook before the halo.Add().
And you're still resetting the table for every player, you'd have to place it outside the loop.[/QUOTE]
Thank you.
[QUOTE=SFArial;52409840][code]
--------------------------------------------------------------------------------------------------------------------
--Resets players killstreak after they die. Checks if the player suicided. Checks if traitor kills another traitor--
--------------------------------------------------------------------------------------------------------------------
hook.Add("PlayerDeath", "kill_streak_counter", function(victim, _, attacker)
victim:SetKillStreak(0)
end
if(victim != attacker && attacker:IsValid() && attacker:IsPlayer())then
attacker:SetKillStreak(attacker:GetKillStreak() + 1)
end
if victim:IsTraitor() == attacker:IsTraitor() then
attacker:SetKillStreak(0)
util.AddNetworkString("KillstreakReset")
net.Start("KillStreakReset")
net.WriteBool(true)
end
end
[/code]
should be:
[code]
--------------------------------------------------------------------------------------------------------------------
--Resets players killstreak after they die. Checks if the player suicided. Checks if traitor kills another traitor--
--------------------------------------------------------------------------------------------------------------------
hook.Add("PlayerDeath", "kill_streak_counter", function(victim, _, attacker)
victim:SetKillStreak(0)
if(victim != attacker && attacker:IsValid() && attacker:IsPlayer())then
attacker:SetKillStreak(attacker:GetKillStreak() + 1)
end
if victim:IsTraitor() == attacker:IsTraitor() then
attacker:SetKillStreak(0)
util.AddNetworkString("KillstreakReset")
net.Start("KillStreakReset")
net.WriteBool(true)
net.Send(attacker)
end
end)
[/code][/QUOTE]
Doesn't seem to be working with this. Giving me this error.
[CODE]
[ERROR] addons/manlykillstreaks/lua/autorun/server/sv_manlykillstreaks.lua:31: ')' expected (to close '(' at line 27) near 'if'
1. unknown - addons/manlykillstreaks/lua/autorun/server/sv_manlykillstreaks.lua:0
[/CODE]
I don't see an error with his code; some part of your code is missing a close parenthesis
[QUOTE=code_gs;52411499]I don't see an error with his code; some part of your code is missing a close parenthesis[/QUOTE]
The part I showed is where it says the error is happening. It works fine until I try to add the netmessage.
Here's the whole code.
[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
-------------------------------------------------------------
--The function to use to see what the user's killstreak is.--
-------------------------------------------------------------
function PLAYER:GetKillStreak()
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
--------------------------------------------------------------------------------------------------------------------
--Resets players killstreak after they die. Checks if the player suicided. Checks if traitor kills another traitor--
--------------------------------------------------------------------------------------------------------------------
hook.Add("PlayerDeath", "kill_streak_counter", function(victim, _, attacker)
victim:SetKillStreak(0)
end
if (victim != attacker && attacker:IsValid() && attacker:IsPlayer()) then
attacker:SetKillStreak(attacker:GetKillStreak() + 1)
end
if victim:IsTraitor() == attacker:IsTraitor() then
attacker:SetKillStreak(0)
util.AddNetworkString("KillstreakReset")
net.Start("KillstreakReset")
net.WriteBool(true)
net.Send(attacker)
end
local role = ((pl.GetRole && pl:GetRole()) || ROLE_INNOCENT)
if (attacker:GetRole() == ROLE_INNOCENT) == (victim:GetRole() == ROLE_INNOCENT) then
attacker:SetKillStreak(0)
util.AddNetworkString("KillstreakReset")
net.Start("KillstreakReset")
net.WriteBool(true)
net.Send(attacker)
end)
------------------------------------------------------------------------------------------
hook.Add("TTTEndRound", "killstreak_ResetOnEnd", function(pl)
local pls = player.GetAll();
for i = 1, #pls do
local pl = pls[i];
pl:SetKillStreak(0)
end
end)
---------------------------------------------------------------------------------
--This is the net message sent to the user containing their current killstreak.--
---------------------------------------------------------------------------------
util.AddNetworkString("GetKillStreak")
hook.Add("OnKillStreakChange", "player_KillStreakChange", function(pl, newNum)
net.Start("GetKillStreak")
net.WriteInt(newNum, 32)
net.Send(pl)
end)
---------------------------------------------------------------------------------[/CODE]
[QUOTE=Meninist;52411601]The part I showed is where it says the error is happening. It works fine until I try to add the netmessage.
Here's the whole code.
[CODE]
--------------------------------------------------------------------------------------------------------------------
--Resets players killstreak after they die. Checks if the player suicided. Checks if traitor kills another traitor--
--------------------------------------------------------------------------------------------------------------------
hook.Add("PlayerDeath", "kill_streak_counter", function(victim, _, attacker)
victim:SetKillStreak(0)
end
[/CODE][/QUOTE]
Remove the end.
[QUOTE=Benn20002;52411636]Remove the end.[/QUOTE]
Even better, that wasn't in the original code he posted :v
[QUOTE=code_gs;52411865]Even better, that wasn't in the original code he posted :v[/QUOTE]
Uhm, yes it is. lol
[QUOTE=Meninist;52412316]Uhm, yes it is. lol[/QUOTE]
No, it's not.
[T]http://i.imgur.com/F8z2b5l.jpg[/t]
Too long code so i paste them in this link
[url]https://paste.ofcode.org/34KgsvsqkbUQDztN8kAuiud[/url]
No idea why the mine don't explode when i shoot it
(Was testing with Remove)
Having a small issue with some programming and it seems I completely blocked off my problem solving skills (if I ever had any to begin with)
[CODE]
local function ANN (ply, args)
local DidHeSaySomething = function(text)
lwrtext = string.lower(text)
local examplestring = " "
if (string.find(lwrtext) == "something1") then
adressto = "SomeThing1"
else
if (string.find(lwrtext) == "something2") then
adressto = "SomeThing2"
else
if (string.find(lwrtext) =="something3") then
adressto = "SomeThing3"
else
if (string.find(lwrtext) == "something4") then
adressto = "SomeThing4"
else
if (string.find(lwrtext) == "something5") then
adressto = "SomeThing5"
else
adressto = "who the fuck are you trying to tell this to"
return adressto
end
end
end
end
end
end
[/CODE]
la ti da then followed by a simple chat command output
[CODE]
for k,v in pairs(player.GetAll()) do
local color = team.GetColor(ply:Team())
local teamofply = team.GetName(ply:Team())
DarkRP.talkToPerson(v, col, "[Some douchebag named" .. teamply .. " " .. ply:Nick() .. " " .. "is trying to talk to some boneheads over at" .. " " .. adressto .."]", Color(255, 100, 0, 255), text, ply)
end
end
return args, DidHeSaySomething
end
end
[/CODE]
long story short a person would put something like "/sendamessagetopresidentthedonaldtrump asdasdasd" and I'm trying to make it look for "something1-5" so that it can make the value of adressto = "SomeThing1-5"
also tried something like this (from GMOD Wiki)
[QUOTE]
[CODE]hook.Add( "PlayerSay", "PlayerSayExample", function( ply, text, team )
if ( string.sub( text, 1, 4 ) == "/all" ) then -- if the first four characters of the string are /all
return "[Global] " .. string.sub( text, 5 ) -- add [Global] in front of the players text then display
end
end )[/CODE]
[/QUOTE]
But whatever I do it seems to break the whole entire thing
[I][B]
(Not actual indentation CODE wrap kind of ruined it)[/B][/I]
[QUOTE=WAV.Form;52413870]Having a small issue with some programming and it seems I completely blocked off my problem solving skills (if I ever had any to begin with)
[CODE]
local function ANN (ply, args)
local DidHeSaySomething = function(text)
lwrtext = string.lower(text)
local examplestring = " "
if (string.find(lwrtext) == "something1") then
adressto = "SomeThing1"
else
if (string.find(lwrtext) == "something2") then
adressto = "SomeThing2"
else
if (string.find(lwrtext) =="something3") then
adressto = "SomeThing3"
else
if (string.find(lwrtext) == "something4") then
adressto = "SomeThing4"
else
if (string.find(lwrtext) == "something5") then
adressto = "SomeThing5"
else
adressto = "who the fuck are you trying to tell this to"
return adressto
end
end
end
end
end
end
[/CODE]
la ti da then followed by a simple chat command output
[CODE]
for k,v in pairs(player.GetAll()) do
local color = team.GetColor(ply:Team())
local teamofply = team.GetName(ply:Team())
DarkRP.talkToPerson(v, col, "[Some douchebag named" .. teamply .. " " .. ply:Nick() .. " " .. "is trying to talk to some boneheads over at" .. " " .. adressto .."]", Color(255, 100, 0, 255), text, ply)
end
end
return args, DidHeSaySomething
end
end
[/CODE]
long story short a person would put something like "/sendamessagetopresidentthedonaldtrump asdasdasd" and I'm trying to make it look for "something1-5" so that it can make the value of adressto = "SomeThing1-5"
also tried something like this (from GMOD Wiki)
But whatever I do it seems to break the whole entire thing
[I][B]
(Not actual indentation CODE wrap kind of ruined it)[/B][/I][/QUOTE]
1) Holy shit use elseif
2) You don't need that many if statements, just use patterns to find the word "something" followed by a digit
3) Why are you defining a function inside a function?
[QUOTE=JasonMan34;52413914]1) Holy shit use elseif
2) You don't need that many if statements, just use patterns to find the word "something" followed by a digit
3) Why are you defining a function inside a function?[/QUOTE]
1. i tried, awkwardly broke it 3 different times
(seems like fragile code) but thanks never the less
2. If there's a different way to do it other than the 2 ways I already tried please link to the source :)
3. Cause I wanna it works doesn't it :P
[QUOTE=WAV.Form;52413948]1. i tried, awkwardly broke it 3 different times
(seems like fragile code) but thanks never the less[/QUOTE]
That's not a reason to make the code unnecessarily complex. If you have a problem, ask for help.
[QUOTE=WAV.Form;52413948]
2. If there's a different way to do it other than the 2 ways I already tried please link to the source :)[/QUOTE]
Use [img]http://wiki.garrysmod.com/favicon.ico[/img][url=http://wiki.garrysmod.com/page/string/find]string.find[/url] with [URL=http://wiki.garrysmod.com/page/Patterns]Patterns[/url] ("something%d")
[QUOTE=WAV.Form;52413948]
3. Cause I wanna it works doesn't it :P[/QUOTE]
Again, just because it works doesn't mean it's right. What's the purpose of defining it inside the function?
[QUOTE=JasonMan34;52414085]That's not a reason to make the code unnecessarily complex. If you have a problem, ask for help.
Use [img]http://wiki.garrysmod.com/favicon.ico[/img][url=http://wiki.garrysmod.com/page/string/find]string.find[/url] with [URL=http://wiki.garrysmod.com/page/Patterns]Patterns[/url] ("something%d")
Again, just because it works doesn't mean it's right. What's the purpose of defining it inside the function?[/QUOTE]
My mistake, I'll try that, thanks :)
I'm having a really strange problems with the net library.
I'm passing colors with [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/net/WriteInt]net.WriteInt[/url] individually but for some reason it only works if I use 32 bits per value.
If I try to use 8 bits(which should work because it's a value between 0 and 255) it doesn't send the right numbers.
[QUOTE=bilbasio;52414519]I'm having a really strange problems with the net library.
I'm passing colors with [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/net/WriteInt]net.WriteInt[/url] individually but for some reason it only works if I use 32 bits per value.
If I try to use 8 bits(which should work because it's a value between 0 and 255) it doesn't send the right numbers.[/QUOTE]
Use WriteUInt, or else the value will be clamped between -128 and 127
I'm trying to make an entity but whenever I spawn it in sandbox I get an error model, though when I spawn it in through my gamemode the model shows up. I've got no idea how to fix it, this is the code but I feel like it's probably because of where I saved the entity or something:
[CODE]function ENT:Initizialize()
self:SetModel( "models/props_borealis/bluebarrel001.mdl" )
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_NONE)
self:SetSolid(SOLID_VPHYSICS)
self:GetPhysicsObject():Wake()
end[/CODE]
I'm trying to make a poison zombie torso. and the code is at the bottom. and my problem is that first off the torso is slightly floating? and when disable ai is on it goes to T animation instead of idle animation. Help?
function ENT:RunBehaviour()
while ( true ) do
timer.Simple(1.7,function()
end)
local ent = ents.Create("npc_poisonzombie")
ent:SetPos(self:GetPos() + Vector(0,0,20))
ent:SetAngles(self:GetAngles())
ent:Spawn()
ent:SetModel("models/zombie/poison_torso.mdl")
ent:SetKeyValue( "crabcount", 0 )
ent:SetSaveValue("m_fIsTorso", true)
ent:SetName("Poison Zombie Torso")
undo.Create( "Poison Zombie Torso" )
local k, v
for k, v in ipairs( ents.GetAll( ) ) do
if v:IsPlayer() then
undo.AddEntity( ent )
undo.SetPlayer( v )
undo.Finish()
SafeRemoveEntity(self)
coroutine.yield()
end
end
end
end
This is literally spamming my console..
Bad SetLocalOrigin(-17068.048828,-15015.128906,-30.203926) on gmod_hands
What could cause this?
Sorry, you need to Log In to post a reply to this thread.