Jump to content

probleme panel GUI


Recommended Posts

bonsoir ,

j'ai crée un panel et je souhaiterez que les bouton crée fonctionne par exemple le bouton fermer marche mais quand j'essaye de faire marcher la fonction reparer pour fix mon vehicule si je rajoute addcommandHandler ("repair", repair) sa marche mais si je fait addEventHandler("onClientGUIClik", GUIEditor_Button[8], false) rien ne se passe . je comprend pas, je debute dans le script et la je galere vraiment si vous pouviez me donner un coup de main sa serait sympa je met mon Script.lua en dessous.

 

GUIEditor_Window = {}
GUIEditor_Button = {}
GUIEditor_Window[1] = guiCreateWindow(417, 179, 646, 356, "mecano", false)
GUIEditor_Button[1] = guiCreateButton(26, 39, 111, 20, "amortisseur +1", false, GUIEditor_Window[1])
GUIEditor_Button[2] = guiCreateButton(26, 69, 111, 20, "amortisseur +2", false, GUIEditor_Window[1])
GUIEditor_Button[3] = guiCreateButton(26, 99, 111, 20, "amortisseur +3", false, GUIEditor_Window[1])
GUIEditor_Button[4] = guiCreateButton(26, 129, 111, 20, "amortisseur -1", false, GUIEditor_Window[1])
GUIEditor_Button[5] = guiCreateButton(26, 159, 111, 20, "amortisseur -2", false, GUIEditor_Window[1])
GUIEditor_Button[6] = guiCreateButton(26, 189, 111, 20, "amortisseur -3", false, GUIEditor_Window[1])
GUIEditor_Button[7] = guiCreateButton(25, 244, 112, 41, "immatriculation", false, GUIEditor_Window[1])
GUIEditor_Button[8] = guiCreateButton(24, 301, 113, 38, "reparer", false, GUIEditor_Window[1])
GUIEditor_Button[9] = guiCreateButton(193, 40, 35, 29, "avg +1", false, GUIEditor_Window[1])
GUIEditor_Button[10] = guiCreateButton(193, 139, 35, 29, "arg +1", false, GUIEditor_Window[1])
GUIEditor_Button[11] = guiCreateButton(238, 139, 35, 29, "arg  -1", false, GUIEditor_Window[1])
GUIEditor_Button[12] = guiCreateButton(238, 40, 35, 29, "avg  -1", false, GUIEditor_Window[1])
GUIEditor_Button[13] = guiCreateButton(319, 40, 35, 29, "avd  -1", false, GUIEditor_Window[1])
GUIEditor_Button[14] = guiCreateButton(364, 40, 35, 29, "avd +1", false, GUIEditor_Window[1])
GUIEditor_Button[15] = guiCreateButton(364, 139, 35, 29, "ard +1", false, GUIEditor_Window[1])
GUIEditor_Button[16] = guiCreateButton(319, 139, 35, 29, "ard  -1", false, GUIEditor_Window[1])
GUIEditor_Button[17] = guiCreateButton(191, 213, 208, 31, "reprogramation stage 1", false, GUIEditor_Window[1])
GUIEditor_Button[18] = guiCreateButton(191, 260, 208, 31, "reprogramation stage 2", false, GUIEditor_Window[1])
GUIEditor_Button[19] = guiCreateButton(191, 308, 208, 31, "reprogramation stage 3", false, GUIEditor_Window[1])
GUIEditor_Button[20] = guiCreateButton(491, 41, 122, 28, "xenon", false, GUIEditor_Window[1])
GUIEditor_Button[21] = guiCreateButton(491, 79, 122, 28, "origine", false, GUIEditor_Window[1])
GUIEditor_Button[22] = guiCreateButton(491, 121, 122, 28, "hold school", false, GUIEditor_Window[1])
GUIEditor_Button[23] = guiCreateButton(527, 321, 100, 18, "fermer", false, GUIEditor_Window[1])
GUIEditor_Button[24] = guiCreateButton(485, 183, 27, 20, "1", false, GUIEditor_Window[1])
GUIEditor_Button[25] = guiCreateButton(522, 183, 27, 20, "2", false, GUIEditor_Window[1])
GUIEditor_Button[26] = guiCreateButton(559, 183, 27, 20, "3", false, GUIEditor_Window[1])
GUIEditor_Button[27] = guiCreateButton(596, 183, 27, 20, "4", false, GUIEditor_Window[1])
GUIEditor_Button[28] = guiCreateButton(596, 213, 27, 20, "8", false, GUIEditor_Window[1])
GUIEditor_Button[29] = guiCreateButton(559, 213, 27, 20, "7", false, GUIEditor_Window[1])
GUIEditor_Button[30] = guiCreateButton(522, 213, 27, 20, "6", false, GUIEditor_Window[1])
GUIEditor_Button[31] = guiCreateButton(485, 213, 27, 20, "5", false, GUIEditor_Window[1])
GUIEditor_Button[32] = guiCreateButton(485, 243, 27, 20, "9", false, GUIEditor_Window[1])
GUIEditor_Button[33] = guiCreateButton(485, 273, 27, 20, "13", false, GUIEditor_Window[1])
GUIEditor_Button[34] = guiCreateButton(522, 273, 27, 20, "14", false, GUIEditor_Window[1])
GUIEditor_Button[35] = guiCreateButton(559, 273, 27, 20, "15", false, GUIEditor_Window[1])
GUIEditor_Button[36] = guiCreateButton(596, 273, 27, 20, "16", false, GUIEditor_Window[1])
GUIEditor_Button[37] = guiCreateButton(522, 243, 27, 20, "10", false, GUIEditor_Window[1])
GUIEditor_Button[38] = guiCreateButton(559, 243, 27, 20, "11", false, GUIEditor_Window[1])
GUIEditor_Button[39] = guiCreateButton(596, 243, 27, 20, "12", false, GUIEditor_Window[1])     
guiSetFont(GUIEditor_Button[1], "sans")
guiWindowSetSizable(GUIEditor_Window[1], false)
guiSetVisible(GUIEditor_Window[1], false)
showCursor(false) 

function enableVehicleControl()
  if guiGetVisible(GUIEditor_Window[1]) == false then
    guiSetVisible(GUIEditor_Window[1], true)
    showCursor(true)
  else
    guiSetVisible(GUIEditor_Window[1], false)
    showCursor(false)
  end
end
addCommandHandler("tds", enableVehicleControl)
bindKey("f4", "down", enableVehicleControl)

function closeButton()
  guiSetVisible(GUIEditor_Window[1], false)
  showCursor(false)
end
addEventHandler("onClientGUIClick", GUIEditor_Button[23], closeButton, false)

function repair()
		getVehicleDamage = tonumber math.random = getVehicleProcentage
		takePlayerMoney (thePlayer, 50, true )
		setVehicleFixed
		= outputChatBox("You have payed 50$ for your repair", getRootElement(), 125, 125, 0 )
end
addEventHandler("onClientGUIClick", GUIEditor_Button[8], repair, false)

 

Link to comment

exemple :

 

addEventHandler("onClientGUIClick", root, 
function ()
if ( source == GUIEditor_Window[1] ) then
--bla bla bla bla
elseif ( source == GUIEditor_Window[2] ) then
--bla bla bla bla
    end
end
)

 

Edited by <~KaMiKaZe~>
Link to comment
  • Moderators
2 hours ago, sanka-campbell said:

si je rajoute addcommandHandler ("repair", repair) sa marche

Impossible, le code n'a aucun sens et même avec un addCommandHandler ça ne passera pas.

function repair()
    outputChatBox("Bouton réparer cliqué !")
end
addEventHandler("onClientGUIClick", GUIEditor_Button[8], repair, false)

Ce code affichera "Bouton réparer cliqué !" dans le chat si on fait un clic gauche, droit ou clic molette.
Ok donc on va maintenant restreindre notre code pour n'autoriser que le clic gauche, et pour ça il faut vérifier la valeur du paramètre button que l'event envoit en 1er paramètre si on ajoute une variable pour la réceptionner:

Quote

string button, string state, int absoluteX, int absoluteY
function repair( button )
    if button == "left" then
        outputChatBox("Bouton réparer cliqué !")
    end
end
addEventHandler("onClientGUIClick", GUIEditor_Button[8], repair, false)

Voilà le code du dessus affichera "Bouton réparer cliqué !" mais que si on a fait un clic gauche.

Maintenant on veut réparer le véhicule dans lequel le joueur est assis. En regardant le wiki, je trouve cette fonction: fixVehicle

Quote

This function will set a vehicle's health to full and fix its damage model.

Mais d'après la syntaxe et comme on pouvait s'y attendre, il faut lui donner en paramètre le véhicule à réparer donc il faut d'abord récupérer le véhicule dans lequel le joueur local (on est en script client donc getLocalPlayer() pour ça) est assis et toujours via le wiki (plus difficile à trouver je te l'accorde) je vois cette fonction: getPedOccupiedVehicle

Quote

 

This function gets the vehicle that the ped is currently in or is trying to enter, if any.

 

Elle retournera false s'il n'est pas actuellement dans un véhicule, auquel cas on peut afficher un message d'erreur:

function repair( button )
    if button == "left" then
        local vehicle = getPedOccupiedVehicle( getLocalPlayer() ) -- on récupère le véhicule occupé par le joueur local
        if vehicle then -- si on a bien une valeur (autre que false ici) ...
            fixVehicle( vehicle ) -- on répare ce véhicule
        else -- sinon ...
            outputChatBox( "You have to be in a vehicle to fix it !", getLocalPlayer(), 200, 0, 0) -- on affiche ce message au joueur local et en rouge.
        end
    end
end
addEventHandler("onClientGUIClick", GUIEditor_Button[8], repair, false)

On va également lui retirer 50$ et afficher ton message:

function repair( button )
    if button == "left" then
        local vehicle = getPedOccupiedVehicle( getLocalPlayer() )
        if vehicle then
            fixVehicle( vehicle )
            takePlayerMoney ( getLocalPlayer(), 50 ) -- il n'y a que 2 arguments, pas de true à la fin
            outputChatBox( "You have payed 50$ for your repair.", getLocalPlayer(), 125, 125, 0 )
        else
            outputChatBox( "You have to be in a vehicle to fix it !", getLocalPlayer(), 200, 0, 0)
        end
    end
end
addEventHandler("onClientGUIClick", GUIEditor_Button[8], repair, false)

Et là tu as quelque chose de de fonctionnel et qui correspond à ce que tu veux.

C'est en essayant et en apprenant de ces erreurs qu'on devient meilleur. Continue ton apprentissage et n'hésite pas si tu as d'autres questions.

Cordialement,
Citizen

  • Like 1
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...