Build in a new world
#11
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?
Reply
Thanks given by:
#12
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).
Reply
Thanks given by:
#13
no, dont workSad
Reply
Thanks given by:
#14
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
Reply
Thanks given by:
#15
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?
Reply
Thanks given by:
#16
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.
Reply
Thanks given by:
#17
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
Reply
Thanks given by:
#18
What doesn't work? You're returning true, which blocks all admins from placing blocks...
Reply
Thanks given by:
#19
I need to only admins can destroy the blocks. It does not work
Reply
Thanks given by:
#20
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
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)