LucasBaker Posted June 15, 2013 Share Posted June 15, 2013 Well I would like to use the SetTimer for when a player enter / or life / vest he takes life but can only use these two commands again after 20 seconds I have tried everything but just goes to the SetTimer function and not for command could anyone do to me? -- Função da vida: function buyhealth ( thePlayer ) local money = getPlayerMoney ( thePlayer ) if money >= 500 then outputChatBox("Você comprou Vida por 500$",thePlayer, 255, 106, 106) local thePlayerhealth = getElementHealth ( thePlayer ) setElementHealth ( thePlayer, 569 ) takePlayerMoney ( thePlayer, 500 ) else outputChatBox("Não há dinheiro suficiente, necessário 500$",thePlayer, 139, 101, -- s8) --> end end addCommandHandler ( "vida", buyhealth ) --Função do colete: function buyarmor ( thePlayer ) local money = getPlayerMoney ( thePlayer ) if money >= 500 then outputChatBox("Você comprou Colete por 500$",thePlayer, 255, 106, 106) local thePlayerarmor = getPedArmor(thePlayer) setPedArmor ( thePlayer, 100 ) takePlayerMoney ( thePlayer, 500 ) else outputChatBox("Não há dinheiro suficiente, necessário 500$!",thePlayer, 139, 117, 0) end end addCommandHandler ( "colete", buyarmor ) Link to comment
iPrestege Posted June 15, 2013 Share Posted June 15, 2013 (edited) Here's an example : local LastHandled = { } function buyhealth ( thePlayer ) if not LastHandled [ thePlayer ] then LastHandled [ thePlayer ] = { } end if LastHandled [ thePlayer ] == false then return outputChatBox('Please Wait 20 Sec!',thePlayer,255,0,0) end local money = getPlayerMoney ( thePlayer ) if money >= 500 then outputChatBox("Você comprou Vida por 500$",thePlayer, 255, 106, 106) local thePlayerhealth = getElementHealth ( thePlayer ) setElementHealth ( thePlayer, 569 ) takePlayerMoney ( thePlayer, 500 ) else outputChatBox("Não há dinheiro suficiente, necessário 500$",thePlayer, 139, 101, -- s8) --> end LastHandled [ thePlayer ] = false setTimer ( function ( ) LastHandled [ thePlayer ] = true end,20000,1 ) end addCommandHandler ( "vida", buyhealth ) This is for the health make it for anything you want . Edited June 15, 2013 by Guest Link to comment
Castillo Posted June 15, 2013 Share Posted June 15, 2013 Where is the table "LastHandled" defined? Link to comment
iPrestege Posted June 15, 2013 Share Posted June 15, 2013 Where is the table "LastHandled" defined? forgot it . Edited . Link to comment
Castillo Posted June 15, 2013 Share Posted June 15, 2013 Won't work either. This one works: local LastHandled = { } function buyhealth ( thePlayer ) if ( LastHandled [ thePlayer ] == nil ) then LastHandled [ thePlayer ] = { } end if ( LastHandled [ thePlayer ] == false ) then return outputChatBox ( 'Please Wait 20 Sec!', thePlayer, 255, 0, 0 ) end local money = getPlayerMoney ( thePlayer ) if ( money >= 500 ) then outputChatBox ( "Você comprou Vida por 500$", thePlayer, 255, 106, 106 ) local thePlayerhealth = getElementHealth ( thePlayer ) setElementHealth ( thePlayer, 569 ) takePlayerMoney ( thePlayer, 500 ) else outputChatBox ( "Não há dinheiro suficiente, necessário 500$", thePlayer, 139, 101, 8 ) end LastHandled [ thePlayer ] = false setTimer ( function ( ) LastHandled [ thePlayer ] = true end ,20000, 1 ) end addCommandHandler ( "vida", buyhealth ) Link to comment
iPrestege Posted June 15, 2013 Share Posted June 15, 2013 Won't work either.This one works: local LastHandled = { } function buyhealth ( thePlayer ) if ( LastHandled [ thePlayer ] == nil ) then LastHandled [ thePlayer ] = { } end if ( LastHandled [ thePlayer ] == false ) then return outputChatBox ( 'Please Wait 20 Sec!', thePlayer, 255, 0, 0 ) end local money = getPlayerMoney ( thePlayer ) if ( money >= 500 ) then outputChatBox ( "Você comprou Vida por 500$", thePlayer, 255, 106, 106 ) local thePlayerhealth = getElementHealth ( thePlayer ) setElementHealth ( thePlayer, 569 ) takePlayerMoney ( thePlayer, 500 ) else outputChatBox ( "Não há dinheiro suficiente, necessário 500$", thePlayer, 139, 101, 8 ) end LastHandled [ thePlayer ] = false setTimer ( function ( ) LastHandled [ thePlayer ] = true end ,20000, 1 ) end addCommandHandler ( "vida", buyhealth ) Reason. Link to comment
Castillo Posted June 15, 2013 Share Posted June 15, 2013 if not LastHandled [ thePlayer ] then LastHandled [ thePlayer ] = { } end You made that, but it'll always clean the table again, because 'false' and 'nil' will pass that 'if'. Link to comment
iPrestege Posted June 15, 2013 Share Posted June 15, 2013 if not LastHandled [ thePlayer ] then LastHandled [ thePlayer ] = { } end You made that, but it'll always clean the table again, because 'false' and 'nil' will pass that 'if'. Much thanks. 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