Jump to content

isPlayerInTeam


DRW

Recommended Posts

function medicenterVehicle ( player, seat, jacked ) 
    if not isPlayerInTeam (source, "Médico") then 
         cancelEvent() 
        outputChatBox ( "Debes de ser un médico para poder entrar al vehículo.", player ) 
    end 
end 

ERROR: attempt to call global 'isPlayerInTeam' (a nil value)

What's wrong?

Link to comment

You have to add isPlayerInTeam function to your script

function medicenterVehicle ( player, seat, jacked ) 
    if not isPlayerInTeam (source, "Médico") then 
         cancelEvent() 
        outputChatBox ( "Debes de ser un médico para poder entrar al vehículo.", player ) 
    end 
end 
  
function isPlayerInTeam(player, team) 
    assert(isElement(player) and getElementType(player) == "player", "Bad argument 1 @ isPlayerInTeam [player expected, got " .. tostring(player) .. "]") 
    assert((not team) or type(team) == "string" or (isElement(team) and getElementType(team) == "team"), "Bad argument 2 @ isPlayerInTeam [nil/string/team expected, got " .. tostring(team) .. "]") 
    return getPlayerTeam(player) == (type(team) == "string" and getTeamFromName(team) or (type(team) == "userdata" and team or (getPlayerTeam(player) or true))) 
end 

Link to comment
that's wrong replace source with player here

12401f3aab.png

i think he is trying to use "onVehicleStartEnter" and the source of this event is the vehicle in which a player began to enter.

Yes but it's still not working, same error

Link to comment

Try this it should work

function medicenterVehicle ( player, seat, jacked ) 
    local playerTeam = getPlayerTeam(player) 
    if (playerTeam) then 
        if getTeamName(playerTeam) ~= "Médico" then 
            cancelEvent() 
            outputChatBox ( "Debes de ser un médico para poder entrar al vehículo.", player,255,0,0 ) 
        end 
    end 
end 

Link to comment
Try this it should work
function medicenterVehicle ( player, seat, jacked ) 
    local playerTeam = getPlayerTeam(player) 
    if (playerTeam) then 
        if getTeamName(playerTeam) ~= "Médico" then 
            cancelEvent() 
            outputChatBox ( "Debes de ser un médico para poder entrar al vehículo.", player,255,0,0 ) 
        end 
    end end 
end 

Even people of the team can enter a vehicle

Link to comment

Even people of the team can enter a vehicle

You mean even medic players can't enter the vehicle if yes try this client side

function medicenterVehicle ( player, seat, jacked ) 
    if player == getLocalPlayer() then 
    local playerTeam = getPlayerTeam(player) 
    if (playerTeam) then 
        if not (getTeamName(playerTeam) == "Médico") then 
            cancelEvent() 
            outputChatBox ( "Debes de ser un médico para poder entrar al vehículo.", player ) 
            end 
        end 
    end  
end  
addEventHandler("onClientVehicleStartEnter",root,medicenterVehicle) 

Link to comment

Even people of the team can enter a vehicle

You mean even medic players can't enter the vehicle if yes try this client side

function medicenterVehicle ( player, seat, jacked ) 
    if player == getLocalPlayer() then 
    local playerTeam = getPlayerTeam(player) 
    if (playerTeam) then 
        if not (getTeamName(playerTeam) == "Médico") then 
            cancelEvent() 
            outputChatBox ( "Debes de ser un médico para poder entrar al vehículo.", player ) 
            end 
        end 
    end  
end  
addEventHandler("onClientVehicleStartEnter",root,medicenterVehicle) 

Actually, every player can enter a vehicle, doesn't matter if it's in médico team nor in another team, every player can enter

Link to comment

Actually, every player can enter a vehicle, doesn't matter if it's in médico team nor in another team, every player can enter

Are you sure that it's "Médico" not "Médicos" because here you are trying to use "Médicos"

0f07006f5f.png

Anyways try this before you check my code

function checkTeam (player) 
    local playerTeam = getPlayerTeam(player) 
    if (playerTeam) then 
        outputChatBox("Your team is "..getTeamName(playerTeam),player,255,0,0) 
    end  
end  
addCommandHandler("team",checkTeam) 

function medicenterVehicle ( player, seat, jacked ) 
    if not isPlayerInTeam(player,"Médico") then 
        cancelEvent() 
        outputChatBox ( "Debes de ser un médico para poder entrar al vehículo.", player ) 
    end 
end 
addEventHandler ( "onVehicleStartEnter", getRootElement(), medicenterVehicle ) 
  
function isPlayerInTeam(src, TeamName) 
    if src and isElement ( src ) and getElementType ( src ) == "player" then 
           local team = getPlayerTeam(src) 
        if team then 
            if getTeamName(team) == TeamName then 
                return true 
                else 
                return false 
            end 
        end 
    end 
end 

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