Jump to content

Godmod working for only one team


Visma

Recommended Posts

Posted

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) 

Just when the caterpillar thought the world was ending, he turned into a butterfly

Posted

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.

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted
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 

Inactivo.

Posted

still doesnt work.

I change team and i still get godmode

Just when the caterpillar thought the world was ending, he turned into a butterfly

Posted

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) 

Just when the caterpillar thought the world was ending, he turned into a butterfly

Posted

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) 

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

Still does not work, First i do not have godmode, i join the staff team and have godmode but then once i leave the staff team and join a different one i still have godmode.

Just when the caterpillar thought the world was ending, he turned into a butterfly

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

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

Now it doesnt work at all @JR10, the debug doesnt give me anything either.

TAPL how would i do that?

Just when the caterpillar thought the world was ending, he turned into a butterfly

Posted
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?

sup?

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

CiTLh.png
Posted
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

Just when the caterpillar thought the world was ending, he turned into a butterfly

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