MTA.Castiel Posted January 20, 2022 Share Posted January 20, 2022 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 Citizen Posted January 21, 2022 Moderators Share Posted January 21, 2022 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: Thank you for your understanding. 1 Link to comment
Shady1 Posted January 21, 2022 Share Posted January 21, 2022 (edited) 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 January 21, 2022 by eoL|Shady i changed the codes 1 Link to comment
TMTMTL Posted January 21, 2022 Share Posted January 21, 2022 Hi. Could you better explain what you're trying to achieve please? Are you doing something similar to the invisible mode in GTA 5? 1 Link to comment
MTA.Castiel Posted January 22, 2022 Author Share Posted January 22, 2022 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
βurak Posted January 22, 2022 Share Posted January 22, 2022 (edited) 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 January 22, 2022 by Burak5312 1 Link to comment
MTA.Castiel Posted January 22, 2022 Author Share Posted January 22, 2022 @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) 1 Link to comment
Shady1 Posted January 22, 2022 Share Posted January 22, 2022 Mta.Castiel If there is a different issue, please open a new topic, I can help you. good luck 1 Link to comment
MTA.Castiel Posted January 23, 2022 Author Share Posted January 23, 2022 Thanks @eoL|Shady, i really appreciate your assistance! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now