Hey guys, I am an armature lua coder and I have been trying to make buy able pets for the pointshop on my server.
Here is the code for it:
ITEM.Name = 'Fast Headcrab' ITEM.Price = 1000 ITEM.Model = 'models/headcrab.mdl' ITEM.SingleUse = false function ITEM:OnEquip(ply) pet = ents.Create("npc_headcrab_fast") pet:SetOwner(ply) pet:SetMaxHealth(150) pet:SetHealth(150) pet:AddEntityRelationship(ply, 3, 99) for k,v in pairs(player.GetAll()) do if(v != ply) then pet:AddEntityRelationship(v, 4, 99) end end pet:SetPos(ply:GetPos()+Vector(0,0,10)) pet:SetCollisionGroup(COLLISION_GROUP_WORLD) pet:Spawn() pet:Activate() checkpet = 1 timer.Create("Pet_Follow", 0.1, 0, Follow, ply) end function Follow(ply) if checkpet == 1 then if pet:IsValid() then pet:SetLastPosition(pet:GetOwner():GetPos()) pet:SetSchedule(71) end end end function ITEM:OnHolster(ply) if checkpet == 1 then if pet:IsValid() then pet:Remove() end end end
It spawns the headcrab fine but it doesn’t set its health. Also, if someone else buys the headcrab while I (or anyone else) has it equipped, it will stop following me and if they holster it while someone else’s headcrab is out, it disappears.
I am also trying to make a Double Jump power up, here is its code:
ITEM.Name = 'Double Jump' ITEM.Price = 600 ITEM.Model = 'models/Items/battery.mdl' ITEM.NoPreview = false function ITEM:OnEquip(ply, modifications) end function ITEM:Think(ply) if ply:Health() >=1 then if IsValid(ply) then 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 = -1 * 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 end end function ITEM:OnHolster(ply) end
This has a similar problem where if two people are wearing it it doesn’t work properly. You both have to jump at the same time and then only one of you can jump until the other lands on the ground.
I understand why I get these problems, I am just clueless on how to fix them.