Jump to content

Help with 2 Small problems


justn

Recommended Posts

So, Hi, I need help with 2 functions ..

The first one, I need help with, if the player has 1 or less wanted level, then his wanted will be set to '2'

function onPlayerDamage ( attacker ) 
    if isPlayerInTeam ( source, "Police" ) then 
        if ( getElementType ( attacker ) == "player" and getElementModel ( source ) == 280 ) then 
            setPlayerWantedLevel ( attacker, 2 ) 
        end 
    end 
end 
addEventHandler ( "onPlayerDamage", getRootElement(), onPlayerDamage ) 

Now the second one, is onPlayerWasted..

the problem is, this doesn't work, no errors in debugscript.

function onPlayerWasted ( attacker ) 
    if isPlayerInTeam ( source, "Police" ) then 
        if ( getElementType ( attacker ) == "player" ) then 
        setPlayerWantedLevel ( attacker, getPlayerWantedLevel(attacker)+1 ) 
        end 
    end 
end 
addEventHandler ( "onPlayerWasted", getRootElement(), onPlayerWasted ) 

Link to comment

1: You must check if the wanted level of the player is below 2.

function onPlayerDamage ( attacker ) 
    if isPlayerInTeam ( source, "Police" ) then 
        if ( getElementType ( attacker ) == "player" and getElementModel ( source ) == 280 ) and ( getPlayerWantedLevel ( attacker ) < 2 ) then 
            setPlayerWantedLevel ( attacker, 2 ) 
        end 
    end 
end 
addEventHandler ( "onPlayerDamage", getRootElement(), onPlayerDamage ) 

2: The first argument of "onPlayerWasted" is the total ammo, the second is the killer.

function onPlayerWasted ( _, attacker ) 
    if isPlayerInTeam ( source, "Police" ) then 
        if ( getElementType ( attacker ) == "player" ) then 
            if ( attacker ~= source ) then 
                setPlayerWantedLevel ( attacker, getPlayerWantedLevel ( attacker ) + 1 ) 
            end 
        end 
    end 
end 
addEventHandler ( "onPlayerWasted", getRootElement(), onPlayerWasted ) 

Link to comment

Ahh, i have 1 last problem, it doesn't work, can you tell me the problem ?

function onPlayerTargetA ( theCop ) 
    if isPlayerInTeam( theCop, "Police" )  then 
     if not isPlayerInTeam(source, "Police" ) then 
     if ( getPlayerWantedLevel ( source ) == 1 ) then 
     exports["TopBarChat"]:sendClientMessage("You have bribed "..getPlayerName(source)..", Wait for him to pay it",theCop,255, 0, 0, true) 
     exports["TopBarChat"]:sendClientMessage("You have gotten a ticket ! Press 'H' to pay it. !",source,255, 0, 0, true) 
        end 
    end 
end 
end 
addEventHandler ( "onPlayerTarget", getRootElement(), onPlayerTargetA ) 
bindKey ( theCop, "N", "down", onPlayerTargetA ) 

Link to comment
Move the bindKey after the "sendClientMessage".

P.S: You put "Press H" in the message, but the key is binded to "N".

I know, when the police bribes the player, the press H message, will be displayed to the player.

and you mean like this ?

function onPlayerTargetA ( theCop ) 
    if isPlayerInTeam( theCop, "Police" )  then 
        if not isPlayerInTeam(source, "Police" ) then 
            if ( getPlayerWantedLevel ( source ) == 1 ) then 
                if ( getElementType ( theCop ) == "player" ) then 
                exports["TopBarChat"]:sendClientMessage("You have bribed "..getPlayerName(source)..", Wait for him to pay it",theCop,255, 0, 0, true) 
                exports["TopBarChat"]:sendClientMessage("You have gotten a ticket ! Press 'H' to pay it. !",source,255, 0, 0, true) 
                bindKey ( theCop, "N", "down", onPlayerTargetA ) 
                end 
                end 
            end 
        end 
    end 
  
addEventHandler ( "onPlayerTarget", getRootElement(), onPlayerTargetA ) 

Link to comment

My bad, and i already made a new code but it's not working, IDK why

function onPlayerTargetA ( theCop ) 
    if isPlayerInTeam( theCop, "Police" )  then 
        if not isPlayerInTeam(source, "Police" ) then 
            if ( getPlayerWantedLevel ( source ) == 1 ) then 
                if ( getElementType ( theCop ) == "player" ) then 
                bindKey ( theCop, "N", "down", function() 
                exports["TopBarChat"]:sendClientMessage("You have given "..getPlayerName(source).." a ticket , Wait for him to pay it",theCop,255, 0, 0, true) 
                exports["TopBarChat"]:sendClientMessage("You have gotten a ticket ! Press 'H' to pay it!",source,255, 0, 0, true) 
bindKey ( source, "H", "down", payTheTicket ) 
end) 
                end 
                end 
            end 
        end 
    end 
  
addEventHandler ( "onPlayerTarget", getRootElement(), onPlayerTargetA ) 
  
function payTheTicket (theCop) 
if isPlayerInTeam( theCop, "Police" )  then 
        if not isPlayerInTeam(source, "Police" ) then 
            if ( getPlayerWantedLevel ( source ) == 1 ) then 
                if ( getElementType ( theCop ) == "player" ) then 
                givePlayerMoney(theCop,200) 
                takePlayerMoney(source,200) 
                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),source,255, 0, 0, true) 
            end 
        end 
    end 
end 
end 

Link to comment
'source' is not defined at "payTheTicket" function.

Okay i have defined source in both functions ( if i didnt in the first function then the sendClientMessage wouldnt work ) but now. i defined it, and still not working. (no errors in debugscript )

Link to comment
  • Moderators
bindKey ( source, "H", "down", payTheTicket, source) 

function payTheTicket (theCop,key,keyState,source) 

https://wiki.multitheftauto.com/wiki/BindKey

Server

bindKey ( player thePlayer, string key, string keyState, function handlerFunction,  [ var arguments, ... ] ) 

function functionName ( player keyPresser, string key, string keyState, [ var arguments, ... ] ) 

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