justn Posted March 25, 2014 Share Posted March 25, 2014 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
Castillo Posted March 25, 2014 Share Posted March 25, 2014 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
justn Posted March 25, 2014 Author Share Posted March 25, 2014 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
DNL291 Posted March 25, 2014 Share Posted March 25, 2014 theCop not seem to be defined at line 12. Link to comment
justn Posted March 25, 2014 Author Share Posted March 25, 2014 e.e This is technically my first time using bindKey really so.. a little help please? Link to comment
justn Posted March 25, 2014 Author Share Posted March 25, 2014 When the police targets the player, I want him to press N and then the player will get bribed Link to comment
Castillo Posted March 25, 2014 Share Posted March 25, 2014 Move the bindKey after the "sendClientMessage". P.S: You put "Press H" in the message, but the key is binded to "N". Link to comment
justn Posted March 25, 2014 Author Share Posted March 25, 2014 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
Castillo Posted March 25, 2014 Share Posted March 25, 2014 You are binding the key to the same function that binds the key in the first place, it makes no sense. Link to comment
justn Posted March 25, 2014 Author Share Posted March 25, 2014 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
Castillo Posted March 25, 2014 Share Posted March 25, 2014 'source' is not defined at "payTheTicket" function. Link to comment
justn Posted March 25, 2014 Author Share Posted March 25, 2014 '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 IIYAMA Posted March 26, 2014 Moderators Share Posted March 26, 2014 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
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