Jump to content

Godmode adjustment


MTA.Castiel

Recommended Posts

I'm facing an issue with godmode protected players being able to use vehicles to damage non-protected players by ramming them.

I've tried a few things, unfortunately it has not worked.

 

function godmodePlayers(attacker, weapon, bodypart)

    if (weapon == 54 or weapon == 53) then --Have godmode.active players take damage from falling or drowning
        return
    end

    if getElementData(attacker, "godmode.active") or getElementData(localPlayer, "godmode.active") then
        cancelEvent()
    end

    if getElementType(attacker) == "vehicle" and getElementData(attacker, "godmode.active")  then
        cancelEvent()
    end


end
addEventHandler("onClientPlayerDamage", getLocalPlayer(), godmodePlayers)

Link to comment
  • Moderators

Hello @MTA.Castiel,

The Tutorials section is only for posting tutorials. Your post is a scripting question so I'm moving it into the right section.

Also please edit your post so that your Lua code is wrapped into a code block so that it's easier for people to read it:image.png.48e18b1cd6aaa1b2d25e2521c87d9d5a.png

Thank you for your understanding.

  • Like 1
Link to comment

hi @MTA.Castiel, i prepared some code for you, let me know if i could help.

local isGodMode = getElementData(source, "godmode.active")
 if attacker and getElementType(attacker) == "vehicle" and isGodMode and damage_causing == 49 then
        local player = getVehicleOccupant(attacker)
        if(player and getElementType(player) == "player") then
           -- if he is not himself
           if(player ~= source) then
             cancelEvent()
           end
        end
    end

Try this code.

 

Edited by eoL|Shady
i changed the codes
  • Like 1
Link to comment

Hello, eoL|Shady! thanks for getting back to me on this topic ? Well, the code you have prepared has not worked  as i intended and perhaps -TheManTheMythTheLegend is right as to 'better explain' what i'm trying achieve. 

I'm sorry but if i may, basically if the player that has the element data
"godmode.active" set, that player cannot be harmed by anyone AND also cannot cause harm to anyone else.

Right now, if i punch a player that has "godmode.active" set, they take no damage, yes that works, but if that godmode.active player punches me or rams me with a vehicle, i lose Health ?‍♂️ Thats the issue i'm trying to solve. 

 

Link to comment

for vehicle and player damage you can try these but I haven't tested them

if attacker and getElementType(attacker) == "vehicle" and damage_causing == 49 then
    local player = getVehicleOccupant(attacker)
    local isGodForSource = getElementData(source, "godmode.active")
    local isGodForAttacker = getElementData(player, "godmode.active")
    if(isGodForSource or isGodForAttacker) then
       if(player ~= source) then
          cancelEvent()
       end
    end
end

if attacker and getElementType(attacker) == "player" then
    local isGodForSource = getElementData(source, "godmode.active")
    local isGodForAttacker = getElementData(attacker, "godmode.active")
    if(isGodForSource or isGodForAttacker) then
      if(attacker ~= source) then
         cancelEvent()
      end
   end
end

 

Edited by Burak5312
  • Thanks 1
Link to comment

@Burak5312 Hey there!
Burak, your code has done the job with very slight modification on the first line at 'damage_causing == 49'. I was still taking damage from the ramming vehicles with the godmode players so I just removed the 'damage_causing == 49' and some of what i did previously. So now we have this. Working as intended ?

Many many thanks! ?

function godmodePlayers(attacker, weapon, bodypart)

	if (weapon == 53 or weapon == 54) then
		return
	end

if attacker and getElementType(attacker) == "vehicle"  then
    local player = getVehicleOccupant(attacker)
    local isGodForSource = getElementData(source, "godmode.active")
    local isGodForAttacker = getElementData(player, "godmode.active")
    if(isGodForSource or isGodForAttacker) then
       if(player ~= source) then
          cancelEvent()
       end
    end
end

if attacker and getElementType(attacker) == "player" then
    local isGodForSource = getElementData(source, "godmode.active")
    local isGodForAttacker = getElementData(attacker, "godmode.active")
    if(isGodForSource or isGodForAttacker) then
      if(attacker ~= source) then
         cancelEvent()
      end
   end
end
end
addEventHandler("onClientPlayerDamage", getLocalPlayer(), godmodePlayers)

 

  • Like 1
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...