Benevolence Posted October 8, 2011 Share Posted October 8, 2011 So I'm trying to make it so if the player is in the safe zone (a rectangular colShape) then that is when he can access the Weapon Shop GUI (by pressing f1). If he's not in the safe zone, then he can't access it. Right now, the player can access it from anywhere he wants. I'm guessing I need to use isElementWithinColShape but the script is kind of messy since I didn't make it so I don't know exactly how and where to put it. This is the full script: -- server side addEvent ("viewGUI", true) function showGui (hitPlayer, matchingDimension) triggerClientEvent ("viewGUI", hitPlayer) end addCommandHandler("shop",showGui) addEvent ("weapBuy", true) addEventHandler ("weapBuy", getRootElement(), function(id, cost, name, ammo) if (getPlayerMoney (source) >= tonumber(cost)) then outputChatBox ("-------------------------------WEAPON SHOP-------------------------------", source, 255, 0, 0, false) outputChatBox ("You Bought a " .. name, source, 255, 0, 0, false) --outputChatBox ("ID: " .. id, source, 255, 0, 0, false) outputChatBox ("Cost: $" .. cost, source, 255, 0, 0, false) outputChatBox ("------------------------------------------------------------------------------------", source, 255, 0, 0, false) takePlayerMoney (source, tonumber (cost)) giveWeapon(source, tonumber(id),1000) else outputChatBox ("You are too poor!", source, 255, 0, 0, false) end end) addEvent ("carBuy", true) addEventHandler ("carBuy", getRootElement(), function(id2, cost2, name2,x, y, z, sRz) if (getPlayerMoney (source) >= tonumber(cost2)) then outputChatBox ("Bought a " .. name2, source, 255, 0, 0, false) outputChatBox ("ID: " .. id2, source, 255, 0, 0, false) outputChatBox ("Cost: " .. cost2, source, 255, 0, 0, false) takePlayerMoney (source, tonumber (cost2)) local x,y,z = getElementPosition (source) local vehicle = createVehicle (id2, x, y, z, 0, 0, sRz ) warpPedIntoVehicle(source, vehicle) else outputChatBox ("You are too poor!", source, 255, 0, 0, false) end end) function vExplode () toggleVehicleRespawn ( source, false ) setTimer(destroyElement, 5000, 1, source) end addEventHandler ( "onVehicleExplode", getResourceRootElement(getThisResource()), vExplode ) function skillButton (id, cost) if (id == "0") then skillBuyPlayer (250,source,69) elseif (id == "1") then skillBuyPlayer (2000,source,70) elseif (id == "2") then skillBuyPlayer (500,source,71) elseif (id == "3") then skillBuyPlayer (5800,source,72) elseif (id == "4") then skillBuyPlayer (11000,source,73) elseif (id == "5") then skillBuyPlayer (7500,source,74) elseif (id == "6") then skillBuyPlayer (5500,source,75) elseif (id == "7") then skillBuyPlayer (7000,source,76) elseif (id == "8") then skillBuyPlayer (8000,source,77) elseif (id == "9") then skillBuyPlayer (10000,source,78) elseif (id == "10") then skillBuyPlayer (10000,source,79) end end addEvent ("skillBuy", true) addEventHandler ("skillBuy", getRootElement(),skillButton) function skillBuyPlayer (cash,player,id) if (getPlayerMoney (player) >= cash) then takePlayerMoney (player,cash) setPedStat(player, id, 999) else outputChatBox ("You are too poor!", player, 255,0,0) end end -- client side shopWindow = guiCreateWindow(367,105,334,435,"Shop",false) guiSetVisible (shopWindow, false) guiSetAlpha(shopWindow,1) guiWindowSetSizable(shopWindow,false) tabPanel = guiCreateTabPanel(11,23,314,372,false,shopWindow) --tab = guiCreateTab("Vehicles",tabPanel) --carGrid = guiCreateGridList(4,6,305,291,false,tab) --guiGridListSetSelectionMode(carGrid,0) --carColumn = guiGridListAddColumn(carGrid,"Vehicle",0.5) costColumn = guiGridListAddColumn(carGrid,"$",0.3) --carButton = guiCreateButton(107,308,100,29,"Buy Vehicle",false,tab) tab2 = guiCreateTab("Weapons",tabPanel) weapGrid = guiCreateGridList(4,6,305,291,false,tab2) guiGridListSetSelectionMode(weapGrid,0) weapColumn = guiGridListAddColumn(weapGrid,"Weapon",0.5) costColumn = guiGridListAddColumn(weapGrid,"Cost",0.3) weapButton = guiCreateButton(107,308,100,29,"Buy Weapon",false,tab2) --tab3 = guiCreateTab("Skills",tabPanel) --skillsGrid = guiCreateGridList(4,6,305,291,false,tab3) --guiGridListSetSelectionMode(skillsGrid,0) --costColumn = guiGridListAddColumn(skillsGrid,"ID",0.3) --skillsColumn = guiGridListAddColumn(skillsGrid,"Skill name",0.5) --costColumn = guiGridListAddColumn(skillsGrid,"$",0.3) --skillsButton = guiCreateButton(107,308,100,29,"Buy Skill",false,tab3) local weapons = {{31,3500},{4,15000},{5,500},{6,1500},{7,3500},{8,10000},{9,12000},{22,2500},{23,2700},{24,4000},{25,4200},{26,9000},{27,8000},{28,6500},{29,7000},{30,3500},{32,7800},{33,11000},{34,16000},{16,20000}} for i,v in ipairs (weapons) do local itemName = getWeaponNameFromID (v[1]) local row = guiGridListAddRow (weapGrid) guiGridListSetItemText (weapGrid, row, 1, itemName, false, true) guiGridListSetItemText (weapGrid, row, 2, tostring(v[2]), false, true) end guiSetAlpha(weapGrid,1) closeButton = guiCreateButton(112,401,113,24,"Close Shop",false,shopWindow) --local vehicles = {{579,60000},{400,60000},{404,28000},{489,65000},{505,65000},{479,45000},{442,45000},{458,45000},{602,100000},{496,42500},{401,41000},{518,60000},{527,75000},{589,75000},{419,45000},{533,75000},{526,50000},{474,55000},{545,50000},{517,45000},{410,41000},{600,50000},{436,41000},{580,50000},{439,75000},{549,75000},{491,45000},{445,45000},{507,45000},{585,45000},{587,100000},{466,55000},{492,50000},{546,45000},{551,45000},{516,45000},{467,45000},{426,47500},{547,45000},{405,55000},{409,75000},{550,45000},{566,45000},{540,45000},{421,50000},{529,45000},{402,250000},{542,65000},{603,150000},{475,75000},{562,175000},{565,95000},{559,125000},{561,50000},{560,125000},{558,100000},{429,150000},{541,150000},{415,150000},{480,95000},{434,100000},{494,200000},{502,200000},{503,200000},{411,300000},{506,150000},{451,300000},{555,95000},{477,95000},{499,25000},{498,25000},{578,50000},{486,70000},{406,500000},{573,250000},{455,75000},{588,50000},{403,75000},{423,1000000},{414,50000},{443,75000},{515,75000},{514,75000},{531,12000},{456,45000},{422,45000},{482,95000},{530,12000},{418,45000},{572,12000},{582,50000},{413,50000},{440,50000},{543,65000},{583,12000},{478,35000},{554,50000},{536,75000},{575,75000},{534,75000},{567,75000},{535,75000},{576,75000},{412,75000},{568,75000},{457,12000},{483,45000},{508,40000},{571,10000},{500,55000},{444,250000},{556,250000},{557,250000},{495,100000},{539,75000},{485,12000},{431,60000},{438,45000},{437,60000},{574,12000},{420,45000},{525,75000},{408,50000},{428,65000}} --for i,v in ipairs (vehicles) do --local carName = getVehicleNameFromModel (v[1]) --local row = guiGridListAddRow (carGrid) --guiGridListSetItemText (carGrid, row, 1, carName, false, true) --guiGridListSetItemText (carGrid, row, 2, tostring(v[2]), false, true) --end skillsTable = {{"0","Colt-45 Skill","250"},{"1","Silenced-Pistol Skill","500"},{"2","Desert-Eagle Skill","2000"},{"3","Shotgun Skill","5800"},{"4","Sawed-off Skill","11000"},{"5","Spaz-12 Skill","7500"},{"6","Uzi Skill","5500"},{"7","MP5 Skill","8000"},{"8","AK-47 Skill","10000"},{"9","M4 Skill","9000"},{"10","Sniper","17000"}} for i,v in ipairs (skillsTable) do local row = guiGridListAddRow (skillsGrid) guiGridListSetItemText (skillsGrid, row, 1, v[1], false, true) guiGridListSetItemText (skillsGrid, row, 2, v[2], false, true) guiGridListSetItemText (skillsGrid, row, 3, v[3], false, true) end function closeShop() if guiGetVisible(shopWindow) then guiSetVisible(shopWindow,false) showCursor(false) end end addEventHandler ("onClientGUIClick", closeButton, closeShop) addEvent ("viewGUI", true) function viewGUI () if (getLocalPlayer() == source) then guiSetVisible (shopWindow, true) showCursor (true) end end addEventHandler ("viewGUI", getRootElement(), viewGUI) function onClientWeapBuy (button, state, absoluteX, absoluteYe) if (source == weapButton) then guiSetVisible (shopWindow, false) showCursor (false) if (guiGridListGetSelectedItem (weapGrid)) then local itemName = guiGridListGetItemText (weapGrid, guiGridListGetSelectedItem (weapGrid), 1) local itemID = getWeaponIDFromName (itemName) local itemCost = guiGridListGetItemText (weapGrid, guiGridListGetSelectedItem (weapGrid), 2) triggerServerEvent ("weapBuy", getLocalPlayer(), itemID, itemCost, itemName) end end end addEventHandler ("onClientGUIClick", weapButton, onClientWeapBuy) function onClientCarBuy (button, state, absoluteX, absoluteYe) if (source == carButton) then guiSetVisible (shopWindow, false) showCursor (false) if (guiGridListGetSelectedItem (carGrid)) then local carName = guiGridListGetItemText (carGrid, guiGridListGetSelectedItem (carGrid), 1) local carID = getVehicleModelFromName (carName) local carCost = guiGridListGetItemText (carGrid, guiGridListGetSelectedItem (carGrid), 2) triggerServerEvent ("carBuy", getLocalPlayer(), carID, carCost, carName) end end end addEventHandler ("onClientGUIClick", carButton, onClientCarBuy) function onClientSkillBuy (button, state, absoluteX, absoluteYe) if (source == skillsButton) then guiSetVisible (shopWindow, false) showCursor (false) if (guiGridListGetSelectedItem (skillsGrid)) then local id = guiGridListGetItemText (skillsGrid, guiGridListGetSelectedItem (skillsGrid), 1) local cost = guiGridListGetItemText (skillsGrid, guiGridListGetSelectedItem (skillsGrid), 2) triggerServerEvent ("skillBuy", getLocalPlayer(), id, cost) end end end addEventHandler ("onClientGUIClick", skillsButton, onClientSkillBuy) function ToggleShop() if guiGetVisible(shopWindow) == true then guiSetVisible(shopWindow,false) showCursor(false) else guiSetVisible(shopWindow,true) showCursor(true) end end bindKey("F1","down",ToggleShop) Link to comment
Aibo Posted October 8, 2011 Share Posted October 8, 2011 function showGui(player) if isElementWithinColshape(player, yourSafeZoneColshape) then triggerClientEvent(player, "viewGUI", root) end end addCommandHandler("shop",showGui) Link to comment
SDK Posted October 8, 2011 Share Posted October 8, 2011 And function ToggleShop() if not isElementWithinColshape(localPlayer, yourSafeZoneColshape) or guiGetVisible(shopWindow) == true then guiSetVisible(shopWindow,false) showCursor(false) else guiSetVisible(shopWindow,true) showCursor(true) end end bindKey("F1","down",ToggleShop) Link to comment
qaisjp Posted October 8, 2011 Share Posted October 8, 2011 The radar shape is server side not client sided SDK. 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