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?
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
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.
What doesn't work? You're returning true, which blocks all admins from placing blocks...
I need to only admins can destroy the blocks. It does not work