Jump to content

[HELP]VİP JETPACK


Electro88

Recommended Posts

Hello everyone i find vip jetpack system and i add bind key for jetpack but no work

bad argument @ 'bindKey' [Expected player at argument 1, got string 'j'

  
    bindKey ( "J", "down",  
    function ( thePlayer ) 
        if doesPedHaveJetPack ( thePlayer ) then -- If the player have a jetpack already, remove it 
            removePedJetPack ( thePlayer ) -- Remove the jetpack 
            return -- And stop the function here 
        end 
  
     -- Otherwise, give him one if he has access 
  
     local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) -- get his account name 
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "V.İ.P" ) ) then -- Does he have access to Admin functions? 
          if not doesPedHaveJetPack ( thePlayer ) then -- If the player doesn't have a jetpack give it. 
               givePedJetPack ( thePlayer )  -- Give the jetpack 
          end 
     end 
end 
) 

where the problem ?

Link to comment

The way you use bindKey is clientsided, not serversided.

You have to use player for 1. argument.

You can put bindKey in onPlayerJoin like

addEventHandler ( "onPlayerJoin", root, function ( ) 
     bindKey ( source, "J", "down", giveJetpack_func ) 
end ) 
  
function giveJetpack_func ... 

Oh and you can delete the 2nd doesPedHaveJetPack.

If you have a jetpack it gets removed and the function stops.

So you can't get to row 13 with an Jetpack, thats why its totally useless.

Edited by Guest
Link to comment

Try that

addEventHandler ("onResourceStart", resourceRoot, 
function () 
    for index, player in ipairs (getElementsByType ("player")) do 
        bindKey ( player, "J", "down", toggleJetpack ) 
    end 
end) 
  
function toggleJetpack( thePlayer ) 
  --give him one if he has access 
    local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) -- get his account name 
    if isObjectInACLGroup ("user."..accName, aclGetGroup ( "V.İ.P" ) ) then -- Does he have access to Admin functions? 
        if not doesPedHaveJetPack ( thePlayer ) then -- If the player doesn't have a jetpack give it. 
            givePedJetPack ( thePlayer )  -- Give the jetpack 
        else 
            removePedJetPack ( thePlayer ) 
        end 
    end 
end 

Edited by Guest
Link to comment

@KariiiM:

With your code it gets binded only on resource start.

If a player joines after the resource startet he won't get the bind for jetpack.

Also there is no need for ipairs, it just slows the script for no reason.

Better use:

local players = getElementsByType ( "player" ) 
for i=1, #players do 
   bindKey ( players[i] ... 
   ... 
end  

or

for index, player in pairs ( getElementsByType ( "player" ) do 

@Electro88:

You can use row 1-6 in his code if you want to (re-)start the Resource while playing.

Link to comment

I cleared it abit,Full code:

addEventHandler ("onPlayerLogin", root, 
function () 
    bindKey ( source, "P", "down", toggleJetpack ) 
end) 
  
addEventHandler ("onResourceStart", resourceRoot, 
function () 
    for index, player in ipairs (getElementsByType ("player")) do 
        bindKey ( player, "J", "down", toggleJetpack ) 
    end 
end) 
  
function toggleJetpack( thePlayer ) 
  --give him one if he has access 
    local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) -- get his account name 
    if isObjectInACLGroup ("user."..accName, aclGetGroup ( "V.İ.P" ) ) then -- Does he have access to Admin functions? 
        if not doesPedHaveJetPack ( thePlayer ) then -- If the player doesn't have a jetpack give it. 
            givePedJetPack ( thePlayer )  -- Give the jetpack 
        else 
            removePedJetPack ( thePlayer ) 
        end 
    end 
end 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...