Jump to content

god mode


mint3d

Recommended Posts

Posted

only example, try

  
-- server 
local GodCommand = "god" -- command 
  
function SetGodAdmin(P) 
if isGuestAccount(getPlayerAccount(P)) then return outputChatBox("Only Adm can use",P) end -- guest 
if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(P)),aclGetGroup( "Admin" )) then -- is admin? 
local Is = getElementData(P,"GodAdmin") -- get data 
if Is then -- if data is true 
removeElementData(P,"GodAdmin") -- lets remove 
outputChatBox("God mod off",P) 
else -- else lets activate 
setElementData(P,"GodAdmin",true) 
outputChatBox("God mod on",P) 
 end 
   end 
      end 
addCommandHandler(GodCommand,SetGodAdmin) 
  
-- client 
  
addEventHandler("onClientPlayerDamage",getLocalPlayer(), 
function() 
if getElementData(source,"GodAdmin") then  
cancelEvent() 
 end 
    end 
) 
  

Posted

your code is a total mess

here try castillo's code

SERVER SIDED:

function toggleGodMode(thePlayer) 
local account = getPlayerAccount(thePlayer) 
if (not account or isGuestAccount(account)) then return end 
local accountName = getAccountName(account) 
if ( isObjectInACLGroup ( "user.".. accountName, aclGetGroup ( "Admin" ) ) ) then 
    if getElementData(thePlayer,"invincible") then 
        setElementData(thePlayer,"invincible",false) 
        outputChatBox("God Mode is now Disabled.",thePlayer,0,255,0) 
    else 
        setElementData(thePlayer,"invincible",true) 
        outputChatBox("God Mode is now Enabled.",thePlayer,0,255,0) 
        end 
    end 
end 
addCommandHandler("godmode",toggleGodMode) 

CLIENT SIDED:

addEventHandler ( "onClientPlayerDamage",root, 
function () 
    if getElementData(source,"invincible") then 
        cancelEvent() 
    end 
end) 
  
addEventHandler("onClientPlayerStealthKill",localPlayer, 
function (targetPlayer) 
    if getElementData(targetPlayer,"invincible") then 
        cancelEvent() 
    end 
end) 

this is Castillo's code.

Posted
only example, try
  
-- server 
local GodCommand = "god" -- command 
  
function SetGodAdmin(P) 
if isGuestAccount(getPlayerAccount(P)) then return outputChatBox("Only Adm can use",P) end -- guest 
if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(P)),aclGetGroup( "Admin" )) then -- is admin? 
local Is = getElementData(P,"GodAdmin") -- get data 
if Is then -- if data is true 
removeElementData(P,"GodAdmin") -- lets remove 
outputChatBox("God mod off",P) 
else -- else lets activate 
setElementData(P,"GodAdmin",true) 
outputChatBox("God mod on",P) 
 end 
   end 
      end 
addCommandHandler(GodCommand,SetGodAdmin) 
  
-- client 
  
addEventHandler("onClientPlayerDamage",getLocalPlayer(), 
function() 
if getElementData(source,"GodAdmin") then  
cancelEvent() 
 end 
    end 
) 
  

Meh, tried to fix your code a bit using local defined variables:

-- server 
local plrGodadmin = false 
  
function SetGodAdmin(P) 
    if isGuestAccount(getPlayerAccount(P)) then  
        outputChatBox("Only Admins can use this", P, 255, 0, 0) 
        return 
    end -- guest 
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(P)),aclGetGroup( "Admin" )) then -- is admin? 
        if (plrGodadmin == true) then -- if data is true 
            plrGodadmin = false -- lets remove 
            outputChatBox("God mod off",P) 
        elseif (plrGodadmin == false) then -- else lets activate 
            plrGodadmin = true 
            outputChatBox("God mod on",P) 
        else 
            return 
        end 
    end 
end 
addCommandHandler("god", SetGodAdmin) 
  
-- client 
  
addEventHandler("onClientPlayerDamage", getLocalPlayer(), 
  function() 
    if (plrGodadmin == true) then 
        cancelEvent() 
    end 
end 
) 
  

I can also use element data, buh, try it this way. (Untested)

Posted

You cannot use it like that.

local plrGodadmin = false 

It will work good as long as one player is on the server, but if there are more players it wont work correctly.

2nd, you dont have plrGodadmin defined client-side.

Posted

