• Help - Check if player has item equiped. [POINTSHOP]
    5 replies, posted
I want you to only execute a function if the pointshop item is equipped. Pointshop item code: [CODE]ITEM.Name = 'Habilidade de Empurrar Pessoas (testes)' ITEM.Price = 100000 ITEM.Model = 'models/props_junk/garbage_glassbottle003a.mdl' function ITEM:OnEquip(ply, modifications) end function ITEM:OnHolster(ply) end[/CODE] Item function code: [CODE]if (CLIENT) then return end local PushSound = { "physics/body/body_medium_impact_hard1.wav", "physics/body/body_medium_impact_hard2.wav", "physics/body/body_medium_impact_hard3.wav", "physics/body/body_medium_impact_hard5.wav", "physics/body/body_medium_impact_hard6.wav", "physics/body/body_medium_impact_soft5.wav", "physics/body/body_medium_impact_soft6.wav", "physics/body/body_medium_impact_soft7.wav", } local push = {} hook.Add( "KeyPress", "ussy ussy ur a pussy", function( ply, key ) if key == IN_USE and !(push[ply:UserID()]) and ply:PS_HasItemEquipped('empurra') then local ent = ply:GetEyeTrace().Entity if ply and ply:IsValid() and ent and ent:IsValid() then if ply:IsPlayer() and ent:IsPlayer() then if ply:GetPos():Distance( ent:GetPos() ) <= 100 then if ent:Alive() and ent:GetMoveType() == MOVETYPE_WALK then ply:EmitSound( PushSound[math.random(#PushSound)], 100, 100 ) local velAng = ply:EyeAngles():Forward() ent:SetVelocity( velAng * 500 ) ent:ViewPunch( Angle( math.random( -30, 30 ), math.random( -30, 30 ), 0 ) ) push[ply:UserID()] = true timer.Simple( 0.1, function() push[ply:UserID()] = false end ) end end end end end end)[/CODE] Why this is not working?
That code is.. messy, to say the least Lots of unnecessary checks (That will always return true), and there's also no need to have so many if statements, you could fit it all in 2 [lua] hook.Add( "KeyPress", "ussy ussy ur a pussy", function( ply, key ) if key == IN_USE and not push[ply:UserID()] and ply:PS_HasItemEquipped('empurra') then local ent = ply:GetEyeTrace().Entity if IsValid( ent ) and ent:IsPlayer() and ent:Alive() and ( ply:GetPos():Distance( ent:GetPos() ) <= 100 ) and ent:GetMoveType() == MOVETYPE_WALK then ply:EmitSound( PushSound[math.random(#PushSound)], 100, 100 ) local velAng = ply:EyeAngles():Forward() ent:SetVelocity( velAng * 500 ) ent:ViewPunch( Angle( math.random( -30, 30 ), math.random( -30, 30 ), 0 ) ) push[ply:UserID()] = true timer.Simple( 0.1, function() push[ply:UserID()] = false end ) end end end )[/lua] Also what exactly isn't working?
after i add ply:PS_HasItemEquipped('empurra') this stop working
[QUOTE=LeShift;52128965]after i add ply:PS_HasItemEquipped('empurra') this stop working[/QUOTE] Then you don't have the item equipped (probably) Have you tried printing the result of [B] ply:PS_HasItemEquipped('empurra')[/B]?
I tried it: [CODE]ITEM.Name = 'Habilidade de Empurrar Pessoas (testes)' ITEM.Price = 100000 ITEM.Model = 'models/props_junk/garbage_glassbottle003a.mdl' function ITEM:OnEquip(ply, modifications) ply:PS_Notify(ply:PS_HasItemEquipped('empurra')) end function ITEM:OnHolster(ply) end[/CODE] but returned it for server console: [ERROR] addons/pointshop-master/lua/pointshop/sv_player_extension.lua:493: invalid value (boolean) at index 1 in table for 'concat' 1. concat - [C]:-1 2. PS_Notify - addons/pointshop-master/lua/pointshop/sv_player_extension.lua:493 3. OnEquip - addons/pointshop-master/lua/pointshop/items/powerups/empurra.lua:6 4. unknown - addons/pointshop-master/lua/pointshop/sv_player_extension.lua:19
PS_Notify receives a string for its argument, not a boolean. But why are you checking it there? Add a simple [B]print( ply:PS_HasItemEquipped( "empurra" ) )[/B] inside your hook
Sorry, you need to Log In to post a reply to this thread.