Jump to content

JetPack


SkiZo

Recommended Posts

addCommandHandler ( "jp",
    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 ( "Admin" ) ) 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
)

How Can I Add bindKey ?? 
Keep the command & and bindKey "j" 
?? Thanks :D

Link to comment
function JetPack(thePlayer)
	if doesPedHaveJetPack(thePlayer) then -- Check if the player already has a jetpack.
		removePedJetPack(thePlayer) -- Remove the jetpack if he has one.
		return -- And stop the function here.
	end
	
     -- Otherwise, give him a jetpack if he is an admin.
	local accName = getAccountName(getPlayerAccount(thePlayer)) -- Get his account name.
	if isObjectInACLGroup("user."..accName, aclGetGroup("Admin")) then -- Check if he's admin.
		if not doesPedHaveJetPack(thePlayer) then -- If the player doesn't have a jetpack, give it.
			givePedJetPack(thePlayer)  -- Give him a jetpack.
		end
	end
end
addCommandHandler("jp", JetPack)

-- Bind the key here for every player as soon as he joins your server.
function bindKeys()
	bindKey(source, "j", "down", JetPack)
addEventHandler("onPlayerJoin", root, bindKeys)

 

Edited by koragg
Link to comment

@koragg's code omits a necessary 'end' between the lines 19 and 20.

The correct version, plus additional functionality to bind the key to people already connected (not those who join after the resource is running)

-- Bind the key here for every player as soon as he joins your server.
function bindKeys()
  bindKey(source, "j", "down", "jp") -- bind key to command 'jp' so that the bind can be changed in MTA settings > binds
end
addEventHandler("onPlayerJoin", root, bindKeys)

-- Bind the key here for every player already connected to your server.
for k, v in ipairs(getElementsByType("player")) do -- loop through already connected players
  bindKey(v, "j", "down", "jp") -- bind key to command 'jp'
end
Edited by MrTasty
  • Like 1
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...