goofie88 Posted November 30, 2012 Share Posted November 30, 2012 hello i have a problem on restricting a vehicle on player level =( hydra = createVehicle ( 520, 1526.5999755859, 2877.1000976563, 13.89999961853, 0, 0, 90 ) function hydralock(player, seat, jacked) local level = tonumber ( getElementData ( player, "level" ) or 0 ) if (source == hydra) then if (seat == 0) then if (level <= 7) then cancelEvent() outputChatBox ( "To enter this hydra you need to be level 7 and higher", player, 255, 0, 0, true ) end end end end end addEventHandler ( "onVehicleStartEnter", getRootElement(), hydralock ) what did i do wrong? all level can enter it and no output =( Link to comment
ali Posted November 30, 2012 Share Posted November 30, 2012 hydra = createVehicle ( 520, 1526.5999755859, 2877.1000976563, 13.89999961853, 0, 0, 90 ) function hydralock(player, seat, jacked) local level = tonumber ( getElementData ( player, "level" ) or 0 ) if (source == hydra) then if (seat == 0) then if (level <= 7) then cancelEvent() outputChatBox ( "To enter this hydra you need to be level 7 and higher", player, 255, 0, 0, true ) end end end end addEventHandler ( "onVehicleStartEnter", hydra, hydralock) 1)you forgot to mention which vehicle it should be the name of vehicle in-place of getRootElement() 2)an extra End Link to comment
ali Posted November 30, 2012 Share Posted November 30, 2012 My Above script ( tested ) Link to comment
goofie88 Posted November 30, 2012 Author Share Posted November 30, 2012 ye thank you worked but how should I do if I want 2 hydras? exemple hydra1 and hydra2? Link to comment
AhmadQTR Posted November 30, 2012 Share Posted November 30, 2012 ye thank you worked but how should I do if I want 2 hydras? exemple hydra1 and hydra2? Just make a table. Link to comment
AhmadQTR Posted November 30, 2012 Share Posted November 30, 2012 I think like this Hydra = { createVehicle ( 520, 1526.5999755859, 2877.1000976563, 13.89999961853, 0, 0, 90 ) createVehicle ( 520, x, y, z, 0, 0, 90 ) } function hydralock(player, seat, jacked) local level = tonumber ( getElementData ( player, "level" ) or 0 ) if (source == Hydra) then if (seat == 0) then if (level <= 7) then cancelEvent() outputChatBox ( "To enter this hydra you need to be level 7 and higher", player, 255, 0, 0, true ) end end end end addEventHandler ( "onVehicleStartEnter", Hydra, hydralock) Just replace the x, y, z with the position. Link to comment
Anderl Posted November 30, 2012 Share Posted November 30, 2012 hydra = createVehicle ( 520, 1526.5999755859, 2877.1000976563, 13.89999961853, 0, 0, 90 ) function hydralock(player, seat, jacked) local level = tonumber ( getElementData ( player, "level" ) or 0 ) if (source == hydra) then if (seat == 0) then if (level <= 7) then cancelEvent() outputChatBox ( "To enter this hydra you need to be level 7 and higher", player, 255, 0, 0, true ) end end end end addEventHandler ( "onVehicleStartEnter", hydra, hydralock) 1)you forgot to mention which vehicle it should be the name of vehicle in-place of getRootElement() 2)an extra End Wrong. He used a statement with a condition "source == hydra" which does the same as putting the element 'hydra' instead of 'root'. I think like this Hydra = { createVehicle ( 520, 1526.5999755859, 2877.1000976563, 13.89999961853, 0, 0, 90 ) createVehicle ( 520, x, y, z, 0, 0, 90 ) } function hydralock(player, seat, jacked) local level = tonumber ( getElementData ( player, "level" ) or 0 ) if (source == Hydra) then if (seat == 0) then if (level <= 7) then cancelEvent() outputChatBox ( "To enter this hydra you need to be level 7 and higher", player, 255, 0, 0, true ) end end end end addEventHandler ( "onVehicleStartEnter", Hydra, hydralock) Just replace the x, y, z with the position. It's wrong too because you can't compare an element with a table. Link to comment
AhmadQTR Posted November 30, 2012 Share Posted November 30, 2012 hydra = createVehicle ( 520, 1526.5999755859, 2877.1000976563, 13.89999961853, 0, 0, 90 ) function hydralock(player, seat, jacked) local level = tonumber ( getElementData ( player, "level" ) or 0 ) if (source == hydra) then if (seat == 0) then if (level <= 7) then cancelEvent() outputChatBox ( "To enter this hydra you need to be level 7 and higher", player, 255, 0, 0, true ) end end end end addEventHandler ( "onVehicleStartEnter", hydra, hydralock) 1)you forgot to mention which vehicle it should be the name of vehicle in-place of getRootElement() 2)an extra End Wrong. He used a statement with a condition "source == hydra" which does the same as putting the element 'hydra' instead of 'root'. I think like this Hydra = { createVehicle ( 520, 1526.5999755859, 2877.1000976563, 13.89999961853, 0, 0, 90 ) createVehicle ( 520, x, y, z, 0, 0, 90 ) } function hydralock(player, seat, jacked) local level = tonumber ( getElementData ( player, "level" ) or 0 ) if (source == Hydra) then if (seat == 0) then if (level <= 7) then cancelEvent() outputChatBox ( "To enter this hydra you need to be level 7 and higher", player, 255, 0, 0, true ) end end end end addEventHandler ( "onVehicleStartEnter", Hydra, hydralock) Just replace the x, y, z with the position. It's wrong too because you can't compare an element with a table. Oh okay sorry and thanks for the information Link to comment
goofie88 Posted November 30, 2012 Author Share Posted November 30, 2012 there is no way to make 2 hydras locked to level? Also the above code didn't really work because i cant set vehicle color then =( Link to comment
Anderl Posted November 30, 2012 Share Posted November 30, 2012 (edited) local pVehicles = { [1] = createVehicle( 520, 1526.5999755859, 2877.1000976563, 13.89999961853, 0, 0, 90 ); } function VehicleEnter( player, seat ) if ( seat == 0 ) then local nLevel = tonumber( getElementData( player, "level" ) ) or 0; if ( nLevel < 7 ) then cancelEvent(); outputChatBox( "To enter this hydra you must have level 7 or higher!", player, 255, 0, 0, false ); end end end -- for _, vehicle in ipairs( pVehicles ) do addEventHandler( "onVehicleStartEnter", vehicle, VehicleEnter ); end Edited November 30, 2012 by Guest Link to comment
goofie88 Posted November 30, 2012 Author Share Posted November 30, 2012 badargument @ addEventHandler [expected function at argument 3, got nil] and all levels can enter Link to comment
Anderl Posted November 30, 2012 Share Posted November 30, 2012 My bad, copy my last code again. Link to comment
goofie88 Posted November 30, 2012 Author Share Posted November 30, 2012 Thank you very much Anderl, everything works great now thank you how can I set the vehicle color if it's a table? im confused a bit Link to comment
Anderl Posted November 30, 2012 Share Posted November 30, 2012 One way would be to use same indexes as in "pVehicles" table in another table with its respective colors. Example: local pColors = { [1] = { 255, 0, 0 }; } for i, model in ipairs( pVehicles ) do setVehicleColor( model, unpack( pColors[i] ) ); end ( This will set vehicle with index 1 at "pVehicle" table with the specified color in the table at index 1 in "pColors" ) Put this below "pVehicles" table. Link to comment
myonlake Posted November 30, 2012 Share Posted November 30, 2012 That's a very interesting scripting technique, Anderl. Congratulations Link to comment
goofie88 Posted December 1, 2012 Author Share Posted December 1, 2012 works perfect man last question and I'll stop asking, why can everyone enter if I add this if not (getElementData(player, "gang") == "Army") then under if ( nLevel < 7 ) then , all gang can enter, but not ppl lower level 7 Link to comment
Anderl Posted December 1, 2012 Share Posted December 1, 2012 I didn't understand it; You want to block access from gangs too or a specific one? That's a very interesting scripting technique, Anderl. Congratulations Ahah, thanks. Link to comment
goofie88 Posted December 1, 2012 Author Share Posted December 1, 2012 yes i tried to block acces to all gangs except Army but everyone can enter =( Link to comment
Anderl Posted December 1, 2012 Share Posted December 1, 2012 Well, just check if the player is in a gang and if it is check if "gang" element data is "Army". If it isn't, block access. I can't show you an example because I don't know how your gang system works. Link to comment
goofie88 Posted December 1, 2012 Author Share Posted December 1, 2012 like that? function VehicleEnter( player, seat ) if ( seat == 0 ) then local nLevel = tonumber( getElementData( player, "level" ) ) or 0; local accountName = getAccountName ( getPlayerAccount ( player ) ) local gangName = exports.gangsystem:getAccountGang ( accountName ) if not (gangName == "Army") then if ( nLevel < 7 ) then cancelEvent(); outputChatBox( "This vehicle is locked to the Army lvl 7!", player, 255, 0, 0, false ); end end end end Link to comment
Anderl Posted December 1, 2012 Share Posted December 1, 2012 like that? function VehicleEnter( player, seat ) if ( seat == 0 ) then local nLevel = tonumber( getElementData( player, "level" ) ) or 0; local accountName = getAccountName ( getPlayerAccount ( player ) ) local gangName = exports.gangsystem:getAccountGang ( accountName ) if not (gangName == "Army") then if ( nLevel < 7 ) then cancelEvent(); outputChatBox( "This vehicle is locked to the Army lvl 7!", player, 255, 0, 0, false ); end end end end Would not "getAccountGang" use account element and not account name? Is the gang system made by you or is it from community? If it's from community, you mind sending me link to check that? Try this, anyway: function VehicleEnter( player, seat ) if ( seat == 0 ) then local nLevel = tonumber( getElementData( player, "level" ) ) or 0; local szGang = exports.gangsystem:getAccountGang( getAccountName( getPlayerAccount( player ) ) ); if ( ( szGang ~= "Army" ) or ( szGang == "Army" and nLevel < 7 ) ) then cancelEvent(); outputChatBox( "This vehicle is locked to Army level 7!", player, 255, 0, 0, false ); end end end Link to comment
goofie88 Posted December 1, 2012 Author Share Posted December 1, 2012 Works perfectly now thank you very much 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