victortp Posted June 8, 2013 Share Posted June 8, 2013 Hello, i need help to create a script with time to use. If i use the command "/command" i have to wait "x" seconds to use it again. Ex: addCommandHandler("kitarmas", true) giveWeapon(source, 4, 200, true) giveWeapon(source, 24, 200, true) end Thx and sorry for my bad english. Link to comment
Blaawee Posted June 8, 2013 Share Posted June 8, 2013 (edited) local status = { }; local timeToWaitFor = 5; addCommandHandler( 'kitarmas', function( player, _, weapon, ammo ) if status[ player ] then return outputChatBox( 'You have to wait '.. timeToWaitFor..' second', player, 255, 0, 0, true ); end if not weapon and not ammo then return outputChatBox( 'Syntex /kitarmas [weapon] [ammo]', player, 255, 0, 0, true ); end giveWeapon( player, tonumber( weapon ), tonumber( ammo ), true ); status[ player ] = true; setTimer( function( ) status[ player ] = false end, timeToWaitFor * 1000, 1 ) end ); Edited June 8, 2013 by Guest Link to comment
victortp Posted June 8, 2013 Author Share Posted June 8, 2013 Thank you @Blaawee, but it's not working for me Link to comment
victortp Posted June 8, 2013 Author Share Posted June 8, 2013 The script loads fine, start: Resource 'kitarmas' started but dont show 'You have to wait '.. timeToWaitFor..' second' or 'Syntex /kitarmas [weapon] [ammo]' and don't give anny gun ;s I already put the weapon/ammo id. Link to comment
Blaawee Posted June 8, 2013 Share Posted June 8, 2013 it's working fine with me, make sure it's server side type. Link to comment
victortp Posted June 8, 2013 Author Share Posted June 8, 2013 I'm using Dayz mta source, is it the problem? Link to comment
Blaawee Posted June 8, 2013 Share Posted June 8, 2013 I don't think so, copy the code again. Link to comment
victortp Posted June 8, 2013 Author Share Posted June 8, 2013 Ok, its working.. but i want to set the weapons that will give.. ex: 1 desert eagle - 200 ammo, 1 ak-47 - 400 ammo.. Link to comment
Blaawee Posted June 8, 2013 Share Posted June 8, 2013 local status = { }; local timeToWaitFor = 5; addCommandHandler( 'kitarmas', function( player, _, weapon, ammo ) if status[ player ] then return outputChatBox( 'You have to wait '.. timeToWaitFor..' second', player, 255, 0, 0, true ); end if not weapon and not ammo then return outputChatBox( 'Syntex /kitarmas [weapon] [ammo]', player, 255, 0, 0, true ); end giveWeapon( player, getWeaponIDFromName( weapon ), tonumber( ammo ), true ); outputChatBox ( 'You got a ' .. getWeaponIDFromName( weapon ), player, 0, 255, 0, true ); status[ player ] = true; setTimer( function( ) status[ player ] = false end, timeToWaitFor * 1000, 1 ) end ); Link to comment
victortp Posted June 8, 2013 Author Share Posted June 8, 2013 @Blaawee i want to set the ids in a array, for example: arrayWeapon = { 8, 24, 28} / arrayAmmo = { 100, 200, 300} and unpack it on "getWeaponIDFromName( weapon )" and "tonumber( ammo )". But i don't know how.. Im new on lua Link to comment
Blaawee Posted June 8, 2013 Share Posted June 8, 2013 You can loop it or unpack it. I can't explain to you how to do but, maybe this could help you viewtopic.php?f=148&t=58158 Link to comment
victortp Posted June 8, 2013 Author Share Posted June 8, 2013 so, i cant set the itens? If you want, you can make it as a event and i will put it in a GUI 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