• Making the player fly.. ;(
    11 replies, posted
I just cant get this to work!! Can someone help me? Please? Thanks. [lua] hook.Add( "Think", "Move the player", function() if (CLIENT) then ply = LocalPlayer() local speed = (ply:GetVelocity().x + ply:GetVelocity().y + ply:GetVelocity().z)/3 local call0er = ply:GetVelocity() * -1 + ply:GetAimVector() * -1000 if speed > 10 && !ply:IsOnGround() then addforcer( call0er, ply ) end end end) if (SERVER) then function addforcer(speeed,ply) ply:SetVelocity(speeed) end end [/lua]
Looks like a Trojan.
What? [editline]02:25PM[/editline] If it is, it certainly fails, because it dosent work. The error log. Hook 'Move the player' Failed: :5: attempt to call method 'SetVelocity' (a nil value) Hook 'Move the player' Failed: :6: attempt to call global 'addforce' (a nil value) Hook 'Move the player' Failed: :11: attempt to call method 'SetVelocity' (a nil value) Hook 'Move the player' Failed: :11: attempt to call method 'SetVelocity' (a nil value) Saving achievements... :3: attempt to index global 'SWEP' (a nil value) Saving achievements... Hook 'Move the player' Failed: :11: attempt to call method 'SetVelocity' (a nil value) Hook 'Move the player' Failed: :7: attempt to call global 'addforcer' (a nil value)
Ignore him. I'll solve this for you in one line: ply:SetMoveType(MOVETYPE_FLYGRAVITY) Or just use MOVETYPE_FLY. (refer to [url]http://wiki.garrysmod.com/?title=Movetype[/url])
Hook 'Move the player' Failed: :11: attempt to call method 'SetVelocity' (a nil value)
Nonono, don't use any of the shit you have, just set the move type.
Post the line of code, do you have to use SetVelocity? As far as I know SetVelocity requires a vector. Edit: [QUOTE=Entoros]Nonono, don't use any of the shit you have, just set the move type. [/QUOTE] What he said. [lua]function LolMove( pl ) ply:SetMoveType(MOVETYPE_FLY) end[/lua]
whaaa? Please explain.
Oh.... well here is my code. [lua] hook.Add( "Think", "Move the player", function() if (CLIENT) then local ply = LocalPlayer() local speed = (ply:GetVelocity().x + ply:GetVelocity().y + ply:GetVelocity().z)/3 local call0er = ply:GetVelocity() * -1 + ply:GetAimVector() * -1000 if speed > 10 && !ply:IsOnGround() then addforce( call0er, ply ) end end end) if (SERVER) then function addforce(speeed,ply) ply:SetMoveType(MOVETYPE_FLYGRAVITY) ply:SetVelocity(speeed) end end [/lua] Hey, where'd automerge go? Anyway, i simply couldnt find any other way of applying force. If you could tell me one, i would like it. Thanks. [QUOTE=BastinkaLive;16377863]Post the line of code, do you have to use SetVelocity? As far as I know SetVelocity requires a vector. Edit: What he said. [lua]function LolMove( pl ) ply:SetMoveType(MOVETYPE_FLY) end[/lua][/QUOTE] So if the player is moving, and he is on the ground, he'll get -1000 units of force applyed to his view angle? Edit: I just realized. My code makes no sence. I need to change if speed > 10 && !ply:IsOnGround() then to if ply:KeyPressed (KEY_W) then. Sorry. I was just using that as a sort of place holder :D Edit: ok [lua] function stuff() if (CLIENT) then local ply = LocalPlayer() local speed = (ply:GetVelocity().x + ply:GetVelocity().y + ply:GetVelocity().z)/3 local call0er = ((ply:GetVelocity() * -1) + ply:GetAimVector()) * -1000 if ply:KeyPressed( KEY_G ) then addforce( call0er, ply ) end end end function addforce(speeed,ply) if (SERVER) then ply:SetMoveType(MOVETYPE_FLYGRAVITY) ply:SetVelocity(speeed) end end hook.Add( "Think", "Move the player", stuff) [/lua]
Ok. Here's what you need to do. [b]Remove all of the code you have.[/b] Use this instead (on the server): [code]for _,v in ipairs(player.GetAll()) do v:SetMoveType(MOVETYPE_FLYGRAVITY) end[/code] And there you go, everyone's flying.
I'm verry sorry. I never told you guys what i wanted, i wasnt thinking, im sorry. Can you tell me why the code i have above dosent work? the code right above yours. Although that code, entoros is cool too :D. Again, im sorry, i didnt explain what i wanted to do. I have also tryed this [lua] function clientsideshit() if (CLIENT) then ply = LocalPlayer() if ply:KeyPressed( IN_JUMP ) then angle = ply:GetAimVector() * -1 serversideshit(ply, angle) end end end function serversideshit(playor, angul) playor:SetVelocity(Vector(0,0,1000)) end hook.Add( "Think", "Flyingg", clientsideshit) [/lua] but it errors [code] Hook 'Flyingg' Failed: :12: attempt to call method 'SetVelocity' (a nil value) [/code]
[QUOTE=bobthe2lol;16378209]I'm verry sorry. I never told you guys what i wanted, i wasnt thinking, im sorry. Can you tell me why the code i have above dosent work? the code right above yours. Although that code, entoros is cool too :D. Again, im sorry, i didnt explain what i wanted to do. I have also tryed this [lua] function clientsideshit() if (CLIENT) then ply = LocalPlayer() if ply:KeyPressed( IN_JUMP ) then angle = ply:GetAimVector() * -1 serversideshit(ply, angle) end end end function serversideshit(playor, angul) playor:SetVelocity(Vector(0,0,1000)) end hook.Add( "Think", "Flyingg", clientsideshit) [/lua] but it errors [code] Hook 'Flyingg' Failed: :12: attempt to call method 'SetVelocity' (a nil value) [/code][/QUOTE] Fix is here. [lua] function clientsideshit() if (CLIENT) then ply = LocalPlayer() if ply:KeyPressed( IN_JUMP ) then angle = ply:GetAimVector() * -1 --serversideshit(ply, angle) end else pl:SetVelocity(Vector(0,0,1000)) -- Server side end end hook.Add( "Think", "Flyingg", clientsideshit) [/lua]
Sorry, you need to Log In to post a reply to this thread.