Jump to content

Item System Error ( Couldnt Give ~Name~ A Hotdog: Nil) Help


micheal1230

Recommended Posts

  xthepr0mise said:
I just want the script of the function giveItem -.-

kay its in Admin script

-- /GIVEITEM 
function givePlayerItem(thePlayer, commandName, targetPlayer, itemID, ...) 
    if (exports.global:isPlayerAdmin(thePlayer)) then 
        if not (itemID) or not (...) or not (targetPlayer) then 
            outputChatBox("SYNTAX: /" .. commandName .. " [Player Partial Nick / ID] [item ID] [item Value]", thePlayer, 255, 194, 14) 
        else 
            local targetPlayer, targetPlayerName = exports.global:findPlayerByPartialNick(thePlayer, targetPlayer) 
             
            if targetPlayer then 
                local logged = getElementData(targetPlayer, "loggedin") 
                 
                itemID = tonumber(itemID) 
                local itemValue = table.concat({...}, " ") 
                itemValue = tonumber(itemValue) or itemValue 
                 
                if ( itemID == 74 or itemID == 75 or itemID == 78 ) and not exports.global:isPlayerScripter( thePlayer ) and not exports.global:isPlayerHeadAdmin( thePlayer) then 
                    -- nuthin 
                elseif ( itemID == 84 ) and not exports.global:isPlayerLeadAdmin( thePlayer ) then 
                elseif (logged==0) then 
                    outputChatBox("Player is not logged in.", thePlayer, 255, 0, 0) 
                elseif (logged==1) then 
                    local name = call( getResourceFromName( "item-system" ), "getItemName", itemID ) 
                     
                    if itemID > 0 and name and name ~= "?" then 
                        local success, reason = exports.global:giveItem(targetPlayer, itemID, itemValue) 
                        if success then 
                            exports.global:sendMessageToAdmins("AdmCmd: " .. getPlayerName(thePlayer) .. " gave " .. targetPlayerName .. " a " .. name .. " with value " .. itemValue .. ".") 
                            outputChatBox("Player " .. targetPlayerName .. " now has a " .. name .. " with value " .. itemValue .. ".", thePlayer, 0, 255, 0) 
                            exports.logs:logMessage(getPlayerName(thePlayer):gsub("_", " ") .. " gave " .. targetPlayerName .. " a " .. name .. " with value " .. itemValue, 13) 
                             
                            if itemID == 2 or itemID == 17 then 
                                triggerClientEvent(targetPlayer, "updateHudClock", targetPlayer) 
                            end 
                        else 
                            outputChatBox("Couldn't give " .. targetPlayerName .. " a " .. name .. ": " .. tostring(reason), thePlayer, 255, 0, 0) 
                        end 
                    else 
                        outputChatBox("Invalid Item ID.", thePlayer, 255, 0, 0) 
                    end 
                end 
            end 
        end 
    end 
end 
addCommandHandler("giveitem", givePlayerItem, false, false) 
  

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...