I have a double jump lua, needs a tweak.

Okay, I have a code for double jump, but I want it to be for an item function, not local function.

[LUA]local function doublejump(ply, key)
if key == IN_JUMP then
if !ply:IsOnGround() then
if ply.FirstJump == 1 then
ply:SetVelocity(Vector(0,0,200) + Vector(0,0,-1*ply:GetVelocity().z))
ply.FirstJump = 0
end
else
ply.FirstJump = 1
end
end
end
hook.Add(“KeyPress”, “doublejump”, doublejump)[/LUA]

I tried something like below with no luck, any ideas what I’m doing wrong? I feel like its so simple.

[LUA]if item.Equipped then
function ITEM:doublejump(ply, key)[/LUA]



if ply:PS_HasItemEquipped("filename") then
--code
end


Still having trouble… hopefully the full code will help…

File Name: jumppack.lua

[LUA]ITEM.Name = ‘Jump Pack’
ITEM.Price = 2500
ITEM.Model = ‘models/xqm/jetengine.mdl’
ITEM.Bone = ‘ValveBiped.Bip01_Spine2’

function ITEM:OnEquip(ply, modifications)
ply:PS_AddClientsideModel(self.ID)
end

function ITEM:OnHolster(ply)
ply:PS_RemoveClientsideModel(self.ID)
end
function ITEM:ModifyClientsideModel(ply, model, pos, ang)
model:SetModelScale(0.5, 0)
pos = pos + (ang:Right() * 7) + (ang:Forward() * 6)

return model, pos, ang

end

if ply:PS_HasItemEquipped(“filename”) then
local function doublejump(ply, key)
if key == IN_JUMP then
if !ply:IsOnGround() then
if ply.FirstJump == 1 then
ply:SetVelocity(Vector(0,0,200) + Vector(0,0,-1*ply:GetVelocity().z))
ply.FirstJump = 0
else
end
else
ply.FirstJump = 1
end
end
end
hook.Add(“KeyPress”, “doublejump”, doublejump)
end[/LUA]

Rename jumppack.lua to filename.lua

Other way around, replace “filename” with “jumppack”

I guess I should’ve mentioned this; “filename” needs to be the ACTUAL filename

I know, I did that, did not work. You are able to equip the jump pack but it does not double jump.


ITEM.Name = 'Double Jump'
ITEM.Price = 25000
ITEM.Model = 'models/props_junk/GlassBottle01a.mdl'
ITEM.NoPreview = true
ITEM.AllowedUserGroups = { "vip" , "moderator" , "admin" , "superadmin" }
ITEM.SingleUse = false
function ITEM:OnEquip(ply, modifications)
    ply.CanDJump = 1
end
function ITEM:OnSell(ply)
    ply.CanDJump = 0
end
function ITEM:OnHolster(ply, modifications)
    ply.CanDJump = 0
end
if SERVER then
local function doubleJump(ply, key)
    if key == IN_JUMP then
        if !ply:IsOnGround() then
            if ply.FirstJump == 1 and ply.CanDJump == 1 and ply:GetVelocity().z > 0 then
                ply:SetVelocity(Vector(0,0,200))
                ply.FirstJump = 0
            end
        else
            ply.FirstJump = 1
        end
    end
end
hook.Add("KeyPress", "doublejump", doubleJump)
end


Found on some random forum in the depths of Google (Took me 2 minutes): http://www.garrystech.com/topic/212-double-jump-point-shop-item-ttt/

Edit: Oh yeah, Niandra the one you posted doesn’t work, just gonna post the error as OP doesn’t seem like he knows what hes doing (No offence OP)



[ERROR] addons/pointshop-master/lua/items/accessories/jumppack.lua:21: attempt to index global 'ply' (a nil value)
  1. unknown - addons/pointshop-master/lua/items/accessories/3jump.lua:21
   2. include - [C]:-1
    3. LoadItems - addons/pointshop-master/lua/sh_pointshop.lua:105
     4. unknown - addons/pointshop-master/lua/autorun/pointshop.lua:35


Thank you very much. :dance: