DRW Posted May 16, 2015 Share Posted May 16, 2015 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
ALw7sH Posted May 16, 2015 Share Posted May 16, 2015 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
Walid Posted May 16, 2015 Share Posted May 16, 2015 that's wrong replace source with player here i think he is trying to use "onVehicleStartEnter" and the source of this event is the vehicle in which a player began to enter. Link to comment
DRW Posted May 16, 2015 Author Share Posted May 16, 2015 that's wrong replace source with player here 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
Walid Posted May 16, 2015 Share Posted May 16, 2015 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
DRW Posted May 16, 2015 Author Share Posted May 16, 2015 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
Walid Posted May 16, 2015 Share Posted May 16, 2015 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
DRW Posted May 16, 2015 Author Share Posted May 16, 2015 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
Walid Posted May 16, 2015 Share Posted May 16, 2015 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" 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
DRW Posted May 16, 2015 Author Share Posted May 16, 2015 Yes, I changed it but didn't work. But hey, you helped me to solve this viewtopic.php?f=91&t=88021, that is almost the same as this script, thanks! Link to comment
Walid Posted May 16, 2015 Share Posted May 16, 2015 Yes, I changed it but didn't work. But hey, you helped me to solve this viewtopic.php?f=91&t=88021, that is almost the same as this script, thanks! You are welcome , try always to change the subject of the topic when your problem is solved. Link to comment
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