Wiseguy Posted September 27, 2018 Share Posted September 27, 2018 Hey, I put myself a bot that works properly, but I would like to support him with some new features, namely buying weapons. How can I do it? I would ask for a practical guide, I know how it works in theory. The bot is to sell weapons for a certain amount of money, for example, 10,000 per ak47. Sorry for my bad english. Client: function cancelPedDamage ( attacker ) cancelEvent() -- cancel any damage done to peds end addEventHandler ( "onClientPedDamage", getRootElement(), cancelPedDamage) GUIEditor = { checkbox = {}, memo = {} } local screenW, screenH = guiGetScreenSize() windowStart = guiCreateWindow((screenW - 441) / 2, (screenH - 317) / 2, 441, 317, "Handlarz bronią", false) guiWindowSetSizable(windowStart, false) guiSetAlpha(windowStart, 0.72) textAk47 = guiCreateEdit(10, 32, 255, 19, "AK-47 | 10, 000$", false, windowStart) buyAk47 = guiCreateButton(283, 31, 148, 20, "Zakup", false, windowStart) textM231 = guiCreateEdit(9, 60, 256, 20, "Karabin M231 FPW | 15, 000$", false, windowStart) buyM231 = guiCreateButton(283, 62, 148, 18, "Zakup", false, windowStart) leaveButton = guiCreateButton(75, 292, 291, 15, "Wyjdz", false, windowStart) markerCreate = createMarker(-369.2470703125, 1202.2958984375, 19.7421875, "cylinder", 1) function guiStart() guiSetVisible(windowStart, true) guiSetVisible(textAk47, true) guiSetVisible(buyAk47, true) guiSetVisible(textM231, true) guiSetVisible(buyM231, true) guiSetVisible(leaveButton, true) showCursor(true) end addEventHandler("onClientMarkerHit", markerCreate, guiStart) function guiStop() guiSetVisible(windowStart, false) guiSetVisible(textAk47, false) guiSetVisible(buyAk47, false) guiSetVisible(textM231, false) guiSetVisible(buyM231, false) guiSetVisible(leaveButton, false) showCursor(false) end addEventHandler("onClientGUIClick", leaveButton, guiStop) Server: function pedCreate() createPed(188, -371.03515625 +2 , 1199.626953125 +2, 19.7421875) end addEventHandler('onResourceStart', getResourceRootElement(), pedCreate) function buyAkPlayer(player) takePlayerMoney(player, 10000) giveWeapon(player, 30, 80) outputChatBox("Otrzymales AK47") end addEventHandler("onClientGUIClick", buyAk47, buyAkPlayer) Link to comment
iMr.WiFi..! Posted September 27, 2018 Share Posted September 27, 2018 You can't use "onClientGUIClick" in Server Side You need to make it in client side the you need to "triggerServerEvent" Link to comment
Wiseguy Posted September 27, 2018 Author Share Posted September 27, 2018 could you explain in more detail? Link to comment
VenomOG Posted September 28, 2018 Share Posted September 28, 2018 7 hours ago, Wiseguy said: could you explain in more detail? He means.im on phone don't blame me. Code Function buyak47 Codes End add event("event name",true) addEventHandler ("event name",source,buyak47) And on client side add addEventHandler ("onClientGUIClick",guidance,function(player) Codes triggerServerEvent("event name",player) end) I did my best I'm on phone Link to comment
justn Posted September 28, 2018 Share Posted September 28, 2018 Client: function cancelPedDamage ( attacker ) cancelEvent() -- cancel any damage done to peds end addEventHandler ( "onClientPedDamage", getRootElement(), cancelPedDamage) GUIEditor = { checkbox = {}, memo = {} } local screenW, screenH = guiGetScreenSize() windowStart = guiCreateWindow((screenW - 441) / 2, (screenH - 317) / 2, 441, 317, "Handlarz bronią", false) guiWindowSetSizable(windowStart, false) guiSetAlpha(windowStart, 0.72) textAk47 = guiCreateEdit(10, 32, 255, 19, "AK-47 | 10, 000$", false, windowStart) buyAk47 = guiCreateButton(283, 31, 148, 20, "Zakup", false, windowStart) textM231 = guiCreateEdit(9, 60, 256, 20, "Karabin M231 FPW | 15, 000$", false, windowStart) buyM231 = guiCreateButton(283, 62, 148, 18, "Zakup", false, windowStart) leaveButton = guiCreateButton(75, 292, 291, 15, "Wyjdz", false, windowStart) markerCreate = createMarker(-369.2470703125, 1202.2958984375, 19.7421875, "cylinder", 1) function guiStart() guiSetVisible(windowStart, true) guiSetVisible(textAk47, true) guiSetVisible(buyAk47, true) guiSetVisible(textM231, true) guiSetVisible(buyM231, true) guiSetVisible(leaveButton, true) showCursor(true) end addEventHandler("onClientMarkerHit", markerCreate, guiStart) function guiStop(btn,state) if ( source == leaveButton ) then -- If the player presses the 'leaveButton' guiSetVisible(windowStart, false) guiSetVisible(textAk47, false) guiSetVisible(buyAk47, false) guiSetVisible(textM231, false) guiSetVisible(buyM231, false) guiSetVisible(leaveButton, false) showCursor(false) elseif ( source == buyAk47 ) then -- If the player presses the 'buyAk47' button triggerServerEvent("onBuyAK47",localPlayer) end end addEventHandler("onClientGUIClick", root, guiStop) Server: function buyAkPlayer() takePlayerMoney(client, 10000) giveWeapon(client, 30, 80) outputChatBox("Otrzymales AK47",client) end addEvent("onBuyAK47",true) addEventHandler("onBuyAK47",root,buyAkPlayer) Link to comment
Wiseguy Posted September 29, 2018 Author Share Posted September 29, 2018 On 28/09/2018 at 09:01, Shux said: Client: function cancelPedDamage ( attacker ) cancelEvent() -- cancel any damage done to peds end addEventHandler ( "onClientPedDamage", getRootElement(), cancelPedDamage) GUIEditor = { checkbox = {}, memo = {} } local screenW, screenH = guiGetScreenSize() windowStart = guiCreateWindow((screenW - 441) / 2, (screenH - 317) / 2, 441, 317, "Handlarz bronią", false) guiWindowSetSizable(windowStart, false) guiSetAlpha(windowStart, 0.72) textAk47 = guiCreateEdit(10, 32, 255, 19, "AK-47 | 10, 000$", false, windowStart) buyAk47 = guiCreateButton(283, 31, 148, 20, "Zakup", false, windowStart) textM231 = guiCreateEdit(9, 60, 256, 20, "Karabin M231 FPW | 15, 000$", false, windowStart) buyM231 = guiCreateButton(283, 62, 148, 18, "Zakup", false, windowStart) leaveButton = guiCreateButton(75, 292, 291, 15, "Wyjdz", false, windowStart) markerCreate = createMarker(-369.2470703125, 1202.2958984375, 19.7421875, "cylinder", 1) function guiStart() guiSetVisible(windowStart, true) guiSetVisible(textAk47, true) guiSetVisible(buyAk47, true) guiSetVisible(textM231, true) guiSetVisible(buyM231, true) guiSetVisible(leaveButton, true) showCursor(true) end addEventHandler("onClientMarkerHit", markerCreate, guiStart) function guiStop(btn,state) if ( source == leaveButton ) then -- If the player presses the 'leaveButton' guiSetVisible(windowStart, false) guiSetVisible(textAk47, false) guiSetVisible(buyAk47, false) guiSetVisible(textM231, false) guiSetVisible(buyM231, false) guiSetVisible(leaveButton, false) showCursor(false) elseif ( source == buyAk47 ) then -- If the player presses the 'buyAk47' button triggerServerEvent("onBuyAK47",localPlayer) end end addEventHandler("onClientGUIClick", root, guiStop) Server: function buyAkPlayer() takePlayerMoney(client, 10000) giveWeapon(client, 30, 80) outputChatBox("Otrzymales AK47",client) end addEvent("onBuyAK47",true) addEventHandler("onBuyAK47",root,buyAkPlayer) my marker has disappeared, what can I do about it? Link to comment
justn Posted September 29, 2018 Share Posted September 29, 2018 (edited) 3 hours ago, Wiseguy said: my marker has disappeared, what can I do about it? No big problem, just some spaces in the code wasn't making it start, removed them for you. Also added in a simple one-liner so the gui isn't showing when the client downloads the file. Here you go. function cancelPedDamage ( attacker ) cancelEvent() -- cancel any damage done to peds end addEventHandler ( "onClientPedDamage", getRootElement(), cancelPedDamage) GUIEditor = { checkbox = {}, memo = {} } local screenW, screenH = guiGetScreenSize() windowStart = guiCreateWindow((screenW - 441) / 2, (screenH - 317) / 2, 441, 317, "Handlarz bronią", false) guiSetVisible(windowStart,false) guiWindowSetSizable(windowStart, false) guiSetAlpha(windowStart, 0.72) textAk47 = guiCreateEdit(10, 32, 255, 19, "AK-47 | 10, 000$", false, windowStart) buyAk47 = guiCreateButton(283, 31, 148, 20, "Zakup", false, windowStart) textM231 = guiCreateEdit(9, 60, 256, 20, "Karabin M231 FPW | 15, 000$", false, windowStart) buyM231 = guiCreateButton(283, 62, 148, 18, "Zakup", false, windowStart) leaveButton = guiCreateButton(75, 292, 291, 15, "Wyjdz", false, windowStart) markerCreate = createMarker(-369.2470703125, 1202.2958984375, 19.7421875, "cylinder", 1) function guiStart() guiSetVisible(windowStart, true) guiSetVisible(textAk47, true) guiSetVisible(buyAk47, true) guiSetVisible(textM231, true) guiSetVisible(buyM231, true) guiSetVisible(leaveButton, true) showCursor(true) end addEventHandler("onClientMarkerHit", markerCreate, guiStart) function guiStop(btn,state) if ( source == leaveButton ) then -- If the player presses the 'leaveButton' guiSetVisible(windowStart, false) guiSetVisible(textAk47, false) guiSetVisible(buyAk47, false) guiSetVisible(textM231, false) guiSetVisible(buyM231, false) guiSetVisible(leaveButton, false) showCursor(false) elseif ( source == buyAk47 ) then -- If the player presses the 'buyAk47' button triggerServerEvent("onBuyAK47",localPlayer) end end addEventHandler("onClientGUIClick", root, guiStop) Edited September 29, 2018 by Shux Link to comment
Wiseguy Posted October 1, 2018 Author Share Posted October 1, 2018 On 29/09/2018 at 20:11, Shux said: No big problem, just some spaces in the code wasn't making it start, removed them for you. Also added in a simple one-liner so the gui isn't showing when the client downloads the file. Here you go. function cancelPedDamage ( attacker ) cancelEvent() -- cancel any damage done to peds end addEventHandler ( "onClientPedDamage", getRootElement(), cancelPedDamage) GUIEditor = { checkbox = {}, memo = {} } local screenW, screenH = guiGetScreenSize() windowStart = guiCreateWindow((screenW - 441) / 2, (screenH - 317) / 2, 441, 317, "Handlarz bronią", false) guiSetVisible(windowStart,false) guiWindowSetSizable(windowStart, false) guiSetAlpha(windowStart, 0.72) textAk47 = guiCreateEdit(10, 32, 255, 19, "AK-47 | 10, 000$", false, windowStart) buyAk47 = guiCreateButton(283, 31, 148, 20, "Zakup", false, windowStart) textM231 = guiCreateEdit(9, 60, 256, 20, "Karabin M231 FPW | 15, 000$", false, windowStart) buyM231 = guiCreateButton(283, 62, 148, 18, "Zakup", false, windowStart) leaveButton = guiCreateButton(75, 292, 291, 15, "Wyjdz", false, windowStart) markerCreate = createMarker(-369.2470703125, 1202.2958984375, 19.7421875, "cylinder", 1) function guiStart() guiSetVisible(windowStart, true) guiSetVisible(textAk47, true) guiSetVisible(buyAk47, true) guiSetVisible(textM231, true) guiSetVisible(buyM231, true) guiSetVisible(leaveButton, true) showCursor(true) end addEventHandler("onClientMarkerHit", markerCreate, guiStart) function guiStop(btn,state) if ( source == leaveButton ) then -- If the player presses the 'leaveButton' guiSetVisible(windowStart, false) guiSetVisible(textAk47, false) guiSetVisible(buyAk47, false) guiSetVisible(textM231, false) guiSetVisible(buyM231, false) guiSetVisible(leaveButton, false) showCursor(false) elseif ( source == buyAk47 ) then -- If the player presses the 'buyAk47' button triggerServerEvent("onBuyAK47",localPlayer) end end addEventHandler("onClientGUIClick", root, guiStop) Thanks, Shux. 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