Leonard.DC Posted November 30, 2013 Posted November 30, 2013 Im trying to restrict some vehicles to teams, but it doesn't work, and doesn't output anything in the debugscript, can someone tell me why? copVehicles = { [523] = true, [598] = true, [596] = true, [597] = true, [599] = true } function enterVehicle1 ( thePlayer, seat, jacked ) if getElementType ( thePlayer ) == "player" then if ( copVehicles[getElementModel ( source )] ) and ( not getTeamFromName ( "team i use" ) ) then removePedFromVehicle( thePlayer )-- force the player out of the vehicle outputChatBox("********", thePlayer, 255, 0, 0) end end end addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle1 ) medicVehicles = { [416] = true, } function enterVehicle2 ( thePlayer, seat, jacked ) if getElementType ( thePlayer ) == "player" then if ( medicVehicles[getElementModel ( source )] ) and ( not getTeamFromName ( "team i use" ) ) removePedFromVehicle( thePlayer ) outputChatBox("*******", thePlayer, 255, 0, 0) end end end addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle2 ) It is all the code
MTA Team 0xCiBeR Posted November 30, 2013 MTA Team Posted November 30, 2013 try using the event onVehicleStartEnter and using cancelEvent()
TAPL Posted November 30, 2013 Posted November 30, 2013 You never used getPlayerTeam to compare it with getTeamFromName.
Enargy, Posted November 30, 2013 Posted November 30, 2013 try this: copVehicles = { [523] = true, [598] = true, [596] = true, [597] = true, [599] = true } copTeam = "TEAM1" --- adds this team here function enterVehicle1 ( thePlayer, seat, jacked ) if ( getElementType ( thePlayer ) == "player" ) then local team = getPlayerTeam ( thePlayer ) local teamName = ( team and getTeamName ( team ) or "" ) if ( teamName == copTeam ) and ( copVehicles[getElementModel ( source )] )) then if ( copVehicles[getElementModel ( source )] ) and ( not getTeamFromName ( "team i use" ) ) then removePedFromVehicle( thePlayer )-- force the player out of the vehicle outputChatBox("********", thePlayer, 255, 0, 0) end end end addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle1 ) medicVehicles = { [416] = true, } medicTeam = "TEAM2" function enterVehicle2 ( thePlayer, seat, jacked ) if ( getElementType ( thePlayer ) == "player" ) then local team = getPlayerTeam ( thePlayer ) local teamName = ( team and getTeamName ( team ) or "" ) if ( teamName == medicTeam ) and ( medicVehicles[getElementModel ( source )] )) then removePedFromVehicle( thePlayer ) outputChatBox("*******", thePlayer, 255, 0, 0) end end addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle2 )
Leonard.DC Posted December 1, 2013 Author Posted December 1, 2013 It doesn't work i dont know why, im changed removePedFromVehicle to cancelEvent(), and used and fixed the code NearGreen say me, but it doesn't output anything in the debugscript, and the event doesn't cancel when i am in another team that not be medic or cop copVehicles = { [523] = true, [598] = true, [596] = true, [597] = true, [599] = true } copTeam = "Police" function enterVehicle1 ( thePlayer, seat, jacked ) if ( getElementType ( thePlayer ) == "player" ) then local team = getPlayerTeam ( thePlayer ) local teamName = ( team and getTeamName ( team ) or "" ) if ( teamName == copTeam ) and ( copVehicles[getElementModel ( source )] ) then if ( copVehicles[getElementModel ( source )] ) and ( not getTeamFromName ( "Police" ) ) then cancelEvent() outputChatBox("You cant use this vehicle", thePlayer, 255, 0, 0) end end end end addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle1 ) medicVehicles = { [416] = true, } medicTeam = "Medic" function enterVehicle2 ( thePlayer, seat, jacked ) if ( getElementType ( thePlayer ) == "player" ) then local team = getPlayerTeam ( thePlayer ) local teamName = ( team and getTeamName ( team ) or "" ) if ( teamName == medicTeam ) and ( medicVehicles[getElementModel ( source )] ) then if ( medicVehicles[getElementModel ( source )] ) and ( not getTeamFromName ( "Medic" ) ) then cancelEvent() outputChatBox("You cant use this vehicle", thePlayer, 255, 0, 0) end end end end addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle2 ) Recent code, i use Server side
tosfera Posted December 1, 2013 Posted December 1, 2013 Maybe try this; copVehicles = { [523] = true, [598] = true, [596] = true, [597] = true, [599] = true } addEventHandler ( "onVehicleStartEnter", root, function ( thePlayer, seat, jacked ) if ( getElementType ( thePlayer ) == "player" ) then local team = getPlayerTeam ( thePlayer ); if ( team ) then if ( ( copVehicles [ getElementModel ( source ) ] ) and not ( team == getTeamFromName ( "Police" ) ) ) then cancelEvent(); outputChatBox ( "You can't use this vehicle", thePlayer, 255, 0, 0, true ); end end end end ); Just woke up, can be garbage.
TAPL Posted December 1, 2013 Posted December 1, 2013 if getElementType ( thePlayer ) == "player" then
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