Jump to content

Help with getting team


xyz

Recommended Posts

So the thing is I can't get this working.

function staffskin(player) 
    if getPlayerTeam(player) == "Staff" then 
        cancelEvent() 
            else 
        end 
end 
addEventHandler("onElementModelChange", getRootElement(), staffskin) 

What's wrong?

Link to comment
  • Moderators

An empty else is no needed and you are comparing a team element (left) with a team name (right).

Also, this event doesn't support cancelation (as 3FreT pointed out) so you have to use setElementModel with the previous model.

This event will give you only one parameter which is the previous model so your "player" is wrong, you wanted to use source instead in your getPlayerTeam function call:

function staffskin(prevSkin) 
    if getPlayerTeam(source) == getTeamFromName("Staff") then 
        setElementModel(source, prevSkin) 
    end 
end 
addEventHandler("onElementModelChange", getRootElement(), staffskin) 

Also as this event will also be triggered for other elements like objects, cars etc, you need to check if source is a player element or you will get warnings or errors:

function staffskin(prevSkin) 
    if getElementType(source) == "player" and getPlayerTeam(source) == getTeamFromName("Staff") then 
        setElementModel(source, prevSkin) 
    end 
end 
addEventHandler("onElementModelChange", getRootElement(), staffskin) 

So this code will prevent any skin change if the player is in the "Staff" team, is it really what you wanted to do ?

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