CaS*

Scripting Godmode for specific Team

Recommended Posts

CaS*    0
addEventHandler("onPlayerLogin",getRootElement(),  
function ()  
	local account = getPlayerAccount(thePlayer) 
	if (not account or isGuestAccount(account)) then return end 
		local accountName = getAccountName(account) 
		local team = getPlayerTeam (thePlayer)
		if (team) then
		if (getTeamName(team) == "Staff Team") then
			if ( isObjectInACLGroup ( "user.".. accountName, aclGetGroup ( "Admin" ) ) ) then 
				if getElementData(thePlayer,"invincible") then 
					setElementData(thePlayer,"invincible",true) 
				else 
					setElementData(thePlayer,"invincible",false) 
				end	
			end 
		end 
	end 
end
)

As the title says, while googling and with my small experience, I came up with this script, all I want is to be GODMODE when sat to "Staff Team" ((((StaffTeam = createTeam ( "Staff Team", 255, 255, 255 ) ))))) Once I leave staffteam Godmode turns off. Once I enter it, Godmode turns on.

 

This code doesn't work... :3

Edited by CaZix

Share this post


Link to post
Default    199
addEventHandler("onPlayerLogin",root,function (_,acc)  
local accountName = getAccountName(acc) 
local team = getPlayerTeam (source)
if ( team and getTeamName ( team ) == "Staff Team" ) then
if ( isObjectInACLGroup ( "user.".. accountName, aclGetGroup ( "Admin" ) ) ) then 
if getElementData(source,"invincible") then 
setElementData(source,"invincible",true) 
else 
setElementData(source,"invincible",false) 
end	
end 
end 
end );

try .

Share this post


Link to post
CaS*    0

@Default, it doesn't work. It gives me no error but still, as a staff taking DMG & as a criminal still taking DMG.

Inb4, as a staff didnt take DMG and it continued like that whenever I leave the StaffTeam. Now, it doesnt work at all.

Share this post


Link to post
shay103    3

I may be able to help with this.

-- You may use either one of these, or both if u choose. I suggest though to use only one, preferably acl.

-- Using Tables to define who should get godmode.
local godmodeTeams = {'Staff Team','Godmode Team'} -- Using tables gives you the benefit of adding infinite teams.

function setTeamGodmode()
  for i,v in pairs(godmodeTeams) do
    for l,p in pairs(getElementsByType('player')) do
      local team = getPlayerTeam(p)
      if team then
        local teamName = getTeamName(team)
        if getTeamFromName(v) then
          if v == teamName then
            setElementData(p,'invincible',true)
          else
            setElementData(p,'invincible',false)
          end
        end
      end
    end
  end
end

-- Doing the same thing only with ACL instead of teams..
local godmodeACL = {'Admin','Super Moderator'}
-- this function is for ACL
function setACLGodmode()
  for o,u in pairs(godmodeTeams) do
    for k,e in pairs(getElementsByType('player')) do
      local acc = getPlayerAccount(e)
      if acc then
        local accName = getAccountName(acc)
        if aclGetGroup(u) then
          if isObjectInACLGroup('user.'..accName,aclGetGroup(u)) then
            setElementData(e,'invincible',true)
          else
            setElementData(e,'invicible',false)
          end
        end
      end
    end
  end
end

-- to trigger these is simple, either put the function in a function as setACLGodmode() or in a timer as setACLGodmode, etc.
setTimer(setACLGodmode,1000,0) -- these timers are not needed, unless u want them, they will check every second to see if all the players get godmode.
setTimer(setTeamGodmode,1000,0)

 

Share this post


Link to post
CaS*    0

I'm defining staff with ACL admin group if hes in it or not. But that has nothing to do with the "GOD MODE" right? As I can specify it for Teams not for staff. So basically, I'm trying to specifing god mode for STAFF TEAM meanwhile checking if hes actually a staff to do it.

Share this post


Link to post
Tekken    27

Server

local aclGrpups = {
	"Admin",
	"Moderator"
};

addEventHandler("onPlayerLogin", root, function(theCurrentAccount)
	for _,v in ipairs(aclGrpups) do
		if isObjectInACLGroup("user."..getAccountName(theCurrentAccount), aclGetGroup(v)) then
			setElementData(source, "staffmember", 1);
			return;
		end
	end
	setElementData(source, "staffmember", false);
end);

Client

addEventHandler("onClientPlayerDamage", root, function()
	local team = getTeamName(getPlayerTeam(source));
	if (team == "STAFF" and getElementData(source, "staffmember") == 1) then
		cancelEvent();
	end
end);

:D

Edited by Tekken
-

Share this post


Link to post
CaS*    0
3 hours ago, Tekken said:

Server


local aclGrpups = {
	"Admin",
	"Moderator"
};

addEventHandler("onPlayerLogin", root, function(theCurrentAccount)
	for _,v in ipairs(aclGrpups) do
		if isObjectInACLGroup("user."..getAccountName(theCurrentAccount), aclGetGroup(v)) then
			setElementData(source, "staffmember", 1);
			return;
		end
	end
	setElementData(source, "staffmember", false);
end);

Client


addEventHandler("onClientPlayerDamage", root, function()
	local team = getTeamName(getPlayerTeam(source));
	if (team == "STAFF" and getElementData(source, "staffmember") == 1) then
		cancelEvent();
	end
end);

:D

When changed "and" to "or" in the "if" condition in client, it worked.

 

Totally appreciate your help, you've been a big help to me.. I spent almost a day trying to figure it out why its giving me errors thats not fixable, till you came with the idea of having it in Client instead of server which I did not notice. Thank you very much.

Also, thanks for the people who tried to help me giving me hints eventho it didn't work. But, I highly appreciate your help. Thanks.

 

Lock requested.

Edited by CaZix

Share this post


Link to post

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.