Jump to content

Minor Bug


justn

Recommended Posts

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

:P

-- 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

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
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

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...