[QUOTE=Mitsudigi;47039825]A year ago I did mouse steering just for fun and ran into the same problem. It works fine when the player is outside the vehicle but once they are driving the wheels refuse to fully turn even if the player doesn't press anything.
Ended up combining it with tiny bursts of WASD depending on angle of turn and it works OK but definitely not as good as it could be.
Here is the code if anyone wants it:
[url]http://pastebin.com/raw.php?i=PmnWEvqt[/url]
Hold right click while in a vehicle to activate it.[/QUOTE]
I tried similar but I was only able to get it to work at speeds of 30-35MPH based on 4/3 = 1 inch. Then it doesn't matter and steering works without any issue.
So, because both of us came to similar conclusions it may be a "bug" because the "Steer" tag is supposed to force the steering. I may post it as an issue on git. Thanks for confirming it!
You wrote a lot more than I did; I was considering using the client to handle steering but since the entity itself is server-side and all controls and movement is handled on the server and because eye angles, etc.. could be obtained on the server I did it all on the server.
This was my code ( Showed the wheels and steering wheel turning [ pose ] and controlled it properly but only above speed mentioned.. otherwise it would limit turning when using A/D if only small amount used ):
[code]hook.Add( "SetupMove", "Vehicle:SteeringSystem", function( _p, _input )
if ( _p:InVehicle( ) ) then
local _v = _p:GetVehicle( );
local _eye_ang = _p:EyeAngles( ).y;
local _v_ang = _v:GetAngles( ).y + 90;
local _ang_diff = math.Clamp( math.AngleDifference( _eye_ang, _v_ang ), -15, 15 ); -- 15 degrees = full-turn
_ang_diff = ( _ang_diff < 0.5 && _ang_diff > -0.5 ) && 0 || _ang_diff; -- Small dead-zone
_steering = ( -_ang_diff / 15 ); -- 1 to -1 based on clamp
_v:SetPoseParameter( "vehicle_steer", _steering ); -- steering wheel and wheel turning animation
_v:Fire( "Steer", _steering ); -- make it happen
end
end );[/code]
[QUOTE=Acecool;47040060]I tried similar but I was only able to get it to work at speeds of 30-35MPH based on 4/3 = 1 inch. Then it doesn't matter and steering works without any issue.[/QUOTE]
Yeah, you're right, my approach was far more convoluted than it needed to be.. It has a HUD indicator as well as auto centering sort of like force feedback controllers have but your code is definitely way more efficient.
PM me with the issue URL and I'll make sure to post confirming that I have the same issue.
Try modifying the CUserCmd's sidemove variable. It should allow for analogue steering as long as IN_MOVELEFT and IN_MOVERIGHT are not held.
[editline]30th January 2015[/editline]
[code]
hook.Add( "CreateMove", "", function( cmd )
cmd:SetSideMove( math.sin( CurTime() * math.pi * 2 / 10 ) * 400 )
end )
[/code]
I believe -400 and 400 are the bounds for the input when applied to a vehicle's turning, but this could be different in gmod's compilation of the sdk.
How would I go about changing a bool on the player that's on the client-side from the server?
Such as I have the bool m_bThirdPEnabled being set on the client but when he changes teams I want to set this to false from OnPlayerChangedTeam
Either use a net message or use SetNWBool on server and GetNWBool on client.
Or SendLua if you're lazy and it's a global bool.
[QUOTE=Robotboy655;47042674]Either use a net message or use SetNWBool on server and GetNWBool on client.[/QUOTE]
Hmm those could work but this is where I get confused, how would GetNWBool work here, Figured I can't use SetNWBool since PlayerBindPress is only on the clientside
This function is where the bool is set
[code]function GM:PlayerBindPress(pl, bind, wasin)
if bind == "gmod_undo" or bind == "undo" then
RunConsoleCommand("+zoom")
timer.CreateEx("ReleaseZoom", 1, 1, RunConsoleCommand, "-zoom")
elseif bind == "+menu_context" then
if pl and pl:OldAlive() then
if pl.m_bThirdPDisabled then
return
end
if pl:Team() == TEAM_UNDEAD and pl.m_bShoulderEnabled then
pl.m_bShoulderEnabled = false
elseif pl:Team() == TEAM_HUMAN and not pl.m_bShoulderEnabled then
pl.m_bShoulderEnabled = true
end
pl.m_bThirdPEnabled = not pl.m_bThirdPEnabled
end
end
end[/code]
I'd figure you'd use net.send here but then how would I send the bool back to the client from the server without another net.send from the serverside
If you are using clientside hook to toggle your third person why do you need the server to send anything?
[QUOTE=Robotboy655;47042918]If you are using clientside hook to toggle your third person why do you need the server to send anything?[/QUOTE]
Because OnPlayerChangedTeam is server-side only apparently, all I really want to do is disable thridperson when you change teams
[QUOTE=ForrestMarkX;47043026]Because OnPlayerChangedTeam is server-side only apparently, all I really want to do is disable thridperson when you change teams[/QUOTE]
Network it. [url]http://wiki.garrysmod.com/page/Net_Library_Usage[/url]
[QUOTE=StonedPenguin;47043083]Network it. [url]http://wiki.garrysmod.com/page/Net_Library_Usage[/url][/QUOTE]
I know about this but sadly I do not know how I would go about sending the value back to the client so far I know to do something like this
[code]function GM:PlayerBindPress(pl, bind, wasin)
--Snip
elseif bind == "+menu_context" then
if pl and pl:OldAlive() then
--Snip
pl.m_bThirdPEnabled = not pl.m_bThirdPEnabled
net.Start( "stp_enabled" )
net.WriteBit(pl.m_bThirdPEnabled)
net.SendToServer()
end
end
end[/code]
I'm unsure where to place net.Receive but I'm sure within init.lua of the gamemode since this is located in cl_init.lua
Couldn't I just do something like. EDIT: Nevermind doing SetNWBool will only set it on the clientside if it's called from the client
[code]pl:SetNWBool("m_bThirdPEnabled", not pl:GetNWBool("m_bThirdPEnabled") )[/code]
[QUOTE=ForrestMarkX;47043154]I know about this but sadly I do not know how I would go about sending the value back to the client so far I know to do something like this
[code]function GM:PlayerBindPress(pl, bind, wasin)
--Snip
elseif bind == "+menu_context" then
if pl and pl:OldAlive() then
--Snip
pl.m_bThirdPEnabled = not pl.m_bThirdPEnabled
net.Start( "stp_enabled" )
net.WriteBit(pl.m_bThirdPEnabled)
net.SendToServer()
end
end
end[/code]
I'm unsure where to place net.Receive but I'm sure within init.lua of the gamemode since this is located in cl_init.lua
Couldn't I just do something like. EDIT: Nevermind doing SetNWBool will only set it on the clientside if it's called from the client
[code]pl:SetNWBool("m_bThirdPEnabled", not pl:GetNWBool("m_bThirdPEnabled") )[/code][/QUOTE]
place the
net.Receive("stp_enabled", function()
--your stuff
end)
in an empty area of init.lua
[QUOTE=bobbleheadbob;47043521]place the
net.Receive("stp_enabled", function()
--your stuff
end)
in an empty area of init.lua[/QUOTE]
What about when I change the bool from the server? How would I sent it back to the client?
[QUOTE=ForrestMarkX;47043538]What about when I change the bool from the server? How would I sent it back to the client?[/QUOTE]
net.Start("stp_enabled")
net.WriteBit(bYourBool)
net.Send(ply)
on the client:
net.Receive("stp_enabled",function(len)
THE_BOOL_YOU_WANNA_SET = net.ReadBit()==1
end)
Note that net.WriteBit takes a bool as an input and net.ReadBit returns a number 0 or 1 for stupid reasons.
[QUOTE=bobbleheadbob;47043864]net.Start("stp_enabled")
net.WriteBit(bYourBool)
net.Send(ply)
on the client:
net.Receive("stp_enabled",function(len)
THE_BOOL_YOU_WANNA_SET = net.ReadBit()==1
end)
Note that net.WriteBit takes a bool as an input and net.ReadBit returns a number 0 or 1 for stupid reasons.[/QUOTE]
I see, this is my last question is net.Start required to be within a function?
[QUOTE=ForrestMarkX;47043918]I see, this is my last question is net.Start required to be within a function?[/QUOTE]
When you call it, it runs. Basically
net.Start("stp_enabled")
net.WriteBit(bYourBool)
net.Send(ply)
means SEND IT NOW.
So if you don't put it IN a function, it will run that code as soon as the server/client starts up.
If you want to send it as they connect, do it in GM:PlayerInitialSpawn(ply). If you want to send it at any other time, do it then.
Lua is ran top of the file to bottom, then when it's done doing that, certain events in the game cause the functions defined in the files to run, such as GM:Think() or GM:PlayerTakeDamage()
If you put a function outside of an event, it will run while the server is reading the files, and that's usually too early because players won't be connected, etc.
-snip- I'm blind
[QUOTE=bobbleheadbob;47043937]When you call it, it runs. Basically
net.Start("stp_enabled")
net.WriteBit(bYourBool)
net.Send(ply)
means SEND IT NOW.
So if you don't put it IN a function, it will run that code as soon as the server/client starts up.
If you want to send it as they connect, do it in GM:PlayerInitialSpawn(ply). If you want to send it at any other time, do it then.
Lua is ran top of the file to bottom, then when it's done doing that, certain events in the game cause the functions defined in the files to run, such as GM:Think() or GM:PlayerTakeDamage()
If you put a function outside of an event, it will run while the server is reading the files, and that's usually too early because players won't be connected, etc.[/QUOTE]
I see, this is my final output
cl_init.lua
[code]function GM:PlayerBindPress(pl, bind, wasin)
if bind == "gmod_undo" or bind == "undo" then
RunConsoleCommand("+zoom")
timer.CreateEx("ReleaseZoom", 1, 1, RunConsoleCommand, "-zoom")
elseif bind == "+menu_context" then
if pl and pl:OldAlive() then
if pl.m_bThirdPDisabled then
return
end
if pl:Team() == TEAM_UNDEAD and pl.m_bShoulderEnabled then
pl.m_bShoulderEnabled = false
elseif pl:Team() == TEAM_HUMAN and not pl.m_bShoulderEnabled then
pl.m_bShoulderEnabled = true
end
pl.m_bThirdPEnabled = not pl.m_bThirdPEnabled
net.Start("stp_enabled")
net.WriteBit(pl.m_bShoulderEnabled)
net.WriteBit(pl.m_bThirdPEnabled)
net.WriteBit(pl.m_bThirdPDisabled)
net.SendToServer()
end
end
end
net.Receive("stp_enabled",function(length, ply)
ply.m_bShoulderEnabled = net.ReadBit()==1
ply.m_bThirdPEnabled = net.ReadBit()==1
ply.m_bThirdPDisabled = net.ReadBit()==1
end)[/code]
init.lua
[code]net.Receive("stp_enabled",function(len, ply)
ply.m_bShoulderEnabled = net.ReadBit()==1
ply.m_bThirdPEnabled = net.ReadBit()==1
ply.m_bThirdPDisabled = net.ReadBit()==1
end)[/code]
sv_thirdperson.lua
[code]hook.Add( "OnPlayerChangedTeam", "STP_ChangedTeam", function( ply, oldTeam, newTeam )
if ply.m_bThirdPEnabled then
if newteam == TEAM_UNDEAD and oldTeam == TEAM_HUMAN then
ply.m_bShoulderEnabled = false
elseif newteam == TEAM_HUMAN and oldTeam == TEAM_UNDEAD then
ply.m_bShoulderEnabled = true
end
end
net.Start("stp_enabled")
net.WriteBit(ply.m_bShoulderEnabled)
net.WriteBit(ply.m_bThirdPEnabled)
net.WriteBit(ply.m_bThirdPDisabled)
net.Send(ply)
end )[/code]
[QUOTE=ForrestMarkX;47043957]I see, this is my final output
cl_init.lua
[code]function GM:PlayerBindPress(pl, bind, wasin)
if bind == "gmod_undo" or bind == "undo" then
RunConsoleCommand("+zoom")
timer.CreateEx("ReleaseZoom", 1, 1, RunConsoleCommand, "-zoom")
elseif bind == "+menu_context" then
if pl and pl:OldAlive() then
if pl.m_bThirdPDisabled then
return
end
if pl:Team() == TEAM_UNDEAD and pl.m_bShoulderEnabled then
pl.m_bShoulderEnabled = false
elseif pl:Team() == TEAM_HUMAN and not pl.m_bShoulderEnabled then
pl.m_bShoulderEnabled = true
end
pl.m_bThirdPEnabled = not pl.m_bThirdPEnabled
net.Start("stp_enabled")
net.WriteBit(pl.m_bShoulderEnabled)
net.WriteBit(pl.m_bThirdPEnabled)
net.WriteBit(pl.m_bThirdPDisabled)
net.SendToServer()
end
end
end
net.Receive("stp_enabled",function(length, ply)
ply.m_bShoulderEnabled = net.ReadBit()==1
ply.m_bThirdPEnabled = net.ReadBit()==1
ply.m_bThirdPDisabled = net.ReadBit()==1
end)[/code]
init.lua
[code]net.Receive("stp_enabled",function(len, ply)
ply.m_bShoulderEnabled = net.ReadBit()==1
ply.m_bThirdPEnabled = net.ReadBit()==1
ply.m_bThirdPDisabled = net.ReadBit()==1
end)[/code]
sv_thirdperson.lua
[code]hook.Add( "OnPlayerChangedTeam", "STP_ChangedTeam", function( ply, oldTeam, newTeam )
if ply.m_bThirdPEnabled then
if newteam == TEAM_UNDEAD and oldTeam == TEAM_HUMAN then
ply.m_bShoulderEnabled = false
elseif newteam == TEAM_HUMAN and oldTeam == TEAM_UNDEAD then
ply.m_bShoulderEnabled = true
end
end
net.Start("stp_enabled")
net.WriteBit(ply.m_bShoulderEnabled)
net.WriteBit(ply.m_bThirdPEnabled)
net.WriteBit(ply.m_bThirdPDisabled)
net.Send(ply)
end )[/code][/QUOTE]
Should work.
Is there a way to force the player to duck?
I'm asking because I need the player to only be allowed to duck under specific conditions within a function. I'm assuming I'd have to screw around with disallowing and allowing binds, but it'd be cool if there was a way to allow the player to duck using one specific function for it.
[QUOTE=wauterboi;47044153]Is there a way to force the player to duck?
I'm asking because I need the player to only be allowed to duck under specific conditions within a function. I'm assuming I'd have to screw around with disallowing and allowing binds, but it'd be cool if there was a way to allow the player to duck using one specific function for it.[/QUOTE]
Make a player duck:
1. Set duck height to 32
2. Run +Duck
3. Prevent the player from calling -duck indefinitely
Make a player stand:
1. Set duck height to their total height (72 I think)
2. Allow -duck to be called.
3. Run -duck manually.
EDIT:
[quote=You almost]BUT BAWBLEHEAD HOW DO I SET DUCK HEIGHT?[/quote]
Good question.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/SetHullDuck]Player:SetHullDuck[/url]
[QUOTE=bobbleheadbob;47044137]Should work.[/QUOTE]
Doesn't seem to cl_init.lua
"attempt to index local 'ply' (a nil value)"
change it to LocalPlayer()
-snip-
[QUOTE=zerf;47044276]change it to LocalPlayer()[/QUOTE]
Thank you, that worked
[QUOTE=ForrestMarkX;47043026]Because OnPlayerChangedTeam is server-side only apparently, all I really want to do is disable thridperson when you change teams[/QUOTE]
If the VGUI is client-side then you can simply add a clause in the CalcView... Set a local var when they click change-team or if they're dead and the current team isn't the previous team value. Set false when alive again.
Something similar to: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/logic/controlled_toggles.lua.html[/url]
Control it based on cached team value, and alive. So prevent 3rd person continuing if !Alive and Team != CachedTeam then return elseif Alive and Team != CachedTeam then CachedTeam = Team end
Simple toggle; prevents needing networking but I'm not sure how the entire system is coded.
[QUOTE=Willox;47040504]Try modifying the CUserCmd's sidemove variable. It should allow for analogue steering as long as IN_MOVELEFT and IN_MOVERIGHT are not held.
[editline]30th January 2015[/editline]
[code]
hook.Add( "CreateMove", "", function( cmd )
cmd:SetSideMove( math.sin( CurTime() * math.pi * 2 / 10 ) * 400 )
end )
[/code]
I believe -400 and 400 are the bounds for the input when applied to a vehicle's turning, but this could be different in gmod's compilation of the sdk.[/QUOTE]
I went through my code again and I got the steering working flawlessly. I tried SetSideMove but it didn't work so I tried setting +/- binds based on Steering ( and - them on exit vehicle ) and it ended up working. I found another way on top of that but I'm still testing as I'm not sure if it is better or not. With the keybinds I simply had a toggle so it'd only use one at a time, and - before the next...
Going to get this feature finalized and ready for launch!
-snip- For some reason it didn't edit O_o
[QUOTE=Acecool;47046620]I went through my code again and I got the steering working flawlessly. I tried SetSideMove but it didn't work so I tried setting +/- binds based on Steering ( and - them on exit vehicle ) and it ended up working. I found another way on top of that but I'm still testing as I'm not sure if it is better or not. With the keybinds I simply had a toggle so it'd only use one at a time, and - before the next...
Going to get this feature finalized and ready for launch![/QUOTE]
Sidemove definitely works for vehicles. That's how xbox controllers do it. Make sure you are modifying the usercmd before the SetupMove hook is called using either CreateMove clientside or StartCommand shared.
[QUOTE=Acecool;47047588]-snip- For some reason it didn't edit O_o[/QUOTE]
I think there's a limited time span for when new posts get automatically edited into the last one ;)
What's the equivalent of gui.EnableScreenClicker() for keyboard input? I don't want to use MakePopup in this particular case (unless there's a way to undo it).
Sorry, you need to Log In to post a reply to this thread.