swag_k_dog Posted October 8, 2016 Share Posted October 8, 2016 (edited) Hi, On this script there are 2 teams created and 2 buttons.. I want when you click the bCrim button to join the crimz team and close the gui. help? crimz = createTeam("Criminal", 255, 0, 0) enfz = createTeam("Enforcer", 0, 0, 255) addEventHandler("onClientResourceStart", resourceRoot, function() local screenW, screenH = guiGetScreenSize() sScreen = guiCreateStaticImage((screenW - 1366) / 2, (screenH - 768) / 2, 1366, 768, "images/scrn.png", false) bCrim = guiCreateButton(376, 369, 162, 63, "", false, sScreen) guiSetAlpha(bCrim, 0.00) bEnf = guiCreateButton(743, 369, 162, 63, "", false, sScreen) guiSetAlpha(bEnf, 0.00) end ) thanks Edited October 8, 2016 by swag_k_dog Link to comment
pa3ck Posted October 8, 2016 Share Posted October 8, 2016 1. Create team server side 2. Handle the GUI button click client side and triggerServerEvent with a variable that indicates which team has been clicked 3. Handle the server event, set the team of the player according the value you passed in step 2. If you don't know how to trigger a server side event, look at the wiki page and try to do it on your own, if you can't manage to get it working, come back with your code and the problem you are facing. Link to comment
swag_k_dog Posted October 8, 2016 Author Share Posted October 8, 2016 9 minutes ago, pa3ck said: 1. Create team server side 2. Handle the GUI button click client side and triggerServerEvent with a variable that indicates which team has been clicked 3. Handle the server event, set the team of the player according the value you passed in step 2. If you don't know how to trigger a server side event, look at the wiki page and try to do it on your own, if you can't manage to get it working, come back with your code and the problem you are facing. I started scripting few days ago and I dont really understand everything you're saying but here is the "client" script addEventHandler("onClientResourceStart", resourceRoot, function() local screenW, screenH = guiGetScreenSize() sScreen = guiCreateStaticImage((screenW - 1366) / 2, (screenH - 768) / 2, 1366, 768, "images/scrn.png", false) bCrim = guiCreateButton(376, 369, 162, 63, "", false, sScreen) guiSetAlpha(bCrim, 0.00) bEnf = guiCreateButton(743, 369, 162, 63, "", false, sScreen) guiSetAlpha(bEnf, 0.00) end ) function showC() showCursor( true ) end addEventHandler("onClientResourceStart", getRootElement(), showC) addEventHandler("onClientGUIClick", bCrim, teamset ) and "server" script function teemz () crimz = createTeam ( "Criminal", 255, 0, 0 ) enfz = createTeam ( "Enforcer", 0, 0, 255 ) end addEventHandler("onResourceStart", resourceRoot, teemz) can you like write a code on how to do it? would be cool, thanks Link to comment
pa3ck Posted October 8, 2016 Share Posted October 8, 2016 (edited) We usually don't just write the code for you without you making an effort, but because you said you just started, I wrote the code for you with heavy documentation. Hopefully you will get the gist of it -- Server Side local crimz = createTeam("Criminal", 255, 0, 0) local enfz = createTeam("Enforcer", 0, 0, 255) addEvent("onClientTeamPicked", true) -- its essential to enable the event so we can actually use it in this script file -- notice the name is same as we had client side -- the client is enabled, now lets assign a function to it addEventHandler("onClientTeamPicked", root, function(name) -- the variable "name" is coming from the client local team = getTeamFromName(name) -- this is where our variable comes in to play -- its gonna be either "Criminal" or "Enforcer" so we can find the team by its name -- we can be 100% that we found the team as we have hard coded names both end setPlayerTeam(client, team) -- client is a "predefined" variable that comes with the the event and it is the player element that triggered from client side -- we have the team element, we have the client, so we can enroll them to the team end) -- Client Side local sScreen, bCrim, bEnf local screenW, screenH = guiGetScreenSize() addEventHandler("onClientResourceStart", resourceRoot, function() -- basic stuff, I guess you already know this, as this is your code showCursor(true) sScreen = guiCreateStaticImage((screenW - 1366) / 2, (screenH - 768) / 2, 1366, 768, "images/scrn.png", false) bCrim = guiCreateButton(376, 369, 162, 63, "", false, sScreen) guiSetAlpha(bCrim, 0.00) bEnf = guiCreateButton(743, 369, 162, 63, "", false, sScreen) guiSetAlpha(bEnf, 0.00) function closePanel() destroyElement(sScreen) -- we can just destroy the image as the buttons are children removeEventHandler("onClientGUIClick", resourceRoot, guiClicked) -- remove the event listener for GUI clicks showCursor(false) end function guiClicked(btn, state) if btn == "left" and state == "up" then -- left mouse button, when user released it if source == bCrim then triggerServerEvent("onClientTeamPicked", localPlayer, "Criminal") -- pass "Criminal" with the trigger as string -- triggerServerEvent "triggerName", playerWeWantToSendItTo, variable closePanel() -- destroy the panel and remove event listener elseif source == bEnf then triggerServerEvent("onClientTeamPicked", localPlayer, "Enforcer") -- pass "Enforcer" with the trigger as string closePanel() end end end addEventHandler("onClientGUIClick", resourceRoot, guiClicked) -- add the GUI button click listener end ) This code tag is a bit messy, it's fine in Notepad++, but comes out with bad indent here... Edited October 8, 2016 by pa3ck 2 Link to comment
swag_k_dog Posted October 8, 2016 Author Share Posted October 8, 2016 1 minute ago, pa3ck said: We usually don't just write the code for you without you making an effort, but because you said you just started, I wrote the code for you with heavy documentation. Hopefully you will get the gist of it -- Server Side local crimz = createTeam("Criminal", 255, 0, 0) local enfz = createTeam("Enforcer", 0, 0, 255) addEvent("onClientTeamPicked", true) -- its essential to enable the event so we can actually use it in this script file -- notice the name is same as we had client side -- the client is enabled, now lets assign a function to it addEventHandler("onClientTeamPicked", root, function(name) -- the variable "name" is coming from the client local team = getTeamFromName(name) -- this is where our variable comes in to play -- its gonna be either "Criminal" or "Enforcer" so we can find the team by its name -- we can be 100% that we found the team as we have hard coded names both end setPlayerTeam(client, team) -- client is a "predefined" variable that comes with the the event and it is the player element that triggered from client side -- we have the team element, we have the client, so we can enroll them to the team end) -- Client Side local sScreen, bCrim, bEnf local screenW, screenH = guiGetScreenSize() addEventHandler("onClientResourceStart", resourceRoot, function() -- basic stuff, I guess you already know this, as this is your code showCursor(true) sScreen = guiCreateStaticImage((screenW - 1366) / 2, (screenH - 768) / 2, 1366, 768, "images/scrn.png", false) bCrim = guiCreateButton(376, 369, 162, 63, "", false, sScreen) guiSetAlpha(bCrim, 0.00) bEnf = guiCreateButton(743, 369, 162, 63, "", false, sScreen) guiSetAlpha(bEnf, 0.00) function closePanel() destroyElement(sScreen) -- we can just destroy the image as the buttons are children removeEventHandler("onClientGUIClick", resourceRoot, guiClicked) -- remove the event listener for GUI clicks showCursor(false) end function guiClicked(btn, state) if btn == "left" and state == "up" then -- left mouse button, when user released it if source == bCrim then triggerServerEvent("onClientTeamPicked", localPlayer, "Criminal") -- pass "Criminal" with the trigger as string -- triggerServerEvent "triggerName", playerWeWantToSendItTo, variable closePanel() -- destroy the panel and remove event listener elseif source == bEnf then triggerServerEvent("onClientTeamPicked", localPlayer, "Enforcer") -- pass "Enforcer" with the trigger as string closePanel() end end end addEventHandler("onClientGUIClick", resourceRoot, guiClicked) -- add the GUI button click listener end ) thanks, ill guide myself and learn.. wish I had a real mta scripting teacher Link to comment
pa3ck Posted October 8, 2016 Share Posted October 8, 2016 Believe me, LUA is one of the easiest languages you will learn (if you're planning to become a programmer, obviously). It's simple, you just have to practice to get familiar with the MTA functions, methods etc. 2 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