Mtaplayer01 Posted December 24, 2017 Share Posted December 24, 2017 En chargeant le module police j'ai un souci que je n'arrive pas à voir. (je ne suis pas très calé en la matière mais j'essaye de voir) [2017-12-23 21:31:17] Starting Policier [2017-12-23 21:31:17] SCRIPT ERROR: Policier\copsreaction.lua:193: ')' expected (to close '(' at line 192) near 'function' [2017-12-23 21:31:17] ERROR: Loading script failed: Policier\copsreaction.lua:193: ')' expected (to close '(' at line 192) near 'function' [2017-12-23 21:31:17] Policier restarted successfully voici la ou ça ne marche pas (je souhaite que lorsqu'on meurt, on ne soit plus recherché) addEventHandler( "onPlayerWasted", getRootElement( ) Wlevel = getPlayerWantedLevel(thePlayer) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) end J'aimerai aussi que lorsqu'on veut payer ses amendes pour annuler son avis de recherche, qu'on marche sur un marqueur dans les commissariats En gros remplacer ce système de commande par le système énoncé juste au dessus addCommandHandler("bail", function(thePlayer, command) Wlevel = getPlayerWantedLevel(thePlayer) Mlevel = getPlayerMoney(thePlayer) if Wlevel == 1 and Mlevel >= 500 then setPlayerMoney (thePlayer,Mlevel - 500) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 2 and Mlevel >= 1000 then setPlayerMoney (thePlayer,Mlevel - 1000) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 3 and Mlevel >= 1500 then setPlayerMoney (thePlayer,Mlevel - 1500) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 4 and Mlevel >= 2000 then setPlayerMoney (thePlayer,Mlevel - 2000) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 5 and Mlevel >= 2500 then setPlayerMoney (thePlayer,Mlevel - 2500) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 6 and Mlevel >= 3000 then setPlayerMoney (thePlayer,Mlevel - 3000) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 0 then outputChatBox("You don't need to pay! (Você não precisa pagar!)", thePlayer) else outputChatBox("You don't have money enough! (Você não tem dinheiro o bastante!)", thePlayer) outputChatBox("Pay $500 for wanted level! (Pague $500 por nível de procurado)", thePlayer) end end ) Merci d'avance pour le coup de main, cela m'aidera beaucoup Link to comment
Gordon_G Posted December 25, 2017 Share Posted December 25, 2017 On 24/12/2017 at 17:38, Mtaplayer01 said: addCommandHandler("bail", function(thePlayer, command) Wlevel = getPlayerWantedLevel(thePlayer) Mlevel = getPlayerMoney(thePlayer) if Wlevel == 1 and Mlevel >= 500 then setPlayerMoney (thePlayer,Mlevel - 500) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 2 and Mlevel >= 1000 then setPlayerMoney (thePlayer,Mlevel - 1000) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 3 and Mlevel >= 1500 then setPlayerMoney (thePlayer,Mlevel - 1500) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 4 and Mlevel >= 2000 then setPlayerMoney (thePlayer,Mlevel - 2000) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 5 and Mlevel >= 2500 then setPlayerMoney (thePlayer,Mlevel - 2500) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 6 and Mlevel >= 3000 then setPlayerMoney (thePlayer,Mlevel - 3000) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 0 then outputChatBox("You don't need to pay! (Você não precisa pagar!)", thePlayer) else outputChatBox("You don't have money enough! (Você não tem dinheiro o bastante!)", thePlayer) outputChatBox("Pay $500 for wanted level! (Pague $500 por nível de procurado)", thePlayer) end end ) N'oublie pas de mettre la balise code quand tu copie/colle un morceau de script. Bon tout d'abord c'est pas très beau cette mise en forme, même pour toi c'est pas pratique car si plus tard tu veux faire appel à la fonction qu’exécute la commande "bail" tu vas devoir l'insérer une nouvelle fois entièrement dans ton code. function bail ( thePlayer ) Wlevel = getPlayerWantedLevel(thePlayer) Mlevel = getPlayerMoney(thePlayer) if Wlevel == 1 and Mlevel >= 500 then setPlayerMoney (thePlayer,Mlevel - 500) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 2 and Mlevel >= 1000 then setPlayerMoney (thePlayer,Mlevel - 1000) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 3 and Mlevel >= 1500 then setPlayerMoney (thePlayer,Mlevel - 1500) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 4 and Mlevel >= 2000 then setPlayerMoney (thePlayer,Mlevel - 2000) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 5 and Mlevel >= 2500 then setPlayerMoney (thePlayer,Mlevel - 2500) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 6 and Mlevel >= 3000 then setPlayerMoney (thePlayer,Mlevel - 3000) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 0 then outputChatBox("You don't need to pay! (Você não precisa pagar!)", thePlayer) else outputChatBox("You don't have money enough! (Você não tem dinheiro o bastante!)", thePlayer) outputChatBox("Pay $500 for wanted level! (Pague $500 por nível de procurado)", thePlayer) end end addCommandHandler("bail",bail) Là on est sur une mise en forme plus que correcte et on s'y retrouve déjà mieux PS : le problème est résolu, tu as juste à remplacer ton ancien code par le nouveau Link to comment
Moderators Citizen Posted December 26, 2017 Moderators Share Posted December 26, 2017 3 hours ago, Gordon_G said: Là on est sur une mise en forme plus que correcte et on s'y retrouve déjà mieux Tu n'as absolument rien changé au code, t'as juste changé la fonction anonyme en fonction concrète et tu as remis le addCommandHandler alors qu'il demande justement de ne plus l'exécuter via une commande. De plus tu ne lui as même pas corrigé son problème de scope des variables Wlevel et Mlevel (rajouter le keyword local devant). On 24/12/2017 at 17:38, Mtaplayer01 said: voici la ou ça ne marche pas (je souhaite que lorsqu'on meurt, on ne soit plus recherché) addEventHandler( "onPlayerWasted", getRootElement( ) Wlevel = getPlayerWantedLevel(thePlayer) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) end Il manque l'entête de la fonction, la ligne du Wlevel qui ne sert pas (ne cause pas d'erreur celui là) et le fait qu'il faille utiliser 'source' plutôt que thePlayer: Quote The source of this event is the player that died or got killed. addEventHandler( "onPlayerWasted", getRootElement(), function () setPlayerWantedLevel(source, 0) setPlayerTeam(source, getTeamFromName("Citizens")) end) Pour payer son amende via un marker: local ammendeMarker = createMarker(0, 0, 3) -- Modifie le marker comme bon the semble function payerAmmende(thePlayer) local Wlevel = getPlayerWantedLevel(thePlayer) -- scope corrigé (la variable n'est accessible que dans cette fonction et n'est pas modifible en-dehors) local Mlevel = getPlayerMoney(thePlayer) -- pareil if Wlevel == 1 and Mlevel >= 500 then setPlayerMoney (thePlayer,Mlevel - 500) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 2 and Mlevel >= 1000 then setPlayerMoney (thePlayer,Mlevel - 1000) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 3 and Mlevel >= 1500 then setPlayerMoney (thePlayer,Mlevel - 1500) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 4 and Mlevel >= 2000 then setPlayerMoney (thePlayer,Mlevel - 2000) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 5 and Mlevel >= 2500 then setPlayerMoney (thePlayer,Mlevel - 2500) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 6 and Mlevel >= 3000 then setPlayerMoney (thePlayer,Mlevel - 3000) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) elseif Wlevel == 0 then outputChatBox("You don't need to pay! (Você não precisa pagar!)", thePlayer) else outputChatBox("You don't have money enough! (Você não tem dinheiro o bastante!)", thePlayer) outputChatBox("Pay $500 for wanted level! (Pague $500 por nível de procurado)", thePlayer) end end addEventHandler("onMarkerHit", ammendeMarker, payerAmmende) Qu'on peut optimiser comme suit: local amendeMarker = createMarker(0, 0, 3) -- Modifie le marker comme bon the semble function payerAmende( thePlayer ) local Wlevel = getPlayerWantedLevel(thePlayer) if Wlevel == 0 then outputChatBox("You don't need to pay! (Você não precisa pagar!)", thePlayer) return -- On empêche la fonction de continuer end local Mlevel = getPlayerMoney(thePlayer) local needToPay = 500 * Wlevel -- 500$ par niveau de recherche (ex: 5 * 500 = 2500) if Mlevel < needToPay then outputChatBox("You don't have money enough! (Você não tem dinheiro o bastante!)", thePlayer) outputChatBox("Pay $500 for wanted level! (Pague $500 por nível de procurado)", thePlayer) return -- On empêche la fonction de continuer end setPlayerMoney (thePlayer, Mlevel - needToPay) setPlayerWantedLevel(thePlayer, 0) setPlayerTeam (thePlayer, getTeamFromName("Citizens")) end addEventHandler("onMarkerHit", amendeMarker, payerAmende) Link to comment
Gordon_G Posted December 26, 2017 Share Posted December 26, 2017 (edited) @Citizen ça m'apprendra à lire en diagonale, je pensais qu'il voulait simplement résoudre l'erreur, merci à toi Edited December 26, 2017 by Gordon_G Link to comment
Moderators Citizen Posted December 26, 2017 Moderators Share Posted December 26, 2017 @Gordon_G L'erreur portait sur le 1er code plutôt que le 2ème Link to comment
Mtaplayer01 Posted December 26, 2017 Author Share Posted December 26, 2017 (edited) Je vais tester ça, normalement ça devrait le faire. Par contre c'est comment pour la balise code, pour les fois suivantes ? Edited December 26, 2017 by Mtaplayer01 Link to comment
Gordon_G Posted December 26, 2017 Share Posted December 26, 2017 @Citizen décidément j'avais vraiment tout faux Pour la balise code c'est ce bouton ça va t'ouvrir un champ de saisie et là tu y mets ton code. N'oublie pas de bien sélectionner LUA en tant que syntax (liste déroulante en bas à droite). 1 Link to comment
Mtaplayer01 Posted December 26, 2017 Author Share Posted December 26, 2017 D'accord merci, je m'en souviendrais les fois suivantes, je viens de tester et ça fonctionne très bien Par contre, quand quelqu'un se connecte il a le message comme quoi il n'a pas besoin de payer l'amende, bien que ce n'est pas très gênant en soi, j'aimerai qu'il n'apparaisse pas à la connexion du joueur si possible bien entendu Link to comment
Moderators Citizen Posted December 26, 2017 Moderators Share Posted December 26, 2017 13 minutes ago, Mtaplayer01 said: Par contre, quand quelqu'un se connecte il a le message comme quoi il n'a pas besoin de payer l'amende, La seule raison pour que ça arrive c'est que le gars spawn dans le marker à ce moment là. Si ce n'est pas le cas, c'est que ce n'est pas mon code qui l'affiche mais un autre que tu aurais oublié quelque part. Pour en être sûr modifie le message dans le code que je t'ai passé en rajoutant un "LOL C'EST MOI" (par exemple) à la fin du message, relance le GM, reconnecte toi et vérifie. Si le message n'a pas changé c'est que c'est un code autre part qui l'affiche Link to comment
Mtaplayer01 Posted December 26, 2017 Author Share Posted December 26, 2017 Je vasi changer les markeur au cas où. Il faudrait aussi que je puisse ajouter un Blip uniquement lorsqu'il a au moins 1 étoile 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