bosslorenz Posted May 18, 2015 Share Posted May 18, 2015 -CLIENT- local weaponshopmarker1 = createMarker( 1302, -1377, 12.7, "cylinder", 1, 0, 0, 255, 255) GUIEditor = { button = {}, staticimage = {}, progressbar = {}, window = {} } function showweap1() GUIEditor.window[1] = guiCreateWindow(247, 140, 291, 393, "LORENZ WEAPON SHOP TEST", false) guiWindowSetSizable(GUIEditor.window[1], false) guiSetProperty(GUIEditor.window[1], "CaptionColour", "FF1100FF") GUIEditor.button[1] = guiCreateButton(162, 73, 92, 66, "M4 ($5000)", false, GUIEditor.window[1]) guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FFFF0000") GUIEditor.button[2] = guiCreateButton(162, 255, 92, 63, "MP5 ($3000)", false, GUIEditor.window[1]) guiSetProperty(GUIEditor.button[2], "NormalTextColour", "FFFF003B") GUIEditor.staticimage[1] = guiCreateStaticImage(23, 71, 107, 63, "m4.png", false, GUIEditor.window[1]) GUIEditor.staticimage[2] = guiCreateStaticImage(23, 255, 105, 63, "Smp5.png", false, GUIEditor.window[1]) showCursor(true) end function weaponshop1() guiSetVisible(GUIEditor.window[1], true) end addEventHandler("onClientMarkerHit", weaponshopmarker1, showweap1) function buy1 () if (source == GUIEditors.button[1]) then showCursor(true) triggerServerEvent ("givem4", localPlayer) end end addEventHandler("onClientGUIClick", root, buy1) -SERVER- function giveweaponm4() if ( getPlayerMoney (source) >= 5000 ) then takePlayerMoney(source, 5000) giveWeapon (source,31,150,true) end end addEvent("givem4",true) addEventHandler("givem4", root, giveweaponm4) problem is when I click button[1] it doesnt give me the weapon, becoz it doesnt takemy $5000 money. Help Link to comment
xXMADEXx Posted May 18, 2015 Share Posted May 18, 2015 I don't see any errors, does debugscript notify you of any errors? (/debugscript 3) Link to comment
bosslorenz Posted May 18, 2015 Author Share Posted May 18, 2015 I don't see any errors, does debugscript notify you of any errors? (/debugscript 3) No errors Link to comment
Walid Posted May 18, 2015 Share Posted May 18, 2015 Try this it should work -- Client side -- Client side local weaponshopmarker1 = createMarker( 1302, -1377, 12.7, "cylinder", 1, 0, 0, 255, 255) GUIEditor = { button = {}, staticimage = {}, progressbar = {}, window = {} } function showweap1() GUIEditor.window[1] = guiCreateWindow(247, 140, 291, 393, "LORENZ WEAPON SHOP TEST", false) guiWindowSetSizable(GUIEditor.window[1], false) guiSetProperty(GUIEditor.window[1], "CaptionColour", "FF1100FF") guiSetVisible(GUIEditor.window[1],false) GUIEditor.button[1] = guiCreateButton(162, 73, 92, 66, "M4 ($5000)", false, GUIEditor.window[1]) guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FFFF0000") GUIEditor.button[2] = guiCreateButton(162, 255, 92, 63, "MP5 ($3000)", false, GUIEditor.window[1]) guiSetProperty(GUIEditor.button[2], "NormalTextColour", "FFFF003B") GUIEditor.staticimage[1] = guiCreateStaticImage(23, 71, 107, 63, "m4.png", false, GUIEditor.window[1]) GUIEditor.staticimage[2] = guiCreateStaticImage(23, 255, 105, 63, "Smp5.png", false, GUIEditor.window[1]) showCursor(true) -- events addEventHandler("onClientGUIClick", GUIEditor.button[1], buy1,false) end function weaponshop1() guiSetVisible(GUIEditor.window[1], true) showCursor(true) end addEventHandler("onClientMarkerHit", weaponshopmarker1, showweap1) function buy1 () if (source == GUIEditors.button[1]) then showCursor(true) triggerServerEvent ("givem4", localPlayer) end end -- Server side function giveweaponm4() if ( getPlayerMoney (source) >= 5000 ) then takePlayerMoney(source, 5000) giveWeapon (source,31,150,true) end end addEvent("givem4",true) addEventHandler("givem4", root, giveweaponm4) Link to comment
bosslorenz Posted May 20, 2015 Author Share Posted May 20, 2015 CLIENT marker1 = createMarker(1310, -1368.4000244141, 12.6, "cylinder", 1, 0, 0, 255, 255) GUIEditor = { button = {}, window = {}, progressbar = {} } addEventHandler("onClientResourceStart", resourceRoot, function() window1 = guiCreateWindow(283, 116, 173, 360, "TEST", false) guiWindowSetMovable(window1, false) guiWindowSetSizable(window1, false) guiSetVisible(window1,false) button1 = guiCreateButton(53, 66, 102, 49, "m4", false, window1) button2 = guiCreateButton(25, 158, 112, 58, "mp5", false, window1) button3 = guiCreateButton(117, 299, 47, 51, "close", false, window1) end ) function openGui() guiSetVisible(window1, true) showCursor(true) end addEventHandler("onClientMarkerHit", marker1, openGui) function buym4(thePlayer,button1) if ( source == button1) then showCursor(false) guiSetVisible(window1,false) triggerServerEvent("givem4", localPlayer) end end addEventHandler("onClientGUIClick", root, buym4) function buymp5(thePlayer,button2) if ( source == button2) then showCursor(false) guiSetVisible(window1,false) triggerServerEvent("givemp5", localPlayer) end end addEventHandler("onClientGUIClick", root, buymp5) function closeGui() if ( source == button3) then showCursor(false) guiSetVisible(window1,false) end end addEventHandler("onClientGUIClick", root, closeGui) SERVER function buym4() local playerMoney = getPlayerMoney(source) if (playerMoney >= 40000) then takePlayerMoney(source,40000) giveWeapon(source,31,200) end end addEvent("givem4",true) addEventHandler("givem4", root, buym4) function buymp5() local playerMoney = getPlayerMoney(source) if (playerMoney >= 10000) then takePlayerMoney(source,10000) giveWeapon(source,29,150) end end addEvent("givemp5",true) addEventHandler("givemp5", root, buymp5) When i click button1 and button2 its not working. It doesnt takemymoney and doesnt giveWeapon. Only the close button3 works! Help pls! Link to comment
MTA Team 0xCiBeR Posted May 20, 2015 MTA Team Share Posted May 20, 2015 Client: marker1 = createMarker(1310, -1368.4000244141, 12.6, "cylinder", 1, 0, 0, 255, 255) GUIEditor = { button = {}, window = {}, progressbar = {} } addEventHandler("onClientResourceStart", resourceRoot, function() window1 = guiCreateWindow(283, 116, 173, 360, "TEST", false) guiWindowSetMovable(window1, false) guiWindowSetSizable(window1, false) guiSetVisible(window1,false) button1 = guiCreateButton(53, 66, 102, 49, "m4", false, window1) button2 = guiCreateButton(25, 158, 112, 58, "mp5", false, window1) button3 = guiCreateButton(117, 299, 47, 51, "close", false, window1) end ) function openGui() guiSetVisible(window1, true) showCursor(true) end addEventHandler("onClientMarkerHit", marker1, openGui) function buym4() if ( source == button1) then showCursor(false) guiSetVisible(window1,false) triggerServerEvent("givem4", localPlayer) end end addEventHandler("onClientGUIClick", root, buym4) function buymp5() if ( source == button2) then showCursor(false) guiSetVisible(window1,false) triggerServerEvent("givemp5", localPlayer) end end addEventHandler("onClientGUIClick", root, buymp5) function closeGui() if ( source == button3) then showCursor(false) guiSetVisible(window1,false) end end addEventHandler("onClientGUIClick", root, closeGui) You were messing with event args. string button, string state, int absoluteX, int absoluteY Also you should use client for security reasons on server-side event trigger. Link to comment
bosslorenz Posted May 20, 2015 Author Share Posted May 20, 2015 Got it working now. --C-- marker1 = createMarker(1310, -1368.4000244141, 12.6, "cylinder", 1, 0, 0, 255, 255) GUIEditor = { button = {}, window = {}, progressbar = {} } addEventHandler("onClientResourceStart", resourceRoot, function() window1 = guiCreateWindow(283, 116, 173, 360, "TEST", false) guiWindowSetMovable(window1, false) guiWindowSetSizable(window1, false) guiSetVisible(window1,false) button1 = guiCreateButton(53, 66, 102, 49, "m4", false, window1) button2 = guiCreateButton(25, 158, 112, 58, "mp5", false, window1) button3 = guiCreateButton(117, 299, 47, 51, "close", false, window1) end ) function openGui() guiSetVisible(window1, true) showCursor(true) end addEventHandler("onClientMarkerHit", marker1, openGui) function buym4() if ( source == button1) then showCursor(false) guiSetVisible(window1,false) triggerServerEvent("givem4", localPlayer) end end addEventHandler("onClientGUIClick", root, buym4) function buymp5() if ( source == button2) then showCursor(false) guiSetVisible(window1,false) triggerServerEvent("givemp5", localPlayer) end end addEventHandler("onClientGUIClick", root, buymp5) function closeGui() if ( source == button3) then showCursor(false) guiSetVisible(window1,false) end end addEventHandler("onClientGUIClick", root, closeGui) -S- function buym4() local playerMoney = getPlayerMoney(source) if (playerMoney >= 40000) then takePlayerMoney(source,40000) giveWeapon(source,31,200) end end addEvent("givem4",true) addEventHandler("givem4", root, buym4) function buymp5() local playerMoney = getPlayerMoney(source) if (playerMoney >= 10000) then takePlayerMoney(source,10000) giveWeapon(source,29,150) end end addEvent("givemp5",true) addEventHandler("givemp5", root, buymp5) Does someone knows how can I make this separate sell. Just like sell M4 with no bullets. and after buying M4 you can buy bullets for M4. But without the weapon you cannot buy ammo for m4. And also saves the weapon to the account even when ammo runs out, id doesnt remove the weapon from the player. Link to comment
Walid Posted May 20, 2015 Share Posted May 20, 2015 Does someone knows how can I make this separate sell. Just like sell M4 with no bullets. and after buying M4 you can buy bullets for M4. But without the weapon you cannot buy ammo for m4. And also saves the weapon to the account even when ammo runs out, id doesnt remove the weapon from the player. use setAccountData() Link to comment
bosslorenz Posted May 21, 2015 Author Share Posted May 21, 2015 Heres the code I made. Buy rocket launcher working. Problem 1: But it looks like it still allows me to buy rocket launcher ammo even if I dont have a Rocket Launcher. Problem 2: Also when I buy rocket launcher, why does it give me a free 30 ammo, I have put only giveWeapon(source,35) --SERVER-- function buym4() local playerMoney = getPlayerMoney(source) if (playerMoney >= 40000) then takePlayerMoney(source,40000) outputChatBox ("You have bought a Rocket Launcher.", source, 0, 255, 0, false) giveWeapon(source,35) local weapons = { } for i = 0, 12 do weapons[ i ] = { weapon = getPedWeapon( source ), ammo = getPedTotalAmmo( source, i ) } end setAccountData ( getPlayerAccount ( source ), "ownRlauncher", toJSON( weapons ) ) else outputChatBox ("Insufficient money to buy this weapon.", source, 255, 0, 0, false) end end addEvent("givem4",true) addEventHandler("givem4", root, buym4) function buym4ammo() local playerMoney = getPlayerMoney(source) local weapons = getAccountData( getPlayerAccount ( source ), "account.weapons" ) if ( weapons ) then weapons = fromJSON( weapons ) end if (playerMoney >= 10000) and getAccountData ( getPlayerAccount ( source ), "ownRlauncher" ) then outputChatBox ("You have bought a 150 Rocket Launcher Ammo.", source, 0, 255, 0, false) takePlayerMoney(source,10000) setWeaponAmmo(source,35,150) elseif (playerMoney < 10000) and getAccountData ( getPlayerAccount ( source ), "ownRlauncher" ) then outputChatBox ("Insufficient money to buy this ammo.", source, 255, 0, 0, false) elseif (playerMoney >= 10000) and ( not getAccountData ( getPlayerAccount ( source ), "ownRlauncher" ) ) then outputChatBox ("You need to buy first a Rocket Launcher.", source, 255, 0, 0, false) end end addEvent("givem4ammo",true) addEventHandler("givem4ammo", root, buym4ammo) --CLIENT-- marker1 = createMarker(1310, -1368.4000244141, 12.6, "cylinder", 1, 0, 0, 255, 255) GUIEditor = { button = {}, window = {}, progressbar = {} } addEventHandler("onClientResourceStart", resourceRoot, function() window1 = guiCreateWindow(283, 116, 173, 360, "TEST", false) guiWindowSetMovable(window1, false) guiWindowSetSizable(window1, false) guiSetVisible(window1,false) button1 = guiCreateButton(53, 66, 102, 49, "m4", false, window1) button2 = guiCreateButton(25, 158, 112, 58, "mp5", false, window1) button3 = guiCreateButton(117, 299, 47, 51, "close", false, window1) end ) function openGui() guiSetVisible(window1, true) showCursor(true) end addEventHandler("onClientMarkerHit", marker1, openGui) function buym4() if ( source == button1) then showCursor(false) guiSetVisible(window1,false) triggerServerEvent("givem4", localPlayer) end end addEventHandler("onClientGUIClick", root, buym4) function buym4ammo() if ( source == button2) then showCursor(false) guiSetVisible(window1,false) triggerServerEvent("givem4ammo", localPlayer) end end addEventHandler("onClientGUIClick", root, buym4ammo) function closeGui() if ( source == button3) then showCursor(false) guiSetVisible(window1,false) end end addEventHandler("onClientGUIClick", root, closeGui) 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