• So... This LUA pointshop code works, but not well.. Any Ideas?
    20 replies, posted
So it works as in no errors. However you don't jump any higher on the second jump. Maybe it doesn't work? You press space twice and it does nothing but kinda moves the screen a bit as if you were going to double jump. But you don't jump off of the first jump. [CODE]ITEM.Name = 'Double Jump Test' ITEM.Price = 600 ITEM.Model = 'models/Items/battery.mdl' ITEM.NoPreview = true function ITEM:OnEquip(ply, modifications) end function ITEM:Think(ply) if !IsValid( ply ) || !ply:Alive() then return end if ply:IsOnGround() then Jumps=0 end if ply:KeyPressed(IN_JUMP) then Jumps = (Jumps + 1) if Jumps==2 then local ang = ply:GetAngles() local forward, right = ang:Forward(), ang:Right() local vel = -ply:GetVelocity() -- Nullify current velocity vel = vel + Vector(0, 0, 300) -- Add vertical force local spd = ply:GetMaxSpeed() if ply:KeyDown(IN_FORWARD) then vel = vel + forward * spd elseif ply:KeyDown(IN_BACK) then vel = vel - forward * spd end if ply:KeyDown(IN_MOVERIGHT) then vel = vel + right * spd elseif ply:KeyDown(IN_MOVELEFT) then vel = vel - right * spd end ply:SetVelocity(vel) end end end function ITEM:OnHolster(ply) end[/CODE]
Lua
The think hook gets called about 60 times a second or something. You'll probably need to delay your checks or only run your code when IN_JUMP keydowns.
uh. I just put the code into a think hook and dragged and dropped it into my dev server, and it works fine for me.
How does one fix that? :/[QUOTE=Khub;45310215]The think hook gets called about 60 times a second or something. You'll probably need to delay your checks or only run your code when IN_JUMP keydowns.[/QUOTE]
[QUOTE=tommytomtoo;45310284]How does one fix that? :/[/QUOTE] Ignore him, he's wrong. I think it might be some incompatibility with your gamemode, because the code works just fine for me in sandbox.
Apparently it works. I just want the second jump to give a little boost.Like on the second press of space it jumps higher than the first. And in my server when I press jump twice I jump in the same space(I press space twice and I move up a millimeter above the original jump. It's not enough. It's nothing at all :/[QUOTE=tommytomtoo;45310284]How does one fix that? :/[/QUOTE] [editline]6th July 2014[/editline] Yea it's incompatibility. So how would I make it ,like I said in the above post, to make the second jump more of a boost off of pressing space twice?[QUOTE=CallMePyro;45310303]Ignore him, he's wrong. I think it might be some incompatibility with your gamemode, because the code works just fine for me in sandbox.[/QUOTE]
where you see [LUA] vel = vel + Vector(0, 0, 300) -- Add vertical force [/LUA] change the 300 to some bigger number, like 3000, and see if it makes a difference.
It didn't, we tried. The velocity was correct and passed over to ply:SetVelocity, but the player didn't move an inch off. Weird.
Try [lua]hook.Add("KeyPress", "DoubleJump", function(pl, k) if not pl or not pl:IsValid() or k~=2 then return end if not pl.Jumps or pl:IsOnGround() then pl.Jumps=0 end if pl.Jumps==2 then return end pl.Jumps = pl.Jumps + 1 if pl.Jumps==2 then local ang = pl:GetAngles() local forward, right = ang:Forward(), ang:Right() local vel = -1 * pl:GetVelocity() -- Nullify current velocity vel = vel + Vector(0, 0, 300) -- Add vertical force local spd = pl:GetMaxSpeed() if pl:KeyDown(IN_FORWARD) then vel = vel + forward * spd elseif pl:KeyDown(IN_BACK) then vel = vel - forward * spd end if pl:KeyDown(IN_MOVERIGHT) then vel = vel + right * spd elseif pl:KeyDown(IN_MOVELEFT) then vel = vel - right * spd end pl:SetVelocity(vel) end end)[/lua] Instead of: [lua]if !IsValid( ply ) || !ply:Alive() then return end if ply:IsOnGround() then Jumps=0 end if ply:KeyPressed(IN_JUMP) then Jumps = (Jumps + 1) if Jumps==2 then local ang = ply:GetAngles() local forward, right = ang:Forward(), ang:Right() local vel = -ply:GetVelocity() -- Nullify current velocity vel = vel + Vector(0, 0, 300) -- Add vertical force local spd = ply:GetMaxSpeed() if ply:KeyDown(IN_FORWARD) then vel = vel + forward * spd elseif ply:KeyDown(IN_BACK) then vel = vel - forward * spd end if ply:KeyDown(IN_MOVERIGHT) then vel = vel + right * spd elseif ply:KeyDown(IN_MOVELEFT) then vel = vel - right * spd end ply:SetVelocity(vel) end end[/lua]
Doesn't work [QUOTE=Baron von Hax;45311977]Try [lua]hook.Add("KeyPress", "DoubleJump", function(pl, k) if not pl or not pl:IsValid() or k~=2 then return end if not pl.Jumps or pl:IsOnGround() then pl.Jumps=0 end if pl.Jumps==2 then return end pl.Jumps = pl.Jumps + 1 if pl.Jumps==2 then local ang = pl:GetAngles() local forward, right = ang:Forward(), ang:Right() local vel = -1 * pl:GetVelocity() -- Nullify current velocity vel = vel + Vector(0, 0, 300) -- Add vertical force local spd = pl:GetMaxSpeed() if pl:KeyDown(IN_FORWARD) then vel = vel + forward * spd elseif pl:KeyDown(IN_BACK) then vel = vel - forward * spd end if pl:KeyDown(IN_MOVERIGHT) then vel = vel + right * spd elseif pl:KeyDown(IN_MOVELEFT) then vel = vel - right * spd end pl:SetVelocity(vel) end end)[/lua] Instead of: [lua]if !IsValid( ply ) || !ply:Alive() then return end if ply:IsOnGround() then Jumps=0 end if ply:KeyPressed(IN_JUMP) then Jumps = (Jumps + 1) if Jumps==2 then local ang = ply:GetAngles() local forward, right = ang:Forward(), ang:Right() local vel = -ply:GetVelocity() -- Nullify current velocity vel = vel + Vector(0, 0, 300) -- Add vertical force local spd = ply:GetMaxSpeed() if ply:KeyDown(IN_FORWARD) then vel = vel + forward * spd elseif ply:KeyDown(IN_BACK) then vel = vel - forward * spd end if ply:KeyDown(IN_MOVERIGHT) then vel = vel + right * spd elseif ply:KeyDown(IN_MOVELEFT) then vel = vel - right * spd end ply:SetVelocity(vel) end end[/lua][/QUOTE]
Maybe the reason this isn't working is because there's nothing to indicate that the user should gain this double jump script upon equip/buy. A solution you could try is to say the player can double jump if GetNWBool says so, and then use SetNWBool on on equip/holster.
How?[QUOTE=NiandraLades;45312688]Maybe the reason this isn't working is because there's nothing to indicate that the user should gain this double jump script upon equip/buy. A solution you could try is to say the player can double jump if GetNWBool says so, and then use SetNWBool on on equip/holster.[/QUOTE]
[QUOTE=NiandraLades;45312688]Maybe the reason this isn't working is because there's nothing to indicate that the user should gain this double jump script upon equip/buy. A solution you could try is to say the player can double jump if GetNWBool says so, and then use SetNWBool on on equip/holster.[/QUOTE] It's running in ITEM:Think, I believe that means the code only runs while the item is equipped. I had him test a few variations of the code, made something similar to Baron Von Hax's suggestion (so that the velocity update code gets executed on second IN_JUMP keydown), even printed the set velocity into chat. It was being set to correct values in the right moment. It's probably an issue with ply:SetVelocity, we must be using it wrong.
[QUOTE=tommytomtoo;45310129]You press space twice and it does nothing but kinda moves the screen a bit as if you were going to double jump.[/QUOTE] Check if it run serverside
hmmmm
[code] ITEM.Name = 'Double Jump Test' ITEM.Price = 600 ITEM.Model = 'models/Items/battery.mdl' ITEM.NoPreview = true function ITEM:OnEquip(ply, modifications) ply:SetNWBool("DoubleJump",true) end function ITEM:OnHolster(ply) ply:SetNWBool("DoubleJump",false) end [/code] [code] hook.Add("KeyPress", "DoubleJump", function(pl, k) if ply:GetNWBool("DoubleJump", true) then if not pl or not pl:IsValid() or k~=2 then return end if not pl.Jumps or pl:IsOnGround() then pl.Jumps=0 end if pl.Jumps==2 then return end pl.Jumps = pl.Jumps + 1 if pl.Jumps==2 then local ang = pl:GetAngles() local forward, right = ang:Forward(), ang:Right() local vel = -1 * pl:GetVelocity() -- Nullify current velocity vel = vel + Vector(0, 0, 300) -- Add vertical force local spd = pl:GetMaxSpeed() if pl:KeyDown(IN_FORWARD) then vel = vel + forward * spd elseif pl:KeyDown(IN_BACK) then vel = vel - forward * spd end if pl:KeyDown(IN_MOVERIGHT) then vel = vel + right * spd elseif pl:KeyDown(IN_MOVELEFT) then vel = vel - right * spd end pl:SetVelocity(vel) end end end) [/code]
[lua]if ply:GetNWBool("DoubleJump", true) then[/lua] Would give everyone double jump because if they don't have it set then it's true. You'd need to change the true to false.
[QUOTE=Jarva;45320627][lua]if ply:GetNWBool("DoubleJump", true) then[/lua] Would give everyone double jump because if they don't have it set then it's true. You'd need to change the true to false.[/QUOTE] Is that specific to NWBools? Because normally nil == false in [B]if[/B] statements and even if it has to return a bool it should return false.
[QUOTE=Dinnanid;45321232]Is that specific to NWBools? Because normally nil == false in [B]if[/B] statements and even if it has to return a bool it should return false.[/QUOTE] No, by default it is false. But they've stated it should return true if nil, with the second argument.
[CODE]ITEM.Name = 'Double Jump Test' ITEM.Price = 600 ITEM.Model = 'models/Items/battery.mdl' ITEM.NoPreview = true function ITEM:OnEquip(ply, modifications) ply:SetNWBool("DoubleJump",true) hook.Add("KeyPress", "DoubleJump", function(pl, k) if ply:GetNWBool("DoubleJump") then if not pl or not pl:IsValid() or k~=2 then return end if not pl.Jumps or pl:IsOnGround() then pl.Jumps=0 end if pl.Jumps==2 then return end pl.Jumps = pl.Jumps + 1 if pl.Jumps==2 then local ang = pl:GetAngles() local forward, right = ang:Forward(), ang:Right() local vel = -1 * pl:GetVelocity() -- Nullify current velocity vel = vel + Vector(0, 0, 180) -- Add vertical force local spd = pl:GetMaxSpeed() if pl:KeyDown(IN_FORWARD) then vel = vel + forward * spd elseif pl:KeyDown(IN_BACK) then vel = vel - forward * spd end if pl:KeyDown(IN_MOVERIGHT) then vel = vel + right * spd elseif pl:KeyDown(IN_MOVELEFT) then vel = vel - right * spd end pl:SetVelocity(vel) end end end) end function ITEM:OnHolster(ply) ply:SetNWBool("DoubleJump",false) hook.Remove("KeyPress", "DoubleJump") end function ITEM:Think(ply) end[/CODE]
Sorry, you need to Log In to post a reply to this thread.