Jump to content

Godmod working for only one team


Visma

Recommended Posts

I made a script that I want godmode to only work if you are on the staff team, once switch to a different one i want it to stop working. At the moment it works with every team.

Client:

addEventHandler ( "onClientPlayerDamage", getRootElement (), 
function(attacker, weapon, bodypart, loss) 
    if getElementData(source,"admin") then 
        cancelEvent() 
    end 
end) 

Server:

function admin () 
local playerTeam = getPlayerTeam (source,"Staff") 
    if ( playerTeam) then        
        setElementData(source,"admin",true) 
    if ( playerTeam == false ) then 
        setElementData(source,"admin",false) 
        end 
    end 
end 
addEventHandler("onPlayerChangeTeam",resourceRoot,admin) 

Link to comment
getPlayerTeam returns the team element, a userdata value. Not the name. You'll need to use getTeamName to find out what the player's team is called.

The reason for why it works on every team, is because the function will return a userdata value if the player is in a team - so this means no matter what team they are in, the if statement will pass because it is not false or nil.

the correct code would be like this

    local playerTeam = getPlayerTeam ( source ) 
    local teamName = ( playerTeam and getTeamName ( playerTeam ) or "" ) 
    if ( teamName == "CLAN_NAME")then --- team name 
        --- your code 
    end 

Link to comment

Client

addEventHandler ( "onClientPlayerDamage", getRootElement (), 
function(attacker, weapon, bodypart, loss) 
    if getElementData(source,"admin") then 
        cancelEvent() 
    end 
end) 

Server

function admin () 
local playerName = getTeamName ( source,"Staff" ) 
    if ( playerName == true ) then        
        setElementData(source,"admin",true) 
    if ( playerName == false ) then 
        setElementData(source,"admin",false) 
        end 
    end 
end 
addEventHandler("onPlayerChangeTeam",resourceRoot,admin) 

Link to comment

This is wrong. You have to pass a team userdata variable to getTeamName, not a player variable.

function admin () 
local team = getPlayerTeam(source) 
local teamName = team and getTeamName ( team ) or "" 
    if ( teamName == "Staff" ) then       
        setElementData(source,"admin",true) 
    else 
        setElementData(source,"admin",false) 
    end 
end 
addEventHandler("onPlayerChangeTeam",root,admin) 

Link to comment
addEventHandler ( "onClientPlayerDamage", localPlayer, 
function(attacker, weapon, bodypart, loss) 
    if getElementData(localPlayer,"admin") == "true" then 
        cancelEvent() 
    end 
end) 

function admin () 
local team = getPlayerTeam(source) 
local teamName = team and getTeamName ( team ) or "" 
    if ( teamName == "Staff" ) then       
        setElementData(source,"admin","true") 
    else 
        removeElementData(source,"admin") 
    end 
end 
addEventHandler("onPlayerChangeTeam",root,admin) 

If it doesn't work, post the code where you trigger the event, along with any errors in /debugscript 3.

Link to comment
function admin () 
  if isPlayerInTeam(player, "Staff") then       
    if ( playerName == true ) then 
        setElementData(source,"admin",true) 
    if ( playerTeam == false ) then 
        setElementData(source,"admin",false) 
        end 
    end 
end 
addEventHandler("onPlayerChangeTeam",resourceRoot,admin) 

Maybe?

Link to comment
addEventHandler("onClientPlayerDamage", localPlayer, 
function() 
    local team = getPlayerTeam(source) 
    local teamName = team and getTeamName(team) or "" 
    if teamName == "Staff" then 
        cancelEvent() 
    end 
end) 

Link to comment
function admin () 
  if isPlayerInTeam(player, "Staff") then       
    if ( playerName == true ) then 
        setElementData(source,"admin",true) 
    if ( playerTeam == false ) then 
        setElementData(source,"admin",false) 
        end 
    end 
end 
addEventHandler("onPlayerChangeTeam",resourceRoot,admin) 

Maybe?

Didnt work

addEventHandler("onClientPlayerDamage", localPlayer, 
function() 
    local team = getPlayerTeam(source) 
    local teamName = team and getTeamName(team) or "" 
    if teamName == "Staff" then 
        cancelEvent() 
    end 
end) 

Worked thank you finally fixed

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