TorNix~|nR Posted August 31, 2017 Share Posted August 31, 2017 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
Master_MTA Posted September 1, 2017 Share Posted September 1, 2017 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 Lpsd Posted September 1, 2017 Administrators Share Posted September 1, 2017 (edited) @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 September 1, 2017 by LopSided_ 1 Link to comment
xFFrozen Posted September 1, 2017 Share Posted September 1, 2017 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 Lpsd Posted September 1, 2017 Administrators Share Posted September 1, 2017 @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. Link to comment
TorNix~|nR Posted September 1, 2017 Author Share Posted September 1, 2017 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
TorNix~|nR Posted September 1, 2017 Author Share Posted September 1, 2017 @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) 1 Link to comment
DiGiTal Posted September 1, 2017 Share Posted September 1, 2017 yea that is it will works. Link to comment
TorNix~|nR Posted September 1, 2017 Author Share Posted September 1, 2017 Okay thank you, I will test it soon, ty Link to comment
TorNix~|nR Posted September 5, 2017 Author Share Posted September 5, 2017 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
Rockyz Posted September 5, 2017 Share Posted September 5, 2017 (edited) 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 September 5, 2017 by #,+( _xiRoc[K]; > Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now