Cuberite Forum
Build in a new world - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Requests (https://forum.cuberite.org/forum-3.html)
+--- Thread: Build in a new world (/thread-408.html)

Pages: 1 2 3


RE: Build in a new world - Boo - 04-02-2012

Code:
function Initialize( Plugin )
    Plugin:SetName( "block" )
    Plugin:SetVersion( 2 )

    PluginManager = cRoot:Get():GetPluginManager()
    PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_BLOCK_DIG )

    LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() )
    return true
end

function OnBlockDig( PacketData, Player )
local World = Player:GetWorld()
if (World:GetName() == "WorldAdmins") then
  if Player:GetGroupName().contains("Admins") then
         return true
     else
         return false
    end
end
end

It is dont work. what's wrong?


RE: Build in a new world - geser - 04-02-2012

There is no method GetGroupName. May be GetGroups?
http://www.mc-server.org/wiki/doku.php?id=api:cplayer

std::list has no method contains(), try to write your own function to search element in list.
If player can be in only one group use Player:GetGroups().at(0).


RE: Build in a new world - Boo - 04-11-2012

no, dont workSad


RE: Build in a new world - FakeTruth - 04-11-2012

Yes, use Player:GetGroups()

GetGroups() does not return an std::list in Lua though, it returns a regular Lua table/array which you can iterate through.

This should work I think

Code:
for Key, Group in pairs(Player:GetGroups()) do
  LOG("Player " .. Player:GetName() .. " is in group " .. Group:GetName() )
end



RE: Build in a new world - Boo - 04-11-2012

Code:
function Initialize( Plugin )
    Plugin:SetName( "block" )
    Plugin:SetVersion( 2 )

    PluginManager = cRoot:Get():GetPluginManager()
    PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_BLOCK_DIG )

    LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() )
    return true
end

function OnBlockDig( PacketData, Player )

if (Player:GetGroups() == "Admins") then

return true

else
return false

end
end

Dont Work Sad Help what problem?


RE: Build in a new world - xoft - 04-11-2012

This line:
Code:
if (Player:GetGroups() == "Admins") then

You should do this instead:
Code:
for Key, Group in pairs(Player:GetGroups()) do
  if (Group:GetName() == "Admins") then
    return true
  end
end

(Note that I don't do Lua at all so the code may be syntactically wrong)
Explanation: Player may be a member of multiple groups; Player:GetGroups() returns all the groups, so you need to search the returned list of groups for yourparticular group name.


RE: Build in a new world - Boo - 04-11-2012

Code:
function Initialize( Plugin )
    Plugin:SetName( "block" )
    Plugin:SetVersion( 2 )

    PluginManager = cRoot:Get():GetPluginManager()
    PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_BLOCK_DIG )

    LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() )
    return true
end

function OnBlockDig( PacketData, Player )

for Key, Group in pairs(Player:GetGroups()) do
  if (Group:GetName() == "Admins") then
    return true
  end
end
end

No! Dont Work againSad


RE: Build in a new world - FakeTruth - 04-11-2012

What doesn't work? You're returning true, which blocks all admins from placing blocks...


RE: Build in a new world - Boo - 04-11-2012

I need to only admins can destroy the blocks. It does not work


RE: Build in a new world - FakeTruth - 04-11-2012

Code:
function OnBlockDig( PacketData, Player )
    for Key, Group in pairs(Player:GetGroups()) do
        if (Group:GetName() == "Admins") then
            return false
        end
    end
    return true
end