SAbJaN Posted April 16, 2012 Share Posted April 16, 2012 Hey guys, I've been having some problems in this Ghetto Blaster menu, when you right click on it, it opens, but when you click 'Close Menu' it does not remove it, and then the ghetto blaster stays on. Serverside: local function updateWorldItemValue(item, newvalue) exports['anticheat-system']:changeProtectedElementDataEx(item, "itemValue", newvalue) mysql_free_result(mysql_query(handler, "UPDATE worlditems SET itemvalue='" .. newvalue .. "' WHERE id=" .. getElementData(item, "id"))) end function toggleGhettoblaster(item) local state = tonumber(getElementData(item, "itemValue")) if state > 0 then exports.global:sendLocalMeAction(source, "turns the Ghettoblaster off.") else exports.global:sendLocalMeAction(source, "turns the Ghettoblaster on.") end updateWorldItemValue(item, -state) end addEvent("toggleGhettoblaster", true) addEventHandler("toggleGhettoblaster", getRootElement(), toggleGhettoblaster) function changeTrack(item, step) local current = getElementData(item, "itemValue") if current > 0 then current = current + step if current > #tracks then current = 1 elseif current < 1 then current = #tracks end updateWorldItemValue(item, current) exports.global:sendLocalMeAction(source, "retunes the Ghettoblaster.") end end addEvent("changeGhettoblasterTrack", true) addEventHandler("changeGhettoblasterTrack", getRootElement(), changeTrack) Client Side: local sound = false local made = false function checkForInterior() if ( (getElementDimension(getLocalPlayer()) == 1292) and not made ) then setRadioChannel(7) made = true elseif ( getElementDimension(getLocalPlayer()) ~= 1292 and made ) then setRadioChannel(0) made = false end end setTimer(checkForInterior, 1000, 0) blasters = { } function startGB() local itemValue = tonumber( getElementData(source, "itemValue") ) or 0 if itemValue > 0 then local x, y, z = getElementPosition(source) local px, py, pz = getElementPosition(getLocalPlayer()) if (getDistanceBetweenPoints3D(x, y, z, px, py, pz)<300) then local sound = playSound3D("ghettoblaster/" .. tracks[itemValue].file, x, y, z, true) --local sound = setRadioChannel ( tonumber( 3 ) ) blasters[source] = sound setSoundMaxDistance(sound, 20) if (isPedInVehicle(getLocalPlayer())) then setSoundVolume(sound, 0.5) end end end end function stopGB() if (blasters[source]~=nil) then local sound = blasters[source] --setRadioChannel ( tonumber( 0 ) ) stopSound(sound) blasters[source] = nil end end function elementStreamIn() if (getElementType(source)=="object") then local model = getElementModel(source) if (model==2226) then startGB() end end end addEventHandler("onClientElementStreamIn", getRootElement(), elementStreamIn) addEventHandler("onClientElementStreamOut", getRootElement(), stopGB) addEventHandler("onClientElementDestroy", getRootElement(), stopGB) function dampenSound(thePlayer) for key, value in pairs(blasters) do setSoundVolume(value, 0.5) end end addEventHandler("onClientVehicleEnter", getRootElement(), dampenSound) function boostSound(thePlayer) for key, value in pairs(blasters) do setSoundVolume(value, 1.0) end end addEventHandler("onClientVehicleExit", getRootElement(), boostSound) function toggleSound(dataname) if isElementStreamedIn(source) and getElementModel(source) == 2226 and dataname == "itemValue" then local state = getElementData(source, "itemValue") if state > 0 then stopGB() startGB() else stopGB() end end end addEventHandler("onClientElementDataChange", getResourceRootElement(), toggleSound) Link to comment
Absence2 Posted April 16, 2012 Share Posted April 16, 2012 there's more than this, I'm sure. Where's the GUI code? hint: check clientside. Link to comment
SAbJaN Posted April 16, 2012 Author Share Posted April 16, 2012 Theres not more too it, that was the clientside, and server side, This is the item_system client side if that helps: wItems, gItems, gKeys, colSlot, colName, colValue, items, lDescription, bDropItem, bUseItem, bShowItem, bDestroyItem, tabPanel, tabItems, tabWeapons = nil gWeapons, colWSlot, colWName, colWValue = nil toggleLabel, chkFood, chkKeys, chkDrugs, chkOther, chkBooks, chkClothes, chkElectronics, chkEmpty = nil wRightClick = nil bPickup, bToggle, bPreviousTrack, bNextTrack, bCloseMenu = nil ax, ay = nil item = nil showinvPlayer = nil setElementData( getLocalPlayer(), "exclusiveGUI", false, false ) -- setting this to false prevents possible problems with fridge/shelf inv. showFood = true showKeys = true showDrugs = true showOther = true showBooks = true showClothes = true showElectronics = true showEmpty = true activeTab = 0 -- PLEASE WAIT window local sx, sy = guiGetScreenSize( ) wWait = guiCreateButton( ( sx - 200 ) / 2, ( sy - 60 ) / 2, 200, 60, "Please wait a moment...", false ) guiSetEnabled( wWait, false ) guiSetVisible( wWait, false ) guiSetProperty( wWait, "AlwaysOnTop", "True" ) function clickItem(button, state, absX, absY, x, y, z, element) if (button == "right") and (state=="down") then if getElementData(getLocalPlayer(), "exclusiveGUI") then return end local px, py, pz = getElementPosition(getLocalPlayer()) if element and (getElementParent(getElementParent(element)) == getResourceRootElement(getResourceFromName("map-system")) or getElementParent(getElementParent(element)) == getResourceRootElement(getResourceFromName("interior-system"))) then element = nil end if not element then local wx, wy, wz = x, y, z local x, y, z = nil for key, value in ipairs(getElementsByType("object",getResourceRootElement())) do if isElementStreamedIn(value) then x, y, z = getElementPosition(value) local minx, miny, minz, maxx, maxy, maxz = getElementBoundingBox(value) local offset = 0.34 minx = x + minx - offset miny = y + miny - offset minz = z + minz - offset maxx = x + maxx + offset maxy = y + maxy + offset maxz = z + maxz + offset local dist = getDistanceBetweenPoints3D(x, y, z, px, py, pz) if (wx >= minx and wx <=maxx) and (wy >= miny and wy <=maxy) and (wz >= minz and wz <=maxz) then element = value break end end end end if element and getElementParent(getElementParent(element)) == getResourceRootElement() then if getDistanceBetweenPoints3D(x, y, z, px, py, pz) < 3 then if (wRightClick) then hideItemMenu() end ax = absX ay = absY item = element showItemMenu() else outputChatBox("You are too far away from that item.", 255, 0, 0) end else if (wRightClick) then hideItemMenu() end end end end addEventHandler("onClientClick", getRootElement(), clickItem, true) function showItemMenu() local itemID = getElementData(item, "itemID") local itemValue = getElementData(item, "itemValue") local itemName = getItemName( itemID, itemValue ) if itemID ~= 80 then itemName = itemName .. " (" .. getItemValue( itemID, itemValue ) .. ")" end wRightClick = guiCreateWindow(ax, ay, 150, 200, itemName, false) local y = 0.13 if itemID == 81 or itemID == 103 then bPickup = guiCreateButton(0.05, y, 0.9, 0.1, "Open", true, wRightClick) addEventHandler("onClientGUIClick", bPickup, function(button) if button=="left" and not getElementData(localPlayer, "exclusiveGUI") then triggerServerEvent( "openFreakinInventory", getLocalPlayer(), item, ax, ay ) hideItemMenu() end end, false ) else bPickup = guiCreateButton(0.05, y, 0.9, 0.1, "Pick Item Up", true, wRightClick) addEventHandler("onClientGUIClick", bPickup, pickupItem, false) end y = y + 0.14 if itemID == 54 then -- Ghettoblaster if getElementData(item, "itemValue") > 0 then bToggle = guiCreateButton(0.05, y, 0.9, 0.1, "Turn Off", true, wRightClick) y = y + 0.14 bPreviousTrack = guiCreateButton(0.05, y, 0.42, 0.1, "Previous", true, wRightClick) addEventHandler("onClientGUIClick", bPreviousTrack, function() triggerServerEvent("changeGhettoblasterTrack", getLocalPlayer(), item, -1) end, false) bNextTrack = guiCreateButton(0.53, y, 0.42, 0.1, "Next", true, wRightClick) addEventHandler("onClientGUIClick", bNextTrack, function() triggerServerEvent("changeGhettoblasterTrack", getLocalPlayer(), item, 1) end, false) else bToggle = guiCreateButton(0.05, y, 0.9, 0.1, "Turn On", true, wRightClick) end addEventHandler("onClientGUIClick", bToggle, toggleGhettoblaster, false) y = y + 0.14 end bCloseMenu = guiCreateButton(0.05, y, 0.9, 0.1, "Close Menu", true, wRightClick) addEventHandler("onClientGUIClick", bCloseMenu, hideItemMenu, false) end function hideItemMenu() if (isElement(bPickup)) then destroyElement(bPickup) end bPickup = nil if (isElement(bToggle)) then destroyElement(bToggle) end bToggle = nil if (isElement(bPreviousTrack)) then destroyElement(bPreviousTrack) end bPreviousTrack = nil if (isElement(bNextTrack)) then destroyElement(bNextTrack) end bNextTrack = nil if (isElement(bCloseMenu)) then destroyElement(bCloseMenu) end bCloseMenu = nil if (isElement(wRightClick)) then destroyElement(wRightClick) end wRightClick = nil ax = nil ay = nil item = nil showCursor(false) triggerEvent("cursorHide", getLocalPlayer()) end function updateMenu(dataname) if source == item and dataname == "itemValue" and getElementData(source, "itemID") == 54 then -- update the track while you're in menu guiSetText(wRightClick, "GHETTOBLASTER (" .. getElementData(source, "itemValue") .. ")") end end addEventHandler("onClientElementDataChange", getRootElement(), updateMenu) function toggleGhettoblaster(button, state, absX, absY, step) triggerServerEvent("toggleGhettoblaster", getLocalPlayer(), item) hideItemMenu() end function pickupItem(button, state, item) if (button=="left") then local restrain = getElementData(getLocalPlayer(), "restrain") if (restrain) and (restrain==1) then outputChatBox("You are cuffed.", 255, 0, 0) elseif getElementData(item, "itemID") > 0 and not hasSpaceForItem(getLocalPlayer(), getElementData(item, "itemID")) then outputChatBox("Your Inventory is full.", 255, 0, 0) elseif isElement(item) then if wRightClick then showCursor(false) triggerEvent("cursorHide", getLocalPlayer()) end local itemID = tonumber(getElementData(item, "itemID")) or 0 local itemValue = tonumber(getElementData(item, "itemValue")) or 0 if itemID < 0 and itemID ~= -100 then local free, totalfree = exports.weaponcap:getFreeAmmo( -itemID ) local cap = exports.weaponcap:getAmmoCap( -itemID ) if totalfree == 0 then outputChatBox( "You've got all weapons you can carry.", 255, 0, 0 ) elseif free == 0 and cap == 0 then local weaponName = "other weapon" local slot = getSlotFromWeapon( -itemID ) if slot and slot ~= 0 and getPedTotalAmmo( getLocalPlayer(), slot ) > 0 then local weapon = getPedWeapon( getLocalPlayer(), slot ) weaponName = getItemName( -weapon ) end outputChatBox( "You don't carry that weapon, please drop your " .. weaponName .. " first.", 255, 0, 0 ) elseif free == 0 then outputChatBox( "You can't carry any more of that weapon.", 255, 0, 0 ) else triggerServerEvent("pickupItem", getLocalPlayer(), item, free ) end else triggerServerEvent("pickupItem", getLocalPlayer(), item) end if wRightClick then hideItemMenu() end end end end function toggleCategory() if (source==chkFood) then showFood = not showFood elseif (source==chkKeys) then showKeys = not showKeys elseif (source==chkDrugs) then showDrugs = not showDrugs elseif (source==chkBooks) then showBooks = not showBooks elseif (source==chkClothes) then showClothes = not showClothes elseif (source==chkElectronics) then showElectronics = not showElectronics elseif (source==chkOther) then showOther = not showOther elseif (source==chkEmpty) then showEmpty = not showEmpty Link to comment
SAbJaN Posted April 16, 2012 Author Share Posted April 16, 2012 http://pastebin.com/vZFNkXbT 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