Server side

  
function setInince(thePlayer) 
    if (hasObjectPermissionTo(thePlayer, "function.banPlayer")) then 
        if (getElementData(thePlayer, "INV") == "true") then 
            setElementData(thePlayer,"INV", "false") 
            outputChatBox("God mode OFF", thePlayer) 
        else 
            setElementData(thePlayer,"INV", "true") 
            outputChatBox("God mode ON", thePlayer) 
        end 
    else 
        outputChatBox("You do not have permission for this", thePlayer) 
    end 
end 
addCommandHandler("god", setInince) 

Client side

function noadmdamage() 
if (getElementData(source, "INV") == "true") then 
    cancelEvent() 
else 
 end 
end 
addEventHandler("onClientPlayerDamage", getRootElement(), noadmdamage) 
  

Posted
Server side
  
function setInince(thePlayer) 
    if (hasObjectPermissionTo(thePlayer, "function.banPlayer")) then 
        if (getElementData(thePlayer, "INV") == "true") then 
            setElementData(thePlayer,"INV", "false") 
            outputChatBox("God mode OFF", thePlayer) 
        else 
            setElementData(thePlayer,"INV", "true") 
            outputChatBox("God mode ON", thePlayer) 
        end 
    else 
        outputChatBox("You do not have permission for this", thePlayer) 
    end 
end 
addCommandHandler("god", setInince) 

Client side

function noadmdamage() 
if (getElementData(source, "INV") == "true") then 
    cancelEvent() 
else 
 end 
end 
addEventHandler("onClientPlayerDamage", getRootElement(), noadmdamage) 
  

Would this code even work? I mean, when the player triggers the command for the first time his data is nil towards "INV" so it wouldn't be false or true, which would cause the code not to work, I guess. If the code itself did automatically change the players element data to false, you've defined false as "false" meaning it's in a word-form, not recognizable by MTA, just a data definition.

Suggestion, if what I say is correct:

  
function onJoin() 
     if (not getElementData(source, "INV") then 
          setElementData(source, "INV", "false") 
     end 
end 
addEventHandler("onPlayerJoin", root, onJoin) --Not tested 

Posted
Server side
  
function setInince(thePlayer) 
    if (hasObjectPermissionTo(thePlayer, "function.banPlayer")) then 
        if (getElementData(thePlayer, "INV") == "true") then 
            setElementData(thePlayer,"INV", "false") 
            outputChatBox("God mode OFF", thePlayer) 
        else 
            setElementData(thePlayer,"INV", "true") 
            outputChatBox("God mode ON", thePlayer) 
        end 
    else 
        outputChatBox("You do not have permission for this", thePlayer) 
    end 
end 
addCommandHandler("god", setInince) 

Client side

function noadmdamage() 
if (getElementData(source, "INV") == "true") then 
    cancelEvent() 
else 
 end 
end 
addEventHandler("onClientPlayerDamage", getRootElement(), noadmdamage) 
  

Would this code even work? I mean, when the player triggers the command for the first time his data is nil towards "INV" so it wouldn't be false or true, which would cause the code not to work, I guess. If the code itself did automatically change the players element data to false, you've defined false as "false" meaning it's in a word-form, not recognizable by MTA, just a data definition.

Suggestion, if what I say is correct:

  
function onJoin() 
     if (not getElementData(source, "INV") then 
          setElementData(source, "INV", "false") 
     end 
end 
addEventHandler("onPlayerJoin", root, onJoin) --Not tested 

Try my code you genius, it's working.

Posted
your code is a total mess

here try castillo's code

SERVER SIDED:

function toggleGodMode(thePlayer) 
local account = getPlayerAccount(thePlayer) 
if (not account or isGuestAccount(account)) then return end 
local accountName = getAccountName(account) 
if ( isObjectInACLGroup ( "user.".. accountName, aclGetGroup ( "Admin" ) ) ) then 
    if getElementData(thePlayer,"invincible") then 
        setElementData(thePlayer,"invincible",false) 
        outputChatBox("God Mode is now Disabled.",thePlayer,0,255,0) 
    else 
        setElementData(thePlayer,"invincible",true) 
        outputChatBox("God Mode is now Enabled.",thePlayer,0,255,0) 
        end 
    end 
end 
addCommandHandler("godmode",toggleGodMode) 

CLIENT SIDED:

addEventHandler ( "onClientPlayerDamage",root, 
function () 
    if getElementData(source,"invincible") then 
        cancelEvent() 
    end 
end) 
  
addEventHandler("onClientPlayerStealthKill",localPlayer, 
function (targetPlayer) 
    if getElementData(targetPlayer,"invincible") then 
        cancelEvent() 
    end 
end) 

this is Castillo's code.

That code should work.

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...