Jump to content

Problem with OOP


Recommended Posts

Posted

Hello, I'm trying to rewrite my resources to OOP. This code:

addCommandHandler("aduty", function(player) 
    local globalInfo = player:getData("globalInfo") 
    globalInfo.name = string.gsub(globalInfo.name, " ", "_") 
    globalInfo.name = string.gsub(globalInfo.name, "ś", "s") 
    globalInfo.name = string.gsub(globalInfo.name, "ć", "c") 
    local charInfo = player:getData("charInfo") 
    local accountName = player.account:getName() 
    --if isObjectInACLGroup("user."..accountName, aclGetGroup("Admin")) then 
    if ACLGroup.get("Admin"):doesContainObject("user."..player.account:getName()) then 
        if not player:getData("adminduty") then 
            player:setName(globalInfo.name) 
            player:setData("adminduty", true) 
        else 
            player:setName(charInfo.name) 
            player:setData("adminduty", false) 
        end 
    --elseif isObjectInACLGroup("user."..accountName, aclGetGroup("Support")) then 
    elseif ACLGroup.get("Support"):doesContainObject("user."..player.account:getName()) then 
        if not player:getData("supportduty") then 
            player:setName(globalInfo.name) 
            player:setData("supportduty", true) 
        else 
            player:setName(charInfo.name) 
            player:setData("supportduty", false) 
        end 
    end 
end) 

outputing this error:

admin.lua:9: attempt to call method 'doesContainObject' (a nil value) 

I don't know why. Can anyone help me?

Sorry for my english. I am from Poland.

Posted

Try this untested

addCommandHandler("aduty",  
    function(player) 
        local globalInfo = player:getData("globalInfo") 
        local charInfo = player:getData("charInfo") 
        globalInfo.name = string.gsub(globalInfo.name, " ", "_") 
        globalInfo.name = string.gsub(globalInfo.name, "ś", "s") 
        globalInfo.name = string.gsub(globalInfo.name, "ć", "c") 
        local account = player:getAccount()  
        if account and not isGuestAccount(account) then  
        local accountName = account:getName() 
        local admin = ACLGroup.get("Admin") 
        local support = ACLGroup.get("Support") 
        if admin:doesContainObject("user."..accountName) then 
            if not player:getData("adminduty") then 
                player:setName(globalInfo.name) 
                player:setData("adminduty", true) 
            else 
                player:setName(charInfo.name) 
                player:setData("adminduty", false) 
            end 
        elseif support:doesContainObject("user."..accountName) then 
            if not player:getData("supportduty") then 
                player:setName(globalInfo.name) 
                player:setData("supportduty", true) 
            else 
                player:setName(charInfo.name) 
                player:setData("supportduty", false) 
            end 
        end 
    end  
end) 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

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