Bluntz-X Posted March 5, 2014 Posted March 5, 2014 hi all i am new in lua i have problem my button not working how i can open it Like this is button GUIEditor.button[1] = guiCreateButton(9, 81, 73, 37, "Rules", false, GUIEditor.window[1]) when player press button it show this GUIEditor.memo[1] = guiCreateMemo(186, 149, 389, 338, "\nbbabaabaaba", false) i am using this onClientGUIClick hope you can help me
Bluntz-X Posted March 6, 2014 Author Posted March 6, 2014 function initGUI( ) -- Create our button button = guiCreateButton(311, 254, 162, 19, "Rules", false) addEventHandler ( "onClientGUIClick", button, outputEditBox, false ) GUIEditor.window[1] = guiCreateWindow(166, 127, 540, 359, "", false) guiWindowSetSizable(GUIEditor.window[1], false) GUIEditor.memo[1] = guiCreateMemo(9, 22, 521, 327, "/n button not working", false, GUIEditor.window[1]) guiMemoSetReadOnly(GUIEditor.memo[1], true) end addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), initGUI )
Anubhav Posted March 6, 2014 Posted March 6, 2014 function initGUI( ) -- Create our button button = guiCreateButton(311, 254, 162, 19, "Rules", false) GUIEditor.window[1] = guiCreateWindow(166, 127, 540, 359, "", false) guiWindowSetSizable(GUIEditor.window[1], false) GUIEditor.memo[1] = guiCreateMemo(9, 22, 521, 327, "/n button not working", false, GUIEditor.window[1]) guiMemoSetReadOnly(GUIEditor.memo[1], true) end addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), initGUI ) function onClick() guiSetVisible(GUIEditor.memo[1],true) end addEventHandler ( "onClientGUIClick", button, onClick ) See my some resources: Skin shop: https://community.multitheftauto.com/in ... ls&id=8008 Note script: https://community.multitheftauto.com/in ... ls&id=8009 Rules Panel: https://community.multitheftauto.com/in ... ls&id=8246 Random Money: https://community.multitheftauto.com/in ... ls&id=8718
Hell-Mate Posted March 6, 2014 Posted March 6, 2014 Try this. GUIEditor = { window = {}, memo = {}, button = {} } addEventHandler( "onClientResourceStart", resourceRoot, function () -- Create our button GUIEditor.window[1] = guiCreateWindow(166, 127, 540, 359, "Rules", false) GUIEditor.button[1] = guiCreateButton(311, 254, 162, 19, "Rules", false, GUIEditor.window[1]) guiWindowSetSizable(GUIEditor.window[1], true) GUIEditor.memo[1] = guiCreateMemo(9, 22, 521, 327, "/n button not working", false, GUIEditor.window[1]) guiSetVisible(GUIEditor.memo[1],false) guiMemoSetReadOnly(GUIEditor.memo[1], true) showCursor (true) function hmm () if guiGetVisible (GUIEditor.memo[1]) == true then guiSetVisible (GUIEditor.memo[1],false) else guiSetVisible(GUIEditor.memo[1],true) end end end) addEventHandler ( "onClientGUIClick", GUIEditor.button[1], hmm, false ) not tested but as i see it should work.
Moderators IIYAMA Posted March 6, 2014 Moderators Posted March 6, 2014 Try this. GUIEditor = { window = {}, memo = {}, button = {} } addEventHandler( "onClientResourceStart", resourceRoot, function () -- Create our button GUIEditor.window[1] = guiCreateWindow(166, 127, 540, 359, "Rules", false) GUIEditor.button[1] = guiCreateButton(311, 254, 162, 19, "Rules", false, GUIEditor.window[1]) guiWindowSetSizable(GUIEditor.window[1], true) GUIEditor.memo[1] = guiCreateMemo(9, 22, 521, 327, "/n button not working", false, GUIEditor.window[1]) guiSetVisible(GUIEditor.memo[1],false) guiMemoSetReadOnly(GUIEditor.memo[1], true) showCursor (true) function hmm () if guiGetVisible (GUIEditor.memo[1]) == true then guiSetVisible (GUIEditor.memo[1],false) else guiSetVisible(GUIEditor.memo[1],true) end end end) addEventHandler ( "onClientGUIClick", GUIEditor.button[1], hmm, false ) not tested but as i see it should work. No it doesn't. The variable hmm isn't defined when the addEventHandler ( "onClientGUIClick") is attached. Also the button hasn't been created yet. Because onClientResourceStart get triggered after the code has been loaded. GUIEditor = { window = {}, memo = {}, button = {} } addEventHandler( "onClientResourceStart", resourceRoot, function () -- Create our button GUIEditor.window[1] = guiCreateWindow(166, 127, 540, 359, "Rules", false) GUIEditor.button[1] = guiCreateButton(311, 254, 162, 19, "Rules", false, GUIEditor.window[1]) guiWindowSetSizable(GUIEditor.window[1], true) GUIEditor.memo[1] = guiCreateMemo(9, 22, 521, 327, "/n button not working", false, GUIEditor.window[1]) guiSetVisible(GUIEditor.memo[1],false) guiMemoSetReadOnly(GUIEditor.memo[1], true) showCursor (true) function hmm () --<< 1 if guiGetVisible (GUIEditor.memo[1]) == true then guiSetVisible (GUIEditor.memo[1],false) else guiSetVisible(GUIEditor.memo[1],true) end end addEventHandler ( "onClientGUIClick", GUIEditor.button[1], hmm, false ) --<< 2 end) -- end function (onClientResourceStart) --addEventHandler ( "onClientGUIClick", GUIEditor.button[1], hmm, false ) Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Bluntz-X Posted March 30, 2014 Author Posted March 30, 2014 hi i am come back again with more help i make lock button but lock system is server side how i can lock car function () -- Create our button GUIEditor.window[1] = guiCreateWindow(166, 127, 540, 359, "lock", false) GUIEditor.button[1] = guiCreateButton(311, 254, 162, 19, "lock", false, GUIEditor.window[1]) function lockcar ( thePlayer ) playervehicle = getPlayerOccupiedVehicle ( thePlayer ) -- define 'playervehicle' as the vehicle the player is in if ( playervehicle ) then -- if a player is in a vehicle if isVehicleLocked ( playervehicle ) then -- and if the vehicle is already locked setVehicleLocked ( playervehicle, false ) -- unlock it else -- otherwise (if it isn't locked) setVehicleLocked ( playervehicle, true ) -- lock it end end end function bindLockOnSpawn ( theSpawnpoint ) -- when a player spawns bindKey ( source, "l", "down", "Lock car", lockcar ) -- bind the 'l' key to the 'lockcar' function end addEventHandler ( "onPlayerSpawn", getRootElement(), bindLockOnSpawn ) -- add an e thanks for help
.:HyPeX:. Posted March 30, 2014 Posted March 30, 2014 It is not necessarily a server function, just use "onClientPlayerSpawn" instead. My ingame nick is ~HyPeX~ BF3 Gamemode Progress: ~30% - Currently working on AI & MapManager
WhoAmI Posted March 30, 2014 Posted March 30, 2014 addEventHandler ( "onClientGUIClick", GUIEditor.button[1], function () if ( source == GUIEditor.button[1] ) then triggerServerEvent ( "lockCar", localPlayer, localPlayer ) end end ) That was clientside, now serverside: function lockcar ( thePlayer ) playervehicle = getPlayerOccupiedVehicle ( thePlayer ) -- define 'playervehicle' as the vehicle the player is in if ( playervehicle ) then -- if a player is in a vehicle if isVehicleLocked ( playervehicle ) then -- and if the vehicle is already locked setVehicleLocked ( playervehicle, false ) -- unlock it else -- otherwise (if it isn't locked) setVehicleLocked ( playervehicle, true ) -- lock it end end end addEvent ( "lockCar", true ) addEventHandler ( "lockCar", root, lockcar ) function bindLockOnSpawn ( theSpawnpoint ) -- when a player spawns bindKey ( source, "l", "down", "Lock car", lockcar ) -- bind the 'l' key to the 'lockcar' function end addEventHandler ( "onPlayerSpawn", getRootElement(), bindLockOnSpawn )
cheez3d Posted March 30, 2014 Posted March 30, 2014 GUIEditor.window[1] = guiCreateWindow(166, 127, 540, 359, "lock", false) GUIEditor.button[1] = guiCreateButton(311, 254, 162, 19, "lock", false, GUIEditor.window[1]) addEventHandler("onClientGUIClick",GUIEditor.button[1],function() triggerServerEvent("onPlayerRequestLock",localPlayer) end,false) addEvent("onPlayerRequestLock",true) addEventHandler("onPlayerRequestLock",root,function() local vehicle = getPedOccupiedVehicle(client) if vehicle then setVehicleLocked(vehicle,not isVehicleLocked(vehicle)) else outputChatBox("You are not inside a vehicle!",client) end end)
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