selam Posted July 29, 2019 Author Share Posted July 29, 2019 I fixed the error, it was because of the forums. But the code is still not working, I mean, when I click "Buy Fishs" button, my money is still same and I don't have fishs. @HassoN Link to comment
HassoN Posted July 29, 2019 Share Posted July 29, 2019 44 minutes ago, selam said: I fixed the error, it was because of the forums. But the code is still not working, I mean, when I click "Buy Fishs" button, my money is still same and I don't have fishs. @HassoN What does your script say? /debugscript 3 or any message by the outputChatBox function? Try to locate the problem. Link to comment
selam Posted July 29, 2019 Author Share Posted July 29, 2019 Everything works except buying, debugscript 3 says nothing, there is no errors. This is my script folder Spoiler And this is the codes Spoiler function PedLoad(ped) ped = createPed ( 36, 1623.5, 576.70001220703, 1.7999999523163 ) setElementFrozen( ped, true ) addEventHandler("onClientPedDamage", ped, cancelEvent) end addEventHandler("onClientResourceStart", resourceRoot, PedLoad) -- Marker coords -- X: 1623.5999755859 Y: 577.59997558594 Z: 0.79999995231628 marker = createMarker (1623.5999755859, 577.59997558594, 0.79999995231628, "cylinder", 1.2, 255, 0, 0, 140 ) function markerHit(plr) if (plr ~= localPlayer) then return false end guiSetVisible(GUIEditor.window[1], true) showCursor(true) end addEventHandler( "onClientMarkerHit", marker, markerHit) GUIEditor = { button = {}, window = {}, edit = {}, label = {} } addEventHandler("onClientResourceStart", resourceRoot, function() GUIEditor.window[1] = guiCreateWindow(448, 230, 504, 330, "Fisherman", false) guiWindowSetSizable(GUIEditor.window[1], false) guiSetAlpha(GUIEditor.window[1], 0.85) guiSetVisible(GUIEditor.window[1], false) GUIEditor.label[1] = guiCreateLabel(7, 33, 222, 38, " Fisherman: Hello! Get some fish food!", false, GUIEditor.window[1]) guiSetFont(GUIEditor.label[1], "default-bold-small") GUIEditor.label[2] = guiCreateLabel(10, 83, 105, 33, " x10 Food = 300$", false, GUIEditor.window[1]) guiSetFont(GUIEditor.label[2], "default-bold-small") GUIEditor.button[1] = guiCreateButton(22, 133, 122, 80, " BUY FOODS(10)", false, GUIEditor.window[1]) GUIEditor.label[3] = guiCreateLabel(283, 79, 192, 55, "Do you have enough fishes to sell?\n Let me have!", false, GUIEditor.window[1]) GUIEditor.label[4] = guiCreateLabel(293, 33, 68, 20, " Fisherman:", false, GUIEditor.window[1]) guiSetFont(GUIEditor.label[4], "default-bold-small") GUIEditor.button[2] = guiCreateButton(278, 134, 192, 73, " SELL FISHES", false, GUIEditor.window[1]) GUIEditor.label[5] = guiCreateLabel(113, 266, 283, 18, " Note! You can buy maximum 20 foods for per deal", false, GUIEditor.window[1]) guiSetFont(GUIEditor.label[5], "default-bold-small") GUIEditor.button[4] = guiCreateButton(443, 27, 51, 26, "X", false, GUIEditor.window[1]) guiSetFont(GUIEditor.button[4], "default-bold-small") end ) addEventHandler("onClientGUIClick", resourceRoot, function() if (source == GUIEditor.button[4]) then -- replace closeButton with your button name. guiSetVisible(GUIEditor.window[1], false) -- replace window with your window name. showCursor(false) end end) -- client side addEventHandler( "onClientGUIClick", resourceRoot, function() if (source == GUIEditor.button[1]) then -- The button to buy guiSetVisible(GUIEditor.window[1], true) -- The window to buy showCursor(true) elseif (source == GUIEditor.button[1]) then -- add your button to buy buyFish() end end) function buyFish() local money = getPlayerMoney(localPlayer) triggerServerEvent("buyFish", resourceRoot) if (money >= 300) then outputChatBox("You have bought a fish food.") else outputChatBox("You don't have enough money.") end end -- server side function buyFish() takePlayerMoney(client, 300) end addEvent("buyFish", true) addEventHandler("buyFish", root, buyFish) @HassoN Link to comment
HassoN Posted July 29, 2019 Share Posted July 29, 2019 line 58 and 61, why they are the same button name? In that case, the panel will just close without doing the function... Either you put them all together or change the button name that closes the panel. Link to comment
selam Posted July 29, 2019 Author Share Posted July 29, 2019 @HassoN 5 minutes ago, HassoN said: line 58 and 61, why they are the same button name? In that case, the panel will just close without doing the function... Either you put them all together or change the button name that closes the panel. I cant do it Link to comment
HassoN Posted July 29, 2019 Share Posted July 29, 2019 (edited) 13 minutes ago, selam said: @HassoN I cant do it You can't...? -- client function PedLoad(ped) ped = createPed ( 36, 1623.5, 576.70001220703, 1.7999999523163 ) setElementFrozen( ped, true ) addEventHandler("onClientPedDamage", ped, cancelEvent) end addEventHandler("onClientResourceStart", resourceRoot, PedLoad) -- Marker coords -- X: 1623.5999755859 Y: 577.59997558594 Z: 0.79999995231628 marker = createMarker (1623.5999755859, 577.59997558594, 0.79999995231628, "cylinder", 1.2, 255, 0, 0, 140 ) function markerHit(plr) if (plr ~= localPlayer) then return false end guiSetVisible(GUIEditor.window[1], true) showCursor(true) end addEventHandler( "onClientMarkerHit", marker, markerHit) GUIEditor = { button = {}, window = {}, edit = {}, label = {} } addEventHandler("onClientResourceStart", resourceRoot, function() GUIEditor.window[1] = guiCreateWindow(448, 230, 504, 330, "Fisherman", false) guiWindowSetSizable(GUIEditor.window[1], false) guiSetAlpha(GUIEditor.window[1], 0.85) guiSetVisible(GUIEditor.window[1], false) GUIEditor.label[1] = guiCreateLabel(7, 33, 222, 38, " Fisherman: Hello! Get some fish food!", false, GUIEditor.window[1]) guiSetFont(GUIEditor.label[1], "default-bold-small") GUIEditor.label[2] = guiCreateLabel(10, 83, 105, 33, " x10 Food = 300$", false, GUIEditor.window[1]) guiSetFont(GUIEditor.label[2], "default-bold-small") GUIEditor.button[1] = guiCreateButton(22, 133, 122, 80, " BUY FOODS(10)", false, GUIEditor.window[1]) GUIEditor.label[3] = guiCreateLabel(283, 79, 192, 55, "Do you have enough fishes to sell?\n Let me have!", false, GUIEditor.window[1]) GUIEditor.label[4] = guiCreateLabel(293, 33, 68, 20, " Fisherman:", false, GUIEditor.window[1]) guiSetFont(GUIEditor.label[4], "default-bold-small") GUIEditor.button[2] = guiCreateButton(278, 134, 192, 73, " SELL FISHES", false, GUIEditor.window[1]) GUIEditor.label[5] = guiCreateLabel(113, 266, 283, 18, " Note! You can buy maximum 20 foods for per deal", false, GUIEditor.window[1]) guiSetFont(GUIEditor.label[5], "default-bold-small") GUIEditor.button[4] = guiCreateButton(443, 27, 51, 26, "X", false, GUIEditor.window[1]) guiSetFont(GUIEditor.button[4], "default-bold-small") end ) addEventHandler("onClientGUIClick", resourceRoot, function() if (source == GUIEditor.button[4]) then -- replace closeButton with your button name. guiSetVisible(GUIEditor.window[1], false) -- replace window with your window name. showCursor(false) end end) addEventHandler( "onClientGUIClick", resourceRoot, function() if (source == GUIEditor.button[1]) then -- The button to buy guiSetVisible(GUIEditor.window[1], false) -- The window to buy showCursor(false) buyFish() end end) function buyFish() local money = getPlayerMoney(localPlayer) triggerServerEvent("buyFish", resourceRoot) if (money >= 300) then outputChatBox("You have bought a fish food.") else outputChatBox("You don't have enough money.") end end -- server side function buyFish() takePlayerMoney(client, 300) end addEvent("buyFish", true) addEventHandler("buyFish", root, buyFish) Edited July 29, 2019 by HassoN Link to comment
selam Posted July 29, 2019 Author Share Posted July 29, 2019 @HassoN I guess you did not understand me, I am trying to buy fishes when I click "buy fishes" button. When I tried your last codes, now "X" button(for close) is not working also "buy fishes" is not working neither. Link to comment
HassoN Posted July 29, 2019 Share Posted July 29, 2019 1 hour ago, selam said: @HassoN I guess you did not understand me, I am trying to buy fishes when I click "buy fishes" button. When I tried your last codes, now "X" button(for close) is not working also "buy fishes" is not working neither. I have just tried the code. It is working fine. Link to comment
selam Posted July 30, 2019 Author Share Posted July 30, 2019 @HassoN I did not do what did you say, but I did something else and now its working. I added triggerserverevent to the line 61 Spoiler -- client side addEventHandler( "onClientGUIClick", resourceRoot, function() if (source == GUIEditor.button[1]) then -- The button to buy guiSetVisible(GUIEditor.window[1], true) -- The window to buy showCursor(true) triggerServerEvent("buyFish", resourceRoot) -- HERE I ADDED, THIS WASNT HERE BEFORE end end) function buyFish() local money = getPlayerMoney(localPlayer) triggerServerEvent("buyFish", resourceRoot) if (money >= 300) then outputChatBox("You have bought a fish food.") else outputChatBox("You don't have enough money.") end end Link to comment
HassoN Posted July 30, 2019 Share Posted July 30, 2019 1 hour ago, selam said: @HassoN I did not do what did you say, but I did something else and now its working. I added triggerserverevent to the line 61 Hide contents -- client side addEventHandler( "onClientGUIClick", resourceRoot, function() if (source == GUIEditor.button[1]) then -- The button to buy guiSetVisible(GUIEditor.window[1], true) -- The window to buy showCursor(true) triggerServerEvent("buyFish", resourceRoot) -- HERE I ADDED, THIS WASNT HERE BEFORE end end) function buyFish() local money = getPlayerMoney(localPlayer) triggerServerEvent("buyFish", resourceRoot) if (money >= 300) then outputChatBox("You have bought a fish food.") else outputChatBox("You don't have enough money.") end end The trigger was at its right place. 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