Visma Posted February 16, 2015 Posted February 16, 2015 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
Dealman Posted February 16, 2015 Posted February 16, 2015 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.
Enargy, Posted February 16, 2015 Posted February 16, 2015 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.
Visma Posted February 16, 2015 Author Posted February 16, 2015 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
JR10 Posted February 16, 2015 Posted February 16, 2015 Post the current code that you have. 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
Visma Posted February 16, 2015 Author Posted February 16, 2015 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
JR10 Posted February 16, 2015 Posted February 16, 2015 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
Visma Posted February 16, 2015 Author Posted February 16, 2015 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
JR10 Posted February 17, 2015 Posted February 17, 2015 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
TAPL Posted February 17, 2015 Posted February 17, 2015 Why you need the element data when you can just use the team in client side?
Visma Posted February 17, 2015 Author Posted February 17, 2015 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
Enargy, Posted February 17, 2015 Posted February 17, 2015 exactly what that means onPlayerChangeTeam? did you triggered or what? - Inactivo.
Dimmitry007 Posted February 17, 2015 Posted February 17, 2015 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?
TAPL Posted February 17, 2015 Posted February 17, 2015 addEventHandler("onClientPlayerDamage", localPlayer, function() local team = getPlayerTeam(source) local teamName = team and getTeamName(team) or "" if teamName == "Staff" then cancelEvent() end end)
Visma Posted February 19, 2015 Author Posted February 19, 2015 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
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