Jump to content

bindKey


TorNix~|nR

Recommended Posts

Hello guys, sometimes I need to restart this script to work for some players, sometimes some players can not use

the bind, only when I restart the script

help please?

function shootProjectile()
	if not isTimer(shootCooldown) then
		shootCooldown = setTimer(function() end, 1000, 1)
		local vehicle = getPedOccupiedVehicle(localPlayer)
		-- Only create projectile if we are inside a vehicle
		if getElementModel(vehicle) == 411 then
			local x, y, z = getElementPosition(vehicle)
        	createProjectile(vehicle, 19, x, y, z)
		end
	end
end
bindKey("vehicle_fire", "down", shootProjectile)

 

Link to comment
10 hours ago, TorNix~|nR said:

Hello guys, sometimes I need to restart this script to work for some players, sometimes some players can not use

the bind, only when I restart the script

help please?


function shootProjectile()
	if not isTimer(shootCooldown) then
		shootCooldown = setTimer(function() end, 1000, 1)
		local vehicle = getPedOccupiedVehicle(localPlayer)
		-- Only create projectile if we are inside a vehicle
		if getElementModel(vehicle) == 411 then
			local x, y, z = getElementPosition(vehicle)
        	createProjectile(vehicle, 19, x, y, z)
		end
	end
end
bindKey("vehicle_fire", "down", shootProjectile)

 

vehicle_fire 

is not a key name check the wiki page for bind Key

Link to comment
  • Administrators

@Master_MTA re-read the Wiki, control names are also a valid input here.

You need to trigger bindKey when the client joins / the resource is started. At the moment bindKey is only being triggered when the resource is started.

 

function shootProjectile()
	if not isTimer(shootCooldown) then
		shootCooldown = setTimer(function() end, 1000, 1)
		local vehicle = getPedOccupiedVehicle(localPlayer)
		-- Only create projectile if we are inside a vehicle
		if getElementModel(vehicle) == 411 then
			local x, y, z = getElementPosition(vehicle)
        	createProjectile(vehicle, 19, x, y, z)
		end
	end
end

function setupProjectileBinds()
  bindKey("vehicle_fire", "down", shootProjectile)
end
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), setupProjectileBinds)

 

Edited by LopSided_
  • Thanks 1
Link to comment
14 minutes ago, LopSided_ said:

@Master_MTA re-read the Wiki, control names are also a valid input here.

You need to trigger bindKey when the client joins / the resource is started. At the moment bindKey is only being triggered when the resource is started.

 


function shootProjectile()
	if not isTimer(shootCooldown) then
		shootCooldown = setTimer(function() end, 1000, 1)
		local vehicle = getPedOccupiedVehicle(localPlayer)
		-- Only create projectile if we are inside a vehicle
		if getElementModel(vehicle) == 411 then
			local x, y, z = getElementPosition(vehicle)
        	createProjectile(vehicle, 19, x, y, z)
		end
	end
end

function setupProjectileBinds()
  bindKey("vehicle_fire", "down", shootProjectile)
end
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), setupProjectileBinds)

 

re-read the wiki:

This event is triggered when a resource is started. Please note that this is not triggered the same time as the serverside event onResourceStart is. The event is triggered when any clientside resourcesare started. This means it is triggered when a clientside script is initiated after a download, which includes downloading after join.

Link to comment
  • Administrators

@xFFrozen - and little did he know he'd just made a complete and utter fool of himself. What a pillock you are, sir.

OnClientResourceStart will be triggered when a resource has been fully initialized on the clientside. This means it will trigger;

a) when a player joins the game, and that resource has been fully downloaded

b) when the player is already on the server, and the resource is loaded/restarted

I have attached it to the root of the given resource, which means the event will only trigger for that resource.

xD

 

Link to comment

so this doesn't work?

function shootProjectile()
	if not isTimer(shootCooldown) then
		shootCooldown = setTimer(function() end, 1000, 1)
		local vehicle = getPedOccupiedVehicle(localPlayer)
		-- Only create projectile if we are inside a vehicle
		if getElementModel(vehicle) == 411 then
			local x, y, z = getElementPosition(vehicle)
        	createProjectile(vehicle, 19, x, y, z)
		end
	end
end

function setupProjectileBinds()
  bindKey("vehicle_fire", "down", shootProjectile)
end
addEventHandler("onClientPlayerJoin", getResourceRootElement(getThisResource()), setupProjectileBinds)

 

Link to comment

@Master_MTA alright, guys is this work fine?

function shootProjectile()
	if not isTimer(shootCooldown) then
		shootCooldown = setTimer(function() end, 1000, 1)
		local vehicle = getPedOccupiedVehicle(localPlayer)
		-- Only create projectile if we are inside a vehicle
		if getElementModel(vehicle) == 411 then
			local x, y, z = getElementPosition(vehicle)
        	createProjectile(vehicle, 19, x, y, z)
		end
	end
end

function setupProjectileBinds()
  bindKey("k", "down", shootProjectile)
end
addEventHandler("onClientPlayerJoin", getResourceRootElement(getThisResource()), setupProjectileBinds)
  • Like 1
Link to comment

Guys this doesn't work, any help?

function shootProjectile()
	if not isTimer(shootCooldown) then
		shootCooldown = setTimer(function() end, 1000, 1)
		local vehicle = getPedOccupiedVehicle(localPlayer)
		-- Only create projectile if we are inside a vehicle
		if getElementModel(vehicle) == 411 then
			local x, y, z = getElementPosition(vehicle)
        	createProjectile(vehicle, 19, x, y, z)
		end
	end
end

function setupProjectileBinds()
  bindKey("x", "down", shootProjectile)
end
addEventHandler("onClientPlayerJoin", getResourceRootElement(getThisResource()), setupProjectileBinds)

 

Link to comment
addEventHandler ( 'onClientResourceStart', resourceRoot, function (    )
    bindKey ( 'x', 'down',
        function (    )
            if not ( isTimer ( shootCooldown ) ) then
                local projectileVehicle = getPedOccupiedVehicle ( localPlayer )
                    if ( projectileVehicle and getElementModel ( projectileVehicle ) == 411 ) then
                        local x, y, z = getElementPosition ( projectileVehicle )
                            createProjectile ( projectileVehicle, 19, x, y, z )
                        shootCooldown = setTimer (
                      function (    ) end,
                    1000, 1 )
                end
            end
        end )
    end
)

 

Edited by #,+( _xiRoc[K]; >
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...