[QUOTE=Shenesis;49689563]Has anyone encountered an issue with ClientsideModels where they sometimes "lag" behind their intended position?
Here's a video of it happening:
[/QUOTE]
I think I had something like that and the solution was to call SetupBones on the ClientsideModel, assuming you're drawing the CSmodel after the viewmodel.
On EmitSound it says: if used on a player or NPC character with the mouth rigged, the character will "lip-sync". How do i make his mouth rigged? I'm trying with the Kleiner model but his mouth dosent seem to move.
o nvm, it just didnt work with that specific .wav sound..
How do I call a custom SWEP function? all I'm getting is attempt to index global 'SWEP'..
[QUOTE=keeperman;49698193]How do I call a custom SWEP function? all I'm getting is attempt to index global 'SWEP'..[/QUOTE]
Use
[CODE]self:Whatever()[/CODE]
instead
SWEP only works outside of the functions
[QUOTE=BillyOnWiiU;49698286]Use
[CODE]self:Whatever()[/CODE]
instead
SWEP only works outside of the functions[/QUOTE]
Usually this is correct but I think this needs a little more clarification.
SWEP exists only when the file is ran and not afterwards - this is a table that is applied to the weapon entity that is created later. SWEP hooks are called with self as the entity of the weapon, the entity has each function and field that were in SWEP when the script for it was run.
For example this is possible:
[lua]
function SWEP:DoSomeUsingSwep()
print(SWEP)
end
SWEP:DoSomethingUsingSwep()
[/lua]
As well as this:
[lua]
SWEP.Value = 1
function SWEP:GetValue()
return self.Value;
end
concommand.Add("getvalue", function(ply, cmd, args)
print(ply:GetActiveWeapon():GetValue())
end);
[/lua]
Is there a way to halve the player speed? I know I could use GM:SetPlayerSpeed, but there are many mods that change player speeds, and I don't want to override them, so I can't use static values there. I need to set the speed to half of what it should be, no matter if sprinting, crouching or using a weapon that slows him down.
[QUOTE=>>oubliette<<;49698640]Usually this is correct but I think this needs a little more clarification.
SWEP exists only when the file is ran and not afterwards - this is a table that is applied to the weapon entity that is created later. SWEP hooks are called with self as the entity of the weapon, the entity has each function and field that were in SWEP when the script for it was run.
For example this is possible:
[lua]
function SWEP:DoSomeUsingSwep()
print(SWEP)
end
SWEP:DoSomethingUsingSwep()
[/lua]
As well as this:
[lua]
SWEP.Value = 1
function SWEP:GetValue()
return self.Value;
end
concommand.Add("getvalue", function(ply, cmd, args)
print(ply:GetActiveWeapon():GetValue())
end);
[/lua][/QUOTE]
The game won't allow me to call the function for some odd reason, even though I have a similar thing in the code [code]net.Receive( "Netstringthing", function() SWEP:CreateModels() end)[/code]
[QUOTE=keeperman;49698861]The game won't allow me to call the function for some odd reason, even though I have a similar thing in the code [code]net.Receive( "Netstringthing", function() SWEP:CreateModels() end)[/code][/QUOTE]
My example called the function as soon as the script was ran. Yours will never get that chance as it'll be at a minimum ran a tick later. SWEP doesn't exist by that time.
What are you trying to do?
[QUOTE=>>oubliette<<;49698991]My example called the function as soon as the script was ran. Yours will never get that chance as it'll be at a minimum ran a tick later. SWEP doesn't exist by that time.
What are you trying to do?[/QUOTE]
I'm trying to send a vector from a clientside prop the server, but my function does get called in initialize. So the problem is that net.receive can't call the SWEP function
[editline]8th February 2016[/editline]
Whoops copied the wrong net.receive
[code] net.Receive( "NeatNet", function() print( tostring( net.ReadVector() ) ) SWEP:SecondaryAttack( net.ReadVector() ) end) [/code]
[QUOTE=keeperman;49699021]I'm trying to send a vector from a clientside prop the server, but my function does get called in initialize. So the problem is that net.receive can't call the SWEP function[/QUOTE]
try something like:
[lua]
net.Receive("hgdfkjhgdkjfhg", function(len, ply)
local wep = ply:GetActiveWeapon();
if (IsValid(wep) && wep:GetClass() == "myweaponclass") then
wep:Something(net.ReadVector());
end
end);
[/lua]
[QUOTE=>>oubliette<<;49699042]try something like:
[lua]
net.Receive("hgdfkjhgdkjfhg", function(len, ply)
local wep = ply:GetActiveWeapon();
if (IsValid(wep) && wep:GetClass() == "myweaponclass") then
wep:Something(net.ReadVector());
end
end);
[/lua][/QUOTE]
Nah, that won't help. All I'm trying to do is call the function
[QUOTE=keeperman;49699066]Nah, that won't help. All I'm trying to do is call the function[/QUOTE]
That's what my code does, though I feel as if you're doing something wrong for attempting to do it this way, especially since as the net code you posted had you call SecondaryAttack. If you want to have the client call a SWEP function on the server, use the code I provided.
[QUOTE=>>oubliette<<;49699104]That's what my code does, though I feel as if you're doing something wrong for attempting to do it this way, especially since as the net code you posted had you call SecondaryAttack. If you want to have the client call a SWEP function on the server, use the code I provided.[/QUOTE]
[code]function SWEP:SecondaryAttack( vec )
local ply = self.Owner
local part = EffectData()
if ply ~= NULL then
hook.Call( "ergthrhtrhwf" )
part:SetOrigin( vec )
part:SetScale( 1 )
util.Effect( "effect", part)
end
end
net.Receive( "ergergergerg", function() print( tostring( net.ReadVector() ) ) SWEP:SecondaryAttack( net.ReadVector() ) end)[/code] Yours won't help. Everything works except calling giving the function the arguments because I get an error whenever I call it
[QUOTE=keeperman;49699141][code]function SWEP:SecondaryAttack( vec )
local ply = self.Owner
local part = EffectData()
if ply ~= NULL then
hook.Call( "ergthrhtrhwf" )
part:SetOrigin( vec )
part:SetScale( 1 )
util.Effect( "effect", part)
end
end
net.Receive( "ergergergerg", function() print( tostring( net.ReadVector() ) ) SWEP:SecondaryAttack( net.ReadVector() ) end)[/code] Yours won't help. Everything works except calling giving the function the arguments because I get an error whenever I call it[/QUOTE]
You misunderstand my Swedish friend. Firstly that function will be called each time you right click, so for the example I'll call it something else. Also unless you're sending two vectors from the client, the second call to net.ReadVector will return garbage.
Here:
[lua]
function SWEP:MakeEffects( vec )
local ply = self.Owner
local part = EffectData()
hook.Call( "ergthrhtrhwf" )
part:SetOrigin( vec )
part:SetScale( 1 )
util.Effect( "effect", part)
end
util.AddNetworkString( "ergergergerg" );
net.Receive( "ergergergerg", function(len, ply)
local wep = ply:GetActiveWeapon();
if (IsValid(wep) && wep:GetClass() == "my weapon class (fill me in for security)") then
wep:MakeEffects( net.ReadVector() );
end
end)
[/lua]
[QUOTE=>>oubliette<<;49699485]You misunderstand my Swedish friend. Firstly that function will be called each time you right click, so for the example I'll call it something else. Also unless you're sending two vectors from the client, the second call to net.ReadVector will return garbage.
Here:
[lua]
function SWEP:MakeEffects( vec )
local ply = self.Owner
local part = EffectData()
hook.Call( "ergthrhtrhwf" )
part:SetOrigin( vec )
part:SetScale( 1 )
util.Effect( "effect", part)
end
util.AddNetworkString( "ergergergerg" );
net.Receive( "ergergergerg", function(len, ply)
local wep = ply:GetActiveWeapon();
if (IsValid(wep) && wep:GetClass() == "my weapon class (fill me in for security)") then
wep:MakeEffects( net.ReadVector() );
end
end)
[/lua][/QUOTE]
[lua]
for k,v in pairs(player.GetAll()) do net.Start("ergergergerg") net.WriteVector(v:GetPos()) net.SendToServer() end
[/lua]
:v:
[QUOTE=Leystryku;49699506][lua]
for k,v in pairs(player.GetAll()) do net.Start("ergergergerg") net.WriteVector(v:GetPos()) net.SendToServer() end
[/lua]
:v:[/QUOTE]
[lua]
wep:GetClass() == "my weapon class (fill me in for security)"
[/lua]
Also vector shouldn't be sent from client but I'm not sure what he's trying to achieve so I left that in example
[QUOTE=>>oubliette<<;49699485]You misunderstand my Swedish friend. Firstly that function will be called each time you right click, so for the example I'll call it something else. Also unless you're sending two vectors from the client, the second call to net.ReadVector will return garbage.
Here:
function SWEP:MakeEffects( vec ) local ply = self.Owner local part = EffectData() hook.Call( "ergthrhtrhwf" ) part:SetOrigin( vec ) part:SetScale( 1 ) util.Effect( "effect", part)endutil.AddNetworkString( "ergergergerg" );net.Receive( "ergergergerg", function(len, ply) local wep = ply:GetActiveWeapon(); if (IsValid(wep) && wep:GetClass() == "my weapon class (fill me in for security)") then wep:MakeEffects( net.ReadVector() ); endend)
[/QUOTE]
Now I see what you mean
[editline]8th February 2016[/editline]
[QUOTE=>>oubliette<<;49699530]
wep:GetClass() == "my weapon class (fill me in for security)"
Also vector shouldn't be sent from client but I'm not sure what he's trying to achieve so I left that in example[/QUOTE]
In SCK the models are client only. If you look [URL="https://github.com/Clavus/SWEP_Construction_Kit/blob/master/lua/weapons/swep_construction_kit/base_code.lua#L343"]here[/URL]
[QUOTE=>>oubliette<<;49699530][lua]
wep:GetClass() == "my weapon class (fill me in for security)"
[/lua]
Also vector shouldn't be sent from client but I'm not sure what he's trying to achieve so I left that in example[/QUOTE]
yea, but net.Receive with ply as second arg is serverside, meaning the only condition for spamming effects = have that weapon :V
[QUOTE=Leystryku;49699902]yea, but net.Receive with ply as second arg is serverside, meaning the only condition for spamming effects = have that weapon :V[/QUOTE]
But I wasn't sure how to express that issue without knowing what his plan was for the vector, I thought with all the prints and stuff the Vector was a test at first but yeah, you're right. Don't accept random vectors from the client.
[QUOTE=keeperman;49699538]
In SCK the models are client only. If you look [URL="https://github.com/Clavus/SWEP_Construction_Kit/blob/master/lua/weapons/swep_construction_kit/base_code.lua#L343"]here[/URL][/QUOTE]
The difficult but proper way to do it would be calculate where the effect should be made on the server, using same offsets from bones/attachments that the client would use to position the cmodel.
[QUOTE=MaxShadow;49698762]Is there a way to halve the player speed? I know I could use GM:SetPlayerSpeed, but there are many mods that change player speeds, and I don't want to override them, so I can't use static values there. I need to set the speed to half of what it should be, no matter if sprinting, crouching or using a weapon that slows him down.[/QUOTE]
get functions are fun
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/GetWalkSpeed]Player:GetWalkSpeed[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/GetRunSpeed]Player:GetRunSpeed[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/GetCrouchedWalkSpeed]Player:GetCrouchedWalkSpeed[/url]
[QUOTE=roastchicken;49700854]get functions are fun
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/GetWalkSpeed]Player:GetWalkSpeed[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/GetRunSpeed]Player:GetRunSpeed[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/GetCrouchedWalkSpeed]Player:GetCrouchedWalkSpeed[/url][/QUOTE]
That won't work. If I do something like this:
[CODE]ply:SetWalkSpeed(ply:GetWalkSpeed()/2)[/CODE]
It will halve the current player speed every tick, until it's 0. If I only change the speed once, it will be overridden by another addon that also changes player speed. It's not what I'm looking for.
Anyway, I solved it myself with this (in a Think hook):
[CODE]ply:SetLocalVelocity(ply:GetVelocity()/2)[/CODE]
[QUOTE=MaxShadow;49701930]That won't work. If I do something like this:
[CODE]ply:SetWalkSpeed(ply:GetWalkSpeed()/2)[/CODE]
It will halve the current player speed every tick, until it's 0. If I only change the speed once, it will be overridden by another addon that also changes player speed. It's not what I'm looking for.
Anyway, I solved it myself with this (in a Think hook):
[CODE]ply:SetLocalVelocity(ply:GetVelocity()/2)[/CODE][/QUOTE]
that's an awfully expensive way of doing it.
unless you're expecting their default (read: non-halved) speed to change, you can just set their speed to half of their current speed once.
[editline]9th February 2016[/editline]
wait, why is another addon also changing their speed?
you can store the default speed in a variable and set it to half that each time, but I'm not sure if that's much better than just halving their velocity.
[QUOTE=roastchicken;49702964]that's an awfully expensive way of doing it.
unless you're expecting their default (read: non-halved) speed to change, you can just set their speed to half of their current speed once.
[editline]9th February 2016[/editline]
wait, why is another addon also changing their speed?
you can store the default speed in a variable and set it to half that each time, but I'm not sure if that's much better than just halving their velocity.[/QUOTE]
I was thinking in those popular weapon mods like TFA and CW2.0. I was pretty sure that they change player speed when you're using them, but now I don't know. The idea is to halve the player speed while he's dragging a corpse. I agree, changing velocity every tick is much more expensive than changing player speed when he grabs or drops a corpse, I just didn't want to add more compatibility problems to my mod (it already has a few). But perhaps i'm just over complicating things.
[QUOTE=MaxShadow;49703694]I was thinking in those popular weapon mods like TFA and CW2.0. I was pretty sure that they change player speed when you're using them, but now I don't know. The idea is to halve the player speed while he's dragging a corpse. I agree, changing velocity every tick is much more expensive than changing player speed when he grabs or drops a corpse, I just didn't want to add more compatibility problems to my mod (it already has a few). But perhaps i'm just over complicating things.[/QUOTE]
I'm not exactly sure how expensive changing velocity each tick is. I guess if you're not having major lag it's the best solution.
[QUOTE=MaxShadow;49703694]I was thinking in those popular weapon mods like TFA and CW2.0. I was pretty sure that they change player speed when you're using them, but now I don't know. The idea is to halve the player speed while he's dragging a corpse. I agree, changing velocity every tick is much more expensive than changing player speed when he grabs or drops a corpse, I just didn't want to add more compatibility problems to my mod (it already has a few). But perhaps i'm just over complicating things.[/QUOTE]
There is a way!
here is a snippet of code I wrote for a darkrp drug addon I never released
[code]
-- azs_shared.lua
-- lets modify movement when high
hook.Add("Move","AZSMovement", function(ply, cmd) -- hahahah check out this fuckery
if ply:GetDrunkHigh() > 0 then
local drunkness = ply:GetDrunkHigh()
if drunkness > 14 then drunkness = 14 end
local scale = (drunkness/32) +1
--print(scale)
local currentMax = cmd:GetMaxSpeed()
local targetMax = currentMax * scale
local hardMax = 300 -- no running faster than this, ever
local setMax = (targetMax > hardMax) and hardMax or targetMax
cmd:SetMaxSpeed( setMax )
cmd:SetMaxClientSpeed( setMax )
end
end)
[/code]
Just before I write the actual code, does this logic make sense? I want police NPCs to chase down a player who kills a civilian NPC.
server side OnNPCKilled hook:
[code]
if attacker not on list of criminals
add to list
[/code]
server side code in constant timer:
[code]
loop through all police entities:
if is_currently_chasing == true
if enemy dead
clear enemy memory
is_chasing = false
else if is_currently_chasing == false
if criminals on list
set random criminal as enemy
begin chase
is_chasing = true
if no criminals on list
walk back to spawn
[/code]
Why won't my ply:SetBodygroup work?
It's being called serverside one frame after a playerspawn hook.
I know bodygroups work since Rubat's easy bodygroup tool works fine.
[lua]if (condition) then
print(ply .. "BODYGROUP")
ply:SetBodygroup(0,1)
end[/lua]
prints:
Splerge BODYGROUP
I've got quick question;
My gamemode has two mode (Build/Match)
I would like to make one HUD for the Build and another one for the Match mode.
Do I have to use:
[CODE]hook.Add ("HUDPaint", "xxx", function () end)[/CODE]
Then call hook.Remove("HUDPaint", "xxx") whenever I want to remove the HUD to use the other one?!
Or should I make functions that uses vgui.Create("DFrame") and then use the Paint function to draw anything then call the functions of each HUD whenever I want to use the called one? (So it basically draw the created DFrame)
Thanks
[QUOTE=Splerge;49705908]Why won't my ply:SetBodygroup work?
It's being called serverside one frame after a playerspawn hook.
I know bodygroups work since Rubat's easy bodygroup tool works fine.
[lua]if (condition) then
print(ply .. "BODYGROUP")
ply:SetBodygroup(0,1)
end[/lua]
prints:
Splerge BODYGROUP[/QUOTE]
Are you sure your arguments are correct? What happens if you manually call player.GetByID(1):SetBodygroup(0,1) when you are in the server?
I'm trying to make a custom slider without using DNumSlider so I can make it look nice, but I have no idea how to make it actually usable. This is my current code:
[CODE]local function AddSlider(k, _k)
local y = 10 + (options[k][_k][2]-1) * 20
local max = options[k][_k][5][2]
local width = math.ceil(options[k][_k][3] * (140 - 4) / max);
local SliderHolder = vgui.Create("DPanel", Sheets[k])
SliderHolder:SetPos(Main:GetWide() - Info:GetWide() - 185, y)
SliderHolder:SetSize(140, 20 - 1)
local Slider = vgui.Create("DPanel", SliderHolder)
Slider:SetPos(2, 2)
Slider:SetSize(width, 20 - 5)
SliderHolder.Paint = function(self)
DrawRect(0, 0, self:GetWide(), self:GetTall(), Color(45,45,45))
DrawText(options[k][_k][4], "MenuFont", self:GetWide() / 2, self:GetTall() / 2, Color(250,250,250), "c", "c")
end
Slider.Paint = function(self)
DrawRect(0, 0, self:GetWide(), self:GetTall(), Color(195,195,229))
DrawText(options[k][_k][4], "MenuFont", SliderHolder:GetWide() / 2, SliderHolder:GetTall() / 2 - 2, Color(5,5,5), "c", "c")
end
end[/CODE]
I'd appreciate any help making it slide with the mouse. <3
Sorry, you need to Log In to post a reply to this thread.