Jump to content

Restrict script to acl group


Recommended Posts

Hi there, I have a little problem and if anyone could help me I would be very grateful.

I'm trying to create a "superhero" script for my server to use sometimes, but I'd like to restrict these powers to a closed ACL group. I've looked for tutorials on Youtube and haven't found anything about it.

PS: Power scripts are separate and working, I just need to learn how to restrict them

 

Sorry if there was any grammatical error, I used translation software.

 

PS: I'm not a programmer, but I know how to mess with one thing or another in scripts. Obviously with the help of tutorials

Link to comment

You need to use ACL functions, like this one:

https://wiki.multitheftauto.com/wiki/IsObjectInACLGroup or a simplified version https://wiki.multitheftauto.com/wiki/IsPlayerInACL

Simple script:

function sHealth(thePlayer, command, health)
  if health then
    local account = getPlayerAccount(thePlayer)
    if isObjectInACLGroup("user."..account, aclGetGroup("Admin")) then
       setElementHealth(thePlayer, tonumber(health))
    else
       outputChatBox("You don't have the power to use this command", thePlayer, 255, 0, 0, true)
    end
  else
     outputChatBox("Correct syntax: /shealth health[in numbers]", thePlayer, 0, 255, 0, true)
  end
addCommandHandler("shealth", sHealth)
  
  --// Version with isObjectInACLGroup

 

 

 

function sHealth(thePlayer, command, health)
  if health then
    if isPlayerInACL(thePlayer, "Admin") then
       setElementHealth(thePlayer, tonumber(health))
    else
       outputChatBox("You don't have the power to use this command", thePlayer, 255, 0, 0, true)
    end
  else
     outputChatBox("Correct syntax: /shealth health[in numbers]", thePlayer, 0, 255, 0, true)
  end
end

--// Version with isPlayerInACL


function isPlayerInACL(player, acl)
	if isElement(player) and getElementType(player) == "player" and aclGetGroup(acl or "") and not isGuestAccount(getPlayerAccount(player)) then
		local account = getPlayerAccount(player)
		
		return isObjectInACLGroup( "user.".. getAccountName(account), aclGetGroup(acl) )
	end
	return false
end

I hope you understand how things work when you use ACLs now ?

Link to comment
4 hours ago, Hydra said:

You need to use ACL functions, like this one:

https://wiki.multitheftauto.com/wiki/IsObjectInACLGroup or a simplified version https://wiki.multitheftauto.com/wiki/IsPlayerInACL

Simple script:

function sHealth(thePlayer, command, health)
  if health then
    local account = getPlayerAccount(thePlayer)
    if isObjectInACLGroup("user."..account, aclGetGroup("Admin")) then
       setElementHealth(thePlayer, tonumber(health))
    else
       outputChatBox("You don't have the power to use this command", thePlayer, 255, 0, 0, true)
    end
  else
     outputChatBox("Correct syntax: /shealth health[in numbers]", thePlayer, 0, 255, 0, true)
  end
addCommandHandler("shealth", sHealth)
  
  --// Version with isObjectInACLGroup

 

 

 


  
      
        
    
      
  






	        
		
		
		  
	
	 

Espero que você entenda como as coisas funcionam quando você usa ACLs agora?

Unfortunately I couldn't make it work, I think it might not be working because the scripts only work if they run on a client, while the examples on the site run on a server

Link to comment

Well if it's a client script you can do something like this:
You just need to use setElementData and getElementData

--// Server-Side

function login()
   local account = getPlayerAcount(source)
   if isObjectInACLGroup("user."..account, aclGetGroup("Admin")) then
      setElementData(source, "permissionsGranted", true)
   else
      setElementData(source, "permissionsGranted", false)
   end
end
addEventHandler("onPlayerLogin", root, login)



--// Client-Side

function m()
   if getElementData(localPlayer, "permissionsGranted") == true then
      outputChatBox("Yey, you have the access", 255, 255, 255, true)
   elseif getElementData(localPlayer, "permissionsGranted") == false then
      outputChatBox("Sadly you don't have the access", 255, 255, 255, true)
   end
end
addCommandHandler("check", m)

 

Edited by Hydra
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...