justn Posted March 31, 2014 Share Posted March 31, 2014 This is for a police script I have, when the player gets ticketed, and he presses ''H'', when the player presses H again, his money goes down still, i think the problem is in the unbindKey function payTheTicket ( _, _, _, theCop, thePlayer ) givePlayerMoney ( theCop, 200 ) takePlayerMoney ( thePlayer, 200 ) setPlayerWantedLevel( thePlayer, 0 ) exports [ "TopBarChat" ] : sendClientMessage ( "The ticket has been paid by " .. getPlayerName ( thePlayer ), theCop, 255, 0, 0, true ) exports [ "TopBarChat" ] : sendClientMessage ( "You have paid the ticket to " .. getPlayerName ( theCop ), thePlayer, 255, 0, 0, true ) unbindKey ( thePlayer, "H", "down", payTheTicket ) end Link to comment
Tete omar Posted April 1, 2014 Share Posted April 1, 2014 The best way to do that is by using Lua coroutines, also i don't get the point of these bunch of underscores you wrote as arguments for that function. Link to comment
justn Posted April 1, 2014 Author Share Posted April 1, 2014 -- Part where i binded it function onPlayerTargetA ( player ) if ( isPlayerInTeam ( source, "Police" ) ) then if ( isElement ( player ) and getElementType ( player ) == "player" ) then if ( not isPlayerInTeam ( player, "Police" ) ) then bindKey ( source, "N", "down", function() exports [ "TopBarChat" ] : sendClientMessage ( "You have given " .. getPlayerName ( player ) .. " a ticket , Wait for him to pay it", source, 255, 0, 0, true ) exports [ "TopBarChat" ] : sendClientMessage ( "You have gotten a ticket ! Press 'H' to pay it!", player, 255, 0, 0, true ) bindKey ( player, "H", "down", payTheTicket, source, player ) end ) end end end end addEventHandler ( "onPlayerTarget", root, onPlayerTargetA ) function payTheTicket ( _, _, _, theCop, thePlayer ) givePlayerMoney ( theCop, 200 ) takePlayerMoney ( thePlayer, 200 ) setPlayerWantedLevel( thePlayer, 0 ) exports [ "TopBarChat" ] : sendClientMessage ( "The ticket has been paid by " .. getPlayerName ( thePlayer ), theCop, 255, 0, 0, true ) exports [ "TopBarChat" ] : sendClientMessage ( "You have paid the ticket to " .. getPlayerName ( theCop ), thePlayer, 255, 0, 0, true ) unbindKey ( thePlayer, "H", "down", payTheTicket ) end Link to comment
Jaysds1 Posted April 1, 2014 Share Posted April 1, 2014 try this: function onPlayerTargetA ( player ) if ( isPlayerInTeam ( source, "Police" ) ) then if ( isElement ( player ) and getElementType ( player ) == "player" ) then if ( not isPlayerInTeam ( player, "Police" ) ) then bindKey ( source, "N", "down",function() exports [ "TopBarChat" ] : sendClientMessage ( "You have given " .. getPlayerName ( player ) .. " a ticket , Wait for him to pay it", source, 255, 0, 0, true ) exports [ "TopBarChat" ] : sendClientMessage ( "You have gotten a ticket ! Press 'H' to pay it!", player, 255, 0, 0, true ) bindKey ( player, "H", "down", payTheTicket, source ) end) end end end end addEventHandler ( "onPlayerTarget", root, onPlayerTargetA ) function payTheTicket ( source, k, s, theCop ) if not theCop then return end givePlayerMoney ( theCop, 200 ) takePlayerMoney ( source, 200 ) setPlayerWantedLevel( source, 0 ) exports [ "TopBarChat" ] : sendClientMessage ( "The ticket has been paid by " .. getPlayerName ( source ), theCop, 255, 0, 0, true ) exports [ "TopBarChat" ] : sendClientMessage ( "You have paid the ticket to " .. getPlayerName ( theCop ), thePlayer, 255, 0, 0, true ) unbindKey ( source, k, s, payTheTicket ) end Link to comment
justn Posted April 4, 2014 Author Share Posted April 4, 2014 try this:function onPlayerTargetA ( player ) if ( isPlayerInTeam ( source, "Police" ) ) then if ( isElement ( player ) and getElementType ( player ) == "player" ) then if ( not isPlayerInTeam ( player, "Police" ) ) then bindKey ( source, "N", "down",function() exports [ "TopBarChat" ] : sendClientMessage ( "You have given " .. getPlayerName ( player ) .. " a ticket , Wait for him to pay it", source, 255, 0, 0, true ) exports [ "TopBarChat" ] : sendClientMessage ( "You have gotten a ticket ! Press 'H' to pay it!", player, 255, 0, 0, true ) bindKey ( player, "H", "down", payTheTicket, source ) end) end end end end addEventHandler ( "onPlayerTarget", root, onPlayerTargetA ) function payTheTicket ( source, k, s, theCop ) if not theCop then return end givePlayerMoney ( theCop, 200 ) takePlayerMoney ( source, 200 ) setPlayerWantedLevel( source, 0 ) exports [ "TopBarChat" ] : sendClientMessage ( "The ticket has been paid by " .. getPlayerName ( source ), theCop, 255, 0, 0, true ) exports [ "TopBarChat" ] : sendClientMessage ( "You have paid the ticket to " .. getPlayerName ( theCop ), thePlayer, 255, 0, 0, true ) unbindKey ( source, k, s, payTheTicket ) end Doesn't work 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