Jump to content

[string "?"]:34: attempt to call global 'type'(a number value)


Pirulax

Recommended Posts

  • Discord Moderators

Okey, i  have made this small function:

 

addEvent("onClientWantToExecuteCommandHandler",true)
addEventHandler("onClientWantToExecuteCommandHandler",resourceRoot,function(playername, item,value,count,source)
    if (getElementData(source,"acc:admin") or 0 >= 6) then
        local sourcePlayer = source
        local rovid = "#398FB1[GreenStone - Inventory] #ffffff"
        if id and item and value and count and source then
            local targetPlayer, targetPlayerName = exports.mta_main:findPlayer(sourcePlayer, playername)                
            if targetPlayer then
                if giveItem(targetPlayer, tonumber(item), tostring(value), tonumber(count), 0) then -- 0 -> dutyitem        
                    if not (source==targetPlayer) then
                        outputChatBox(rovid.. " Adott egy itemet neked: #43cd80".. getElementData(playerSource,"char:anick") .."#ffffff (" ..exports["mta_item2"]:getItemName(tonumber(item))..")", targetPlayer,255,255,255,true)    
                    end                                
                    outputChatBox(rovid.. " Adtál egy itemet neki: #43cd80".. targetPlayerName:gsub("_", " ") .."#ffffff (" ..exports["mta_item2"]:getItemName(tonumber(item))..")", source,255,255,255,true)                
                    dbExec(con, adminlog, getElementData(playerSource, "char:anick"), getElementData(playerSource, "acc:id"), "GIVEITEM", getElementData(playerSource, "char:anick") .. " adott " .. count .. " db " .. exports["mta_item2"]:getItemName(tonumber(item)) .. " -t. Érték: " .. value .. "", getPlayerName(targetPlayer), getElementData(targetPlayer, "acc:id"))
                    exports.mta_admin:outputAdminMessage("#43cd80" .. getElementData(playerSource, "char:anick") .. "#ffffff adott " .. count .. " darab " .. exports["mta_item2"]:getItemName(tonumber(item)) .. " -t #43cd80" .. targetPlayerName .. "#ffffff játékosnak.")            
                else
                    outputChatBox("#43cd80[" .. serverName .. " #43cd80- Inventory]: #ffffffNem fér el több tárgy az adott játékosnál!", playerSource, 255 ,255, 255, true)
                end        
            end
        end
    end
end)

Its throwing the error on the line 7, but i dont know why...

Link to comment
  • Discord Moderators

@NeXuS™

 

 

[string "?"]:34: attempt to call global 'type'(a number value)

as it stays in the title.Im not totally sure, because that "34" is not the actual line where the error is, in the original script its a blank line.

 

Link to comment

The error is, in fact, referring to an attempt to use type as a function (which is, in fact, a function by default) but it seems it's been overridden with a number value. In other words, some part of the code is trying to call type() but type is a number, not a function.

Try looking through the code to find something like

type = ...
-- or
local type = ...

and change the variable name, don't use type as a variable name as it's already a function. Of course, changing a variable name also means you'll need to change it everywhere else in the code where you referenced it.

Edited by MrTasty
Link to comment
  • Discord Moderators
18 hours ago, MrTasty said:

The error is, in fact, referring to an attempt to use type as a function (which is, in fact, a function by default) but it seems it's been overridden with a number value. In other words, some part of the code is trying to call type() but type is a number, not a function.

Solved the problem, placed the event into another res., isnt the best solution at all, but works :D

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...