mgdmgd Posted July 2, 2017 Posted July 2, 2017 (edited) Can somebody help me with this error? Bad argument @'guiSetEnabled' [Expected gui-element at argument 1, got nil] That's the code local function openElementInventory( ax, ay ) if not getElementData(localPlayer, "exclusiveGUI") then hideMenu() element = source local w, h = 500, 500 local type = getElementModel(source) == 2147 and "Fridge" or getElementModel(source) == 3761 and "Shelf" or (( getElementType(source) == "vehicle" and "Vehicle" ) or ( getElementType(source) == "interior" and "Mailbox" ) or "Safe" ) setElementData(localPlayer, "exclusiveGUI", true, false) ax = math.max( 10, math.min( sx - 410, ax ) ) ay = math.max( 10, math.min( sy - 310, ay ) ) wInventory = guiCreateStaticImage(ax-w/2, ay-h/2, w, h, ":resources/window_body.png",false)--type .. " Inventory", false) --guiWindowSetSizable(wInventory, false) lYou = guiCreateLabel(0.25, 0.1, 0.87, 0.05, "YOU", true, wInventory) guiSetFont(lYou, "default-bold-small") lVehicle = guiCreateLabel(0.675, 0.1, 0.87, 0.05, type:upper(), true, wInventory) guiSetFont(lVehicle, "default-bold-small") gUserItems = guiCreateGridList(0.05, 0.15, 0.45, 0.65+0.075, true, wInventory) UIColName = guiGridListAddColumn(gUserItems, "Name", 0.9) gElementItems = guiCreateGridList(0.5, 0.15, 0.45, 0.65+0.075, true, wInventory) VIColName = guiGridListAddColumn(gElementItems, "Name", 0.9) bCloseInventory = guiCreateButton(0.05, 0.9, 0.9, 0.075, "Close Inventory", true, wInventory) addEventHandler("onClientGUIClick", bCloseInventory, hideMenu, false) bGiveItem = guiCreateButton(0.05, 0.81, 0.45, 0.075, "Move", true, wInventory) addEventHandler("onClientGUIClick", bGiveItem, moveToElement, false) addEventHandler("onClientGUIDoubleClick", gUserItems, moveToElement, false) bTakeItem = guiCreateButton(0.5, 0.81, 0.45, 0.075, " Move ", true, wInventory) addEventHandler("onClientGUIClick", bTakeItem, moveFromElement, false) addEventHandler("onClientGUIDoubleClick", gElementItems, moveFromElement, false) addEventHandler("onClientGUIClick", gElementItems, adminCheck, false) forceUpdate() showCursor( true ) else outputChatBox("You can't access that inventory at the moment.", 255, 0, 0) end end addEvent( "openElementInventory", true ) addEventHandler( "openElementInventory", getRootElement(), openElementInventory ) addEventHandler( "onClientChangeChar", getRootElement(), hideMenu ) addEvent( "fini:~emMove", true ) addEventHandler( "fini:~emMove", getLocalPlayer(), function( ) guiSetEnabled( wInventory, true ) guiSetVisible( wWait, false ) end ) Edited July 2, 2017 by mgdmgd
Seba500PLK Posted July 2, 2017 Posted July 2, 2017 local wInventory = false local function openElementInventory( ax, ay ) ... end addEvent( "openElementInventory", true ) addEventHandler( "openElementInventory", getRootElement(), openElementInventory ) addEventHandler( "onClientChangeChar", getRootElement(), hideMenu ) addEvent( "fini:~emMove", true ) addEventHandler( "fini:~emMove", getLocalPlayer(), function( ) guiSetEnabled( wInventory, true ) guiSetVisible( wWait, false ) end )
mgdmgd Posted July 2, 2017 Author Posted July 2, 2017 Bad argument @ 'guiSetEnabled' [Expected gui-element at argument 1, got boolean] That's what I am getting now @Seba500PLK
DiGiTal Posted July 2, 2017 Posted July 2, 2017 @Seba500PLK I'm learning the scripting , why we need change local function to function?
koragg Posted July 2, 2017 Posted July 2, 2017 addEvent( "fini:~emMove", true ) addEventHandler( "fini:~emMove", getLocalPlayer(), function( ) if wInventory then guiSetEnabled( wInventory, true ) end guiSetVisible( wWait, false ) end )
mgdmgd Posted July 2, 2017 Author Posted July 2, 2017 Alright so I get the move row in the gui now and no errors showing but when I click it nothing happens at all. Those the codes if item:getItemUseNewPickupMethod(itemID) then if item:canItemBeMoved(itemID) then if itemworld:can(localPlayer, "move", element) then if not rcMenu then rcMenu = rightclick:create(itemName) end row.move = rightclick:addrow("Move") end end end if not noPickupFor[itemID] and itemworld:can(localPlayer, "pickup", element) then if not rcMenu then rcMenu = rightclick:create(itemName) end row.pickup = rightclick:addrow("Pick Up") addEventHandler("onClientGUIClick", row.pickup, function (button, state) triggerServerEvent("moveWorldItemToElement", localPlayer, element, localPlayer) end, false) end if not noPropertiesFor[itemID] and itemworld:canEditItemProperties(localPlayer, element) then if not rcMenu then rcMenu = rightclick:create(itemName) end row.properties = rightclick:addrow("Properties") addEventHandler("onClientGUIClick", row.properties, function (button, state) triggerEvent("showItemProperties", localPlayer, element) end, false) end end if not noPickupFor[itemID] and itemworld:can(localPlayer, "move", element) then if not rcMenu then rcMenu = rightclick:create(itemName) end row.move = rightclick:addrow("Move") addEventHandler("onClientGUIClick", row.pickup, function (button, state) triggerServerEvent("moveToElement", localPlayer, element, localPlayer) end, false) end local localPlayer = getLocalPlayer() local element = nil local wInventory, gUserItems, UIColName, gElementItems, VIColName, bCloseInventory, bGiveItem, bTakeItem local sx, sy = guiGetScreenSize() local function forceUpdate( ) if not wInventory then return end guiGridListClear(gUserItems) guiGridListClear(gElementItems) --------------- -- PLAYER --------------- local items = getItems(localPlayer) for slot, item in ipairs( items ) do if item then if getElementModel( element ) ~= 2147 or getItemType( item[ 1 ] ) == 1 then local row = guiGridListAddRow(gUserItems) local name = getItemName( item[1], item[2] ) local desc = tostring(item[1] == 114 and getItemDescription( item[1], item[2] ) or item[2] == 1 and "" or item[2]) if name ~= desc and #desc > 0 and item[1] ~= 114 then name = name .. " - " .. desc elseif item[1] == 114 then name = "Upgrade" .. " - " .. desc end guiGridListSetItemText(gUserItems, row, UIColName, name, false, false) guiGridListSetItemData(gUserItems, row, UIColName, tostring( slot ) ) end end end if getElementModel( element ) ~= 2147 then -- WEAPONS for slot = 0, 12 do if getPedWeapon(localPlayer, slot) and getPedWeapon(localPlayer, slot) > 0 and getPedTotalAmmo( localPlayer, slot ) > 0 then local row = guiGridListAddRow(gUserItems) guiGridListSetItemText(gUserItems, row, UIColName, getItemName( -getPedWeapon(localPlayer, slot) ) .. " - " .. getPedTotalAmmo( localPlayer, slot ), false, false) guiGridListSetItemData(gUserItems, row, UIColName, tostring( -slot ) ) end end -- ARMOR if getPedArmor( localPlayer ) > 0 then local row = guiGridListAddRow(gUserItems) guiGridListSetItemText(gUserItems, row, UIColName, getItemName( -100 ) .. " - " .. math.ceil( getPedArmor( localPlayer ) ), false, false ) guiGridListSetItemData(gUserItems, row, UIColName, tostring( -100 ) ) end end --------------- -- ELEMENTS --------------- if getElementType(element)=="interior" then local interiorStatus = getElementData(element, "status") local interiorType = interiorStatus[1] if not hasKey(getElementData(element, "dbid"), element) and interiorType~=2 then local row = guiGridListAddRow(gElementItems) guiGridListSetItemText(gElementItems, row, VIColName, "You need the key of this house", false, false) triggerEvent("item:updateclient", localPlayer) return else if interiorType==2 then local theTeam = getPlayerTeam(getLocalPlayer()) local factionType = getElementData(theTeam, "type") if (factionType~=2 and factionType~=3 and getElementData(getLocalPlayer(), "duty_admin") ~= 1) then local row = guiGridListAddRow(gElementItems) guiGridListSetItemText(gElementItems, row, VIColName, "Gov faction members only", false, false) triggerEvent("item:updateclient", localPlayer) return end end end end local items = getItems( element ) for slot, item in pairs( items ) do if getElementType( element ) ~= "vehicle" or item[1] ~= 74 then local row = guiGridListAddRow(gElementItems) local name = getItemName( item[1], item[2] ) local desc = tostring(item[1] == 114 and getItemDescription( item[1], item[2] ) or item[2] == 1 and "" or item[2]) if name ~= desc and #desc > 0 and item[1] ~= 114 then name = name .. " - " .. desc elseif item[1] == 114 then name = desc end guiGridListSetItemText(gElementItems, row, VIColName, name, false, false) guiGridListSetItemData(gElementItems, row, VIColName, tostring( slot ) ) end end if getElementType( element ) == "vehicle" then local mods = getVehicleUpgrades( element ) local data = getElementData( localPlayer, "v:mods" ) if data and data[ element ] then for key, value in pairs( data[ element ] ) do for k, v in ipairs( mods ) do if key == v then table.remove( mods, k ) local row = guiGridListAddRow(gElementItems) guiGridListSetItemText(gElementItems, row, VIColName, "Upgrade " .. getItemDescription( 114, v ), false, false) guiGridListSetItemData(gElementItems, row, VIColName, tostring( -v ) ) break end end end end if exports.integration:isPlayerTrialAdmin(getLocalPlayer()) then for key, value in ipairs(mods) do local row = guiGridListAddRow(gElementItems) guiGridListSetItemText(gElementItems, row, VIColName, "UPGRADE " .. getItemDescription( 114, value ), false, false) guiGridListSetItemData(gElementItems, row, VIColName, tostring( -value ) ) end end end triggerEvent("item:updateclient", localPlayer) end addEvent( "forceElementMoveUpdate", true ) addEventHandler( "forceElementMoveUpdate", localPlayer, forceUpdate ) local function update() if source == localPlayer or source == element then forceUpdate() end end addEventHandler("recieveItems", getRootElement(), update) local function hideMenu() if wInventory then destroyElement( wInventory ) wInventory = nil triggerServerEvent( "closeFreakinInventory", localPlayer, element ) element = nil setElementData(localPlayer, "exclusiveGUI", false, false) showCursor( false ) end end function hasKey( key, element ) if getElementType(element)~="interior" then return end if exports.global:hasItem(getLocalPlayer(), 4, key) or exports.global:hasItem(getLocalPlayer(), 5,key) then return true, false elseif getElementData(getLocalPlayer(), "duty_admin") == 1 then return true, true else local interiorStatus = getElementData(element, "status") local interiorType = interiorStatus[1] or -1 if interiorType==2 then local theTeam = getPlayerTeam(getLocalPlayer()) local factionType = getElementData(theTeam, "type") if (factionType~=2 and factionType~=3) then return false, false else return true, true end end end return false, false end local function moveToElement( button ) local row, col = guiGridListGetSelectedItem(gUserItems) if button == "left" and col ~= -1 and row ~= -1 then local slot = tonumber( guiGridListGetItemData(gUserItems, row, col) ) if slot then guiSetVisible( wWait, true ) guiSetEnabled( wInventory, false ) if slot > 0 then triggerServerEvent( "moveToElement", localPlayer, element, slot ) elseif slot == -100 then triggerServerEvent( "moveToElement", localPlayer, element, slot, true ) else slot = -slot triggerServerEvent( "moveToElement", localPlayer, element, getPedWeapon( localPlayer, slot ), math.min( getPedTotalAmmo( localPlayer, slot ), getElementData( localPlayer, "ACweapon" .. getPedWeapon( localPlayer, slot ) ) or 0 ) ) end end end end local function moveFromElement( button ) local row, col = guiGridListGetSelectedItem(gElementItems) if button == "left" and col ~= -1 and row ~= -1 then local slot = tonumber( guiGridListGetItemData(gElementItems, row, col) ) if not slot then return end if slot < 0 --[[and exports.integration:isPlayerTrialAdmin(localPlayer)]] then triggerServerEvent( "item:vehicle:removeUpgrade", element, -slot ) guiSetVisible( wWait, true ) guiSetEnabled( wInventory, false ) elseif slot then local item = getItems( element )[ slot ] if item then local itemID, itemValue, itemIndex = unpack( item ) if (hasKey(getElementData(element, "dbid"), element) and getElementType(element)=="interior") or getElementType(element)~="interior" then if itemID < 0 and itemID ~= -100 then -- weapon 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 = getWeaponNameFromID( 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 --guiSetVisible( wWait, true ) --guiSetEnabled( wInventory, false ) triggerServerEvent( "moveFromElement", localPlayer, element, slot, free, itemIndex ) end else --guiSetVisible( wWait, true ) --guiSetEnabled( wInventory, false ) triggerServerEvent( "moveFromElement", localPlayer, element, slot, nil, itemIndex ) end else outputChatBox("You must have the keys to his house to take items from the Mailbox.", getLocalPlayer(), 255, 0, 0) end end end end end local function adminCheck( button ) local row, col = guiGridListGetSelectedItem(gElementItems) if button == "right" and col ~= -1 and row ~= -1 then local slot = tonumber( guiGridListGetItemData(gElementItems, row, col) ) if not slot then return end local item = getItems( element )[ slot ] if not item then return end -- don't pick it up otherwise if exports.global:isStaffOnDuty(getLocalPlayer()) then triggerServerEvent("protectItem", element, fp, item, slot) return end end end local function openElementInventory( ax, ay ) if not getElementData(localPlayer, "exclusiveGUI") then hideMenu() element = source local w, h = 500, 500 local type = getElementModel(source) == 2147 and "Fridge" or getElementModel(source) == 3761 and "Shelf" or (( getElementType(source) == "vehicle" and "Vehicle" ) or ( getElementType(source) == "interior" and "Mailbox" ) or "Safe" ) setElementData(localPlayer, "exclusiveGUI", true, false) ax = math.max( 10, math.min( sx - 410, ax ) ) ay = math.max( 10, math.min( sy - 310, ay ) ) wInventory = guiCreateStaticImage(ax-w/2, ay-h/2, w, h, ":resources/window_body.png",false)--type .. " Inventory", false) --guiWindowSetSizable(wInventory, false) lYou = guiCreateLabel(0.25, 0.1, 0.87, 0.05, "YOU", true, wInventory) guiSetFont(lYou, "default-bold-small") lVehicle = guiCreateLabel(0.675, 0.1, 0.87, 0.05, type:upper(), true, wInventory) guiSetFont(lVehicle, "default-bold-small") gUserItems = guiCreateGridList(0.05, 0.15, 0.45, 0.65+0.075, true, wInventory) UIColName = guiGridListAddColumn(gUserItems, "Name", 0.9) gElementItems = guiCreateGridList(0.5, 0.15, 0.45, 0.65+0.075, true, wInventory) VIColName = guiGridListAddColumn(gElementItems, "Name", 0.9) bCloseInventory = guiCreateButton(0.05, 0.9, 0.9, 0.075, "Close Inventory", true, wInventory) addEventHandler("onClientGUIClick", bCloseInventory, hideMenu, false) bGiveItem = guiCreateButton(0.05, 0.81, 0.45, 0.075, "Move", true, wInventory) addEventHandler("onClientGUIClick", bGiveItem, moveToElement, false) addEventHandler("onClientGUIDoubleClick", gUserItems, moveToElement, false) bTakeItem = guiCreateButton(0.5, 0.81, 0.45, 0.075, " Move ", true, wInventory) addEventHandler("onClientGUIClick", bTakeItem, moveFromElement, false) addEventHandler("onClientGUIDoubleClick", gElementItems, moveFromElement, false) addEventHandler("onClientGUIClick", gElementItems, adminCheck, false) forceUpdate() showCursor( true ) else outputChatBox("You can't access that inventory at the moment.", 255, 0, 0) end end addEvent( "openElementInventory", true ) addEventHandler( "openElementInventory", getRootElement(), openElementInventory ) addEventHandler( "onClientChangeChar", getRootElement(), hideMenu ) addEvent( "fini:~emMove", true ) addEventHandler( "fini:~emMove", getLocalPlayer(), function( ) if wInventory then guiSetEnabled( wInventory, true ) end guiSetVisible( wWait, false ) end ) function collisionFix() for key, value in pairs( getElementsByType( "object", getResourceRootElement( getResourceFromName("item-world") ) ) ) do if isElement( value ) then local modelid = getElementModel(value) if modelid == 1271 then setElementCollisionsEnabled(value, false) end end end end setTimer(collisionFix, 5000, 0) --addEventHandler( "onClientPreRender", getRootElement(), collisionFix ) local function canAccessElement( player, element ) if getElementData(player, "dead") == 1 then return false end if getElementType( element ) == "vehicle" then if not isVehicleLocked( element ) then return true else local veh = getPedOccupiedVehicle( player ) local inVehicle = getElementData( player, "realinvehicle" ) if veh == element and inVehicle == 1 then return true elseif veh == element and inVehicle == 0 then outputDebugString( "canAcccessElement failed (hack?): " .. getPlayerName( player ) .. " on Vehicle " .. getElementData( element, "dbid" ) ) return false else outputDebugString( "canAcccessElement failed (locked): " .. getPlayerName( player ) .. " on Vehicle " .. getElementData( element, "dbid" ) ) return false end end else return true end end -- local function openInventory( element, ax, ay ) if canAccessElement( source, element ) then triggerEvent( "subscribeToInventoryChanges", source, element ) triggerClientEvent( source, "openElementInventory", element, ax, ay ) end end addEvent( "openFreakinInventory", true ) addEventHandler( "openFreakinInventory", getRootElement(), openInventory ) -- local function closeInventory( element ) triggerEvent( "unsubscribeFromInventoryChanges", source, element ) end addEvent( "closeFreakinInventory", true ) addEventHandler( "closeFreakinInventory", getRootElement(), closeInventory ) -- local function output(from, to, itemID, itemValue, evenIfSamePlayer) if from == to and not evenIfSamePlayer then return false end -- player to player if getElementType(from) == "player" and getElementType(to) == "player" then exports.global:sendLocalMeAction( from, "gives " .. getPlayerName( to ):gsub("_", " ") .. " a " .. getItemName( itemID, itemValue ) .. "." ) -- player to item elseif getElementType(from) == "player" then local name = getName(to) if itemID == 134 then triggerEvent('sendAme', from, "puts $" .. exports.global:formatMoney(itemValue) .. " inside the ".. name .."." ) elseif itemID == 150 then --ATM card / MAXIME triggerEvent('sendAme', from, "puts an ATM card into the "..name.."." ) else triggerEvent('sendAme', from, "puts a " .. getItemName( itemID, itemValue ) .. " inside the ".. name .."." ) end -- item to player elseif getElementType(to) == "player" then local name = getName(from) if itemID == 134 then triggerEvent('sendAme', to, "takes $" .. exports.global:formatMoney(itemValue) .. " from the ".. name .."." ) elseif itemID == 150 then --ATM card / MAXIME triggerEvent('sendAme', to, "takes an ATM from the "..name.."." ) else triggerEvent('sendAme', to, "takes a " .. getItemName( itemID, itemValue ) .. " from the ".. name .."." ) end end if itemID == 2 then triggerClientEvent(to, "phone:clearAllCaches", to, itemValue) triggerClientEvent(from, "phone:clearAllCaches", from, itemValue) end return true end function x_output_wrapper( ... ) return output( ... ) end -- local function moveToElement( element, slot, ammo, event ) if not canAccessElement( source, element ) then outputChatBox("You cannot access this inventory at the moment.", source, 255, 0, 0) triggerClientEvent( source, event or "fini:~emMove", source ) return end local name = getName(element) if not ammo then local item = getItems( source )[ slot ] if item then -- ANTI ALT-ALT FOR NON AMMO ITEMS, CHECK THIS FUNCTION FOR AMMO ITEM BELOW AND FOR WORLD ITEM CHECK s_world_items.lua/ MAXIME --31 -> 43 = DRUGS if ( (item[1] >= 31 and item[1] <= 43) or itemBannedByAltAltChecker[item[1]]) and not (getElementModel(element) == 2942 and item[1] == 150) then local hoursPlayedFrom = getElementData( source, "hoursplayed" ) local hoursPlayedTo = 99 if isElement(element) and getElementType(element) == "player" then hoursPlayedTo = getElementData( element, "hoursplayed" ) end if not exports.global:isStaffOnDuty(source) and not exports.global:isStaffOnDuty(element) then if hoursPlayedFrom < 10 then outputChatBox("You require 10 hours of playing time to move a "..getItemName( item[1] ).." to a "..name..".", source, 255, 0, 0) triggerClientEvent( source, event or "fini:~emMove", source ) return false end if hoursPlayedTo < 10 then outputChatBox(string.gsub(getPlayerName(element), "_", " ").." requires 10 hours of playing time to receive a "..getItemName( item[1] ).." from you.", source, 255, 0, 0) outputChatBox("You require 10 hours of playing time to receive a "..getItemName( item[1] ).." from "..string.gsub(getPlayerName(source), "_", " ")..".", element, 255, 0, 0) triggerClientEvent( source, event or "fini:~emMove", source ) return false end end --outputDebugString(hoursPlayedFrom.." "..hoursPlayedTo) end if (getElementType(element) == "ped") and getElementData(element,"shopkeeper") then --[[if item[1] == 121 and not getElementData(element,"customshop") then-- supplies box triggerEvent("shop:handleSupplies", source, element, slot, event) return true end]] -- Removed by MAXIME if getElementData(element,"customshop") then if item[1] == 134 then -- money triggerClientEvent( source, event or "fini:~emMove", source ) return false end triggerEvent("shop:addItemToCustomShop", source, element, slot, event) return true end triggerClientEvent( source, event or "fini:~emMove", source ) return false end if not (getElementModel( element ) == 2942) and not hasSpaceForItem( element, item[1], item[2] ) then --Except for ATM Machine / MAXIME outputChatBox( "The inventory is full.", source, 255, 0, 0 ) else if (item[1] == 115) then -- Weapons local itemCheckExplode = exports.global:explode(":", item[2]) -- itemCheckExplode: [1] = gta weapon id, [2] = serial number, [3] = weapon name local weaponDetails = exports.global:retrieveWeaponDetails( itemCheckExplode[2] ) if (tonumber(weaponDetails[2]) and tonumber(weaponDetails[2]) == 2) then -- /duty outputChatBox("You can't put your duty weapon in a " .. name .. " while being on duty.", source, 255, 0, 0) triggerClientEvent( source, event or "fini:~emMove", source ) return end elseif (item[1] == 116) then -- Ammo local ammoDetails = exports.global:explode( ":", item[2] ) -- itemCheckExplode: [1] = gta weapon id, [2] = serial number, [3] = weapon name local checkString = string.sub(ammoDetails[3], -4) if (checkString == " (D)") then -- /duty outputChatBox("You can't put your duty ammo in a " .. name .. " while being on duty.", source, 255, 0, 0) triggerClientEvent( source, event or "fini:~emMove", source ) return end elseif (item[1] == 179 and getElementType(element) == "vehicle") then --vehicle texture outputDebugString("vehicle texture") local vehID = getElementData(element, "dbid") local veh = element if(exports.global:isStaffOnDuty(source) or exports.integration:isPlayerScripter(source) or exports.global:hasItem(source, 3, tonumber(vehID)) or (getElementData(veh, "faction") > 0 and exports.factions:isPlayerInFaction(source, getElementData(veh, "faction"))) ) then outputDebugString("access granted") local itemExploded = exports.global:explode(";", item[2]) local url = itemExploded[1] local texName = itemExploded[2] if url and texName then local res = exports["item-texture"]:addVehicleTexture(source, veh, texName, url) if res then takeItemFromSlot(source, slot) outputDebugString("success") outputChatBox("success", source) else outputDebugString("item-system/s_move_items: Failed to add vehicle texture") end triggerClientEvent(source, event or "fini:~emMove", source) return end end end if (item[1] == 137) then -- Snake cam outputChatBox("You cannot move this item.", source, 255, 0, 0) triggerClientEvent( source, event or "fini:~emMove", source ) return elseif item[1] == 138 then if not exports.integration:isPlayerAdmin(source) then outputChatBox("It requires an admin to move this item.", source, 255, 0, 0) triggerClientEvent( source, event or "fini:~emMove", source ) return end elseif item[1] == 139 then if not exports.integration:isPlayerTrialAdmin(source) then outputChatBox("It requires a trial administrator to move this item.", source, 255, 0, 0) triggerClientEvent(source, event or "fini:~emMove", source) return end end if (item[1] == 134) then -- Money if not exports.global:isStaffOnDuty(source) and not exports.global:isStaffOnDuty(element) then local hoursPlayedFrom = getElementData( source, "hoursplayed" ) or 99 local hoursPlayedTo = getElementData( element, "hoursplayed" ) or 99 if (getElementType(element) == "player") and (getElementType(source) == "player") then if hoursPlayedFrom < 10 or hoursPlayedTo < 10 then outputChatBox("You require 10 hours of playing time to give money to another player.", source, 255, 0, 0) outputChatBox(exports.global:getPlayerName(source).." requires 10 hours of playing time to give money to you.", element, 255, 0, 0) triggerClientEvent( source, event or "fini:~emMove", source ) outputChatBox("You require 10 hours of playing time to receive money from another player.", element, 255, 0, 0) outputChatBox(exports.global:getPlayerName(element).." requires 10 hours of playing time to receive money from you.", source, 255, 0, 0) triggerClientEvent( source, event or "fini:~emMove", source ) return false end elseif (getElementType(element) == "vehicle") and (getElementType(source) == "player") then if hoursPlayedFrom < 10 then outputChatBox("You require 10 hours of playing time to store money in a vehicle.", source, 255, 0, 0) triggerClientEvent( source, event or "fini:~emMove", source ) return false end elseif (getElementType(element) == "object") and (getElementType(source) == "player") then if hoursPlayedFrom < 10 then outputChatBox("You require 10 hours of playing time to store money in that.", source, 255, 0, 0) triggerClientEvent( source, event or "fini:~emMove", source ) return false end end end if exports.global:takeMoney(source, tonumber(item[2])) then if getElementType(element) == "player" then if exports.global:giveMoney(element, tonumber(item[2])) then triggerEvent('sendAme', source, "gives $" .. exports.global:formatMoney(item[2]) .. " to ".. exports.global:getPlayerName(element) .."." ) end else if exports.global:giveItem(element, 134, tonumber(item[2])) then triggerEvent('sendAme', source, "puts $" .. exports.global:formatMoney(item[2]) .. " inside the ".. name .."." ) end end end else -- not money if getElementType( element ) == "object" then local elementModel = getElementModel(element) local elementItemID = getElementData(element, "itemID") if elementItemID then if elementItemID == 166 then --video player if item[1] ~= 165 then --if item being moved to video player is not a valid video item exports.hud:sendBottomNotification(source, "Video Player", "That is not a valid disc.") triggerClientEvent( source, event or "fini:~emMove", source ) return end end end if ( getElementDimension( element ) < 19000 and ( item[1] == 4 or item[1] == 5 ) and getElementDimension( element ) == item[2] ) or ( getElementDimension( element ) >= 20000 and item[1] == 3 and getElementDimension( element ) - 20000 == item[2] ) then -- keys to that safe as well if countItems( source, item[1], item[2] ) < 2 then outputChatBox("You can't place your only key to that safe in the safe.", source, 255, 0, 0) triggerClientEvent( source, event or "fini:~emMove", source ) return end end end local success, reason = moveItem( source, element, slot ) if not success then if not elementItemID then elementItemID = getElementData(element, "itemID") end local fakeReturned = false if elementItemID then if elementItemID == 166 then --video system exports.hud:sendBottomNotification(source, "Video Player", "There is already a disc inside. Eject old disc first.") fakeReturned = true end end if not fakeReturned then --only check by model IDs if we didnt already find a match on itemID if getElementModel(element) == 2942 then exports.hud:sendBottomNotification(source, "ATM Machine", "There is another ATM stuck inside the ATM machine's slot. Right-click for interactions.") end end outputDebugString( "Item Moving failed: " .. tostring( reason )) else if getElementModel(element) == 2942 then exports.bank:playAtmInsert(element) elseif item[1] == 165 then --video disc if exports.clubtec:isVideoPlayer(element) then --triggerEvent("sendAme", source, "ejects a disc from the video player." ) for key, value in ipairs(getElementsByType("player")) do if getElementDimension(value)==getElementDimension(element) then triggerEvent("fakevideo:loadDimension", value) end end end end --exports.logs:logMessage( getPlayerName( source ) .. "->" .. name .. " #" .. getElementID(element) .. " - " .. getItemName( item[1] ) .. " - " .. item[2], 17) --exports.logs:dbLog(source, 39, source, getPlayerName( source ) .. "->" .. name .. " #" .. getElementID(element) .. " - " .. getItemName( item[1] ) .. " - " .. item[2] ) doItemGiveawayChecks( source, item[1] ) output(source, element, item[1], item[2]) end end exports.logs:dbLog(source, 39, source, getPlayerName( source ) .. "->" .. name .. " #" .. getElementID(element) .. " - " .. getItemName( item[1] ) .. " - " .. item[2] ) end end else -- IF AMMO if not ( ( slot == -100 and hasSpaceForItem( element, slot ) ) or ( slot > 0 and hasSpaceForItem( element, -slot ) ) ) then outputChatBox( "The Inventory is full.", source, 255, 0, 0 ) else if tonumber(getElementData(source, "duty")) > 0 then outputChatBox("You can't put your weapons in a " .. name .. " while being on duty.", source, 255, 0, 0) elseif tonumber(getElementData(source, "job")) == 4 and slot == 41 then outputChatBox("You can't put this spray can into a " .. name .. ".", source, 255, 0, 0) else if slot == -100 then local ammo = math.ceil( getPedArmor( source ) ) if ammo > 0 then setPedArmor( source, 0 ) giveItem( element, slot, ammo ) --exports.logs:logMessage( getPlayerName( source ) .. "->" .. name .. " #" .. getElementID(element) .. " - " .. getItemName( slot ) .. " - " .. ammo, 17) exports.logs:dbLog(source, 39, source, getPlayerName(source) .. " moved " .. getItemName(slot) " - " .. ammo .. " #" .. getElementID(element) ) output(source, element, -100) end else local getCurrentMaxAmmo = exports.global:getWeaponCount(source, slot) if ammo > getCurrentMaxAmmo then exports.global:sendMessageToAdmins("[items\moveToElement] Possible duplication of gun from '"..getPlayerName(source).."' // " .. getItemName( -slot ) ) --exports.logs:logMessage( getPlayerName( source ) .. "->" .. name .. " #" .. getElementID(element) .. " - " .. getItemName( -slot ) .. " - " .. ammo .. " BLOCKED DUE POSSIBLE DUPING", 17) exports.logs:dbLog(source, 39, source, getPlayerName(source) .. " moved " .. getItemName(-slot) " - #" .. getElementID(element) .. " - BLOCKED DUE POSSIBLE DUPING" ) triggerClientEvent( source, event or "fini:~emMove", source ) return end exports.global:takeWeapon( source, slot ) if ammo > 0 then giveItem( element, -slot, ammo ) --exports.logs:logMessage( getPlayerName( source ) .. "->" .. name .. " #" .. getElementID(element) .. " - " .. getItemName( -slot ) .. " - " .. ammo, 17) exports.logs:dbLog(source, 39, source, getPlayerName(source) .. " moved " .. getItemName(-slot) " - " .. ammo .. " #" .. getElementID(element) ) output(source, element, -slot) end end end end end outputDebugString("moveToElement") triggerClientEvent( source, event or "fini:~emMove", source ) end addEvent( "moveToElement", true ) addEventHandler( "moveToElement", getRootElement(), moveToElement ) -- local function moveWorldItemToElement( item, element ) if true then return outputDebugString("[ITEM] moveWorldItemToElement / Disabled ") end if not isElement( item ) or not isElement( element ) or not canAccessElement( source, element ) then return end local id = tonumber(getElementData( item, "id" )) if not id then outputChatBox("Error: No world item ID. Notify a scripter. (s_move_items)",source,255,0,0) destroyElement(element) return end local itemID = getElementData( item, "itemID" ) local itemValue = getElementData( item, "itemValue" ) or 1 local name = getName(element) -- ANTI ALT-ALT MAXIME --31 -> 43 = DRUGS if ((itemID >= 31) and (itemID <= 43)) or itemBannedByAltAltChecker[itemID] then outputChatBox(getItemName(itemID).." can only moved directly from your inventory to this "..name..".", source, 255, 0, 0) return false end if (getElementType(element) == "ped") and getElementData(element,"shopkeeper") then return false end if not canPickup(source, item) then outputChatBox("You can not move this item. Contact an admin via F2.", source, 255, 0, 0) return end if itemID == 138 then if not exports.integration:isPlayerAdmin(source) then outputChatBox("Only a full admin can move this item.", source, 255, 0, 0) return end end if itemID == 169 then --outputChatBox("Nay.") return end if giveItem( element, itemID, itemValue ) then --[[ if itemID == 166 then --video player local videoplayerDisc = exports.clubtec:getVideoPlayerCurrentVideoDisc(item) or 2 local videoplayerObject = nil local dimensionPlayers = {} for key, value in ipairs(getElementsByType("player")) do if getElementDimension(value)==getElementDimension(item) then table.insert(dimensionPlayers,value) end end triggerClientEvent(dimensionPlayers, "fakevideo:removeOne", source, videoplayerDisc, itemValue, videoplayerObject) end --]] output(source, element, itemID, itemValue, true) --exports.logs:logMessage( getPlayerName( source ) .. " put item #" .. id .. " (" .. itemID .. ":" .. getItemName( itemID ) .. ") - " .. itemValue .. " in " .. name .. " #" .. getElementID(element), 17) exports.logs:dbLog( source, 39, source, getPlayerName( source ) .. " put item #" .. id .. " (" .. itemID .. ":" .. getItemName( itemID ) .. ") - " .. itemValue .. " in " .. name .. " #" .. getElementID(element)) mysql:query_free("DELETE FROM worlditems WHERE id='" .. id .. "'") while #getItems( item ) > 0 do moveItem( item, element, 1 ) end destroyElement( item ) if itemID == 166 then --video player for key, value in ipairs(getElementsByType("player")) do if getElementDimension(value)==getElementDimension(source) then triggerEvent("fakevideo:loadDimension", value) end end end else outputChatBox( "The Inventory is full.", source, 255, 0, 0 ) end end addEvent( "moveWorldItemToElement", true ) addEventHandler( "moveWorldItemToElement", getRootElement(), moveWorldItemToElement ) -- local function moveFromElement( element, slot, ammo, index ) if false then return outputDebugString("[ITEM] moveFromElement / Disabled ") end if not canAccessElement( source, element ) then return false end local item = getItems( element )[slot] if not canPickup(source, item) then outputChatBox("You can not move this item. Contact an admin via F2.", source, 255, 0, 0) return end local name = getName(element) if item and item[3] == index then -- ANTI ALT-ALT FOR NON AMMO ITEMS, CHECK THIS FUNCTION FOR AMMO ITEM BELOW AND FOR WORLD ITEM CHECK s_world_items.lua/ MAXIME --31 -> 43 = DRUGS if ( (item[1] >= 31 and item[1] <= 43) or itemBannedByAltAltChecker[item[1]]) and not (getElementModel(element) == 2942 and item[1] == 150) then local hoursPlayedTo = nil if isElement(source) and getElementType(source) == "player" then hoursPlayedTo = getElementData( source, "hoursplayed" ) end if not exports.global:isStaffOnDuty(source) and not exports.global:isStaffOnDuty(element) then if hoursPlayedTo < 10 then outputChatBox("You require 10 hours of playing time to receive a "..getItemName( item[1] ).." from a "..name..".", source, 255, 0, 0) triggerClientEvent( source, "forceElementMoveUpdate", source ) triggerClientEvent( source, "fini:~emMove", source ) return false end end end if not hasSpaceForItem( source, item[1], item[2] ) then outputChatBox( "The inventory is full.", source, 255, 0, 0 ) else if not exports.integration:isPlayerTrialAdmin( source ) and getElementType( element ) == "vehicle" and ( item[1] == 61 or item[1] == 85 or item[1] == 117 or item[1] == 140) then outputChatBox( "Please contact an admin via F2 to move this item.", source, 255, 0, 0 ) elseif not exports.integration:isPlayerAdmin(source) and (item[1] == 138) then outputChatBox("This item requires a regular admin to be moved.", source, 255, 0, 0) elseif not exports.integration:isPlayerTrialAdmin(source) and (item[1] == 139) then outputChatBox("This item requires an admin to be moved.", source, 255, 0, 0) elseif item[1] > 0 then if moveItem( element, source, slot ) then output( element, source, item[1], item[2]) exports.logs:dbLog(source, 39, source, name .. " #" .. getElementID(element) .. "->" .. getPlayerName( source ) .. " - " .. getItemName( item[1] ) .. " - " .. item[2]) doItemGivenChecks(source, tonumber(item[1])) end elseif item[1] == -100 then local armor = math.max( 0, ( ( getElementData( source, "faction" ) == 1 or ( getElementData( source, "faction" ) == 3 and ( getElementData( source, "factionrank" ) == 4 or getElementData( source, "factionrank" ) == 5 or getElementData( source, "factionrank" ) == 13 ) ) ) and 100 or 50 ) - math.ceil( getPedArmor( source ) ) ) if armor == 0 then outputChatBox( "You can't wear any more armor.", source, 255, 0, 0 ) else output( element, source, item[1]) takeItemFromSlot( element, slot ) local leftover = math.max( 0, item[2] - armor ) if leftover > 0 then giveItem( element, item[1], leftover ) end setPedArmor( source, math.ceil( getPedArmor( source ) + math.min( item[2], armor ) ) ) --exports.logs:logMessage( name .. " #" .. getElementID(element) .. "->" .. getPlayerName( source ) .. " - " .. getItemName( item[1] ) .. " - " .. ( math.min( item[2], armor ) ), 17) exports.logs:dbLog(source, 39, source, name .. " #" .. getElementID(element) .. "->" .. getPlayerName( source ) .. " - " .. getItemName( item[1] ) .. " - " .. ( math.min( item[2], armor ) )) end triggerClientEvent( source, "forceElementMoveUpdate", source ) else takeItemFromSlot( element, slot ) output( element, source, item[1]) if ammo < item[2] then exports.global:giveWeapon( source, -item[1], ammo ) giveItem( element, item[1], item[2] - ammo ) --exports.logs:logMessage( name .. " #" .. getElementID(element) .. "->" .. getPlayerName( source ) .. " - " .. getItemName( item[1] ) .. " - " .. ( item[2] - ammo ), 17) exports.logs:dbLog(source, 39, source, name .. " #" .. getElementID(element) .. "->" .. getPlayerName( source ) .. " - " .. getItemName( item[1] ) .. " - " .. ( item[2] - ammo )) else exports.global:giveWeapon( source, -item[1], item[2] ) --exports.logs:logMessage( name .. " #" .. getElementID(element) .. "->" .. getPlayerName( source ) .. " - " .. getItemName( item[1] ) .. " - " .. item[2], 17) exports.logs:dbLog(source, 39, {source, element}, name .. " #" .. getElementID(element) .. "->" .. getPlayerName( source ) .. " - " .. getItemName( item[1] ) .. " - " .. item[2]) end triggerClientEvent( source, "forceElementMoveUpdate", source ) end end elseif item then outputDebugString( "Index mismatch: " .. tostring( item[3] ) .. " " .. tostring( index ) ) end outputDebugString("moveFromElement") triggerClientEvent( source, "fini:~emMove", source ) end addEvent( "moveFromElement", true ) addEventHandler( "moveFromElement", getRootElement(), moveFromElement ) function getName(element) if getElementModel( element ) == 2942 then return "ATM Machine" elseif getElementModel( element ) == 2147 then return "fridge" elseif getElementModel(source) == 3761 then return "shelf" end if getElementParent(getElementParent(element)) == getResourceRootElement(getResourceFromName("item-world")) then local itemID = tonumber(getElementData(element, "itemID")) or 0 --local itemValue = getElementData(element, "itemValue") if itemID == 166 then --video player return "video player" end end if getElementType( element ) == "vehicle" then --[[local brand, model, year = (getElementData(element, "brand") or false), false, false if brand then model = getElementData(element, "maximemodel") or "" year = getElementData(element, "year") or "" return brand.." "..model.." "..year end local mtamodel = getElementModel(element) return getVehicleNameFromModel(mtamodel)]] return exports.global:getVehicleName(element) end if getElementType( element ) == "interior" then return getElementData(element, "name").."'s Mailbox" end if getElementType( element ) == "player" then return "player" end return "safe" end
mgdmgd Posted July 2, 2017 Author Posted July 2, 2017 I appreciate all your help guys, I got it fixed <3! thanks all.
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