Jump to content

Car Ristriction...


DhrJay

Recommended Posts

Hey guys!

Can someone please tell me what I did wrong?

This is my carristriction.lua:

addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), 
    function() 
        armySkins = { [287]=true, [217]=true} 
        armycars = { [432]=true, [520]=true, [425]=true, [548]=true } 
         
    end 
) 
  
function enterVehicle ( thePlayer, seat, jacked ) 
    if ( armycars[getElementModel ( source )] ) and ( not armySkins[getElementModel ( thePlayer )] ) and (seat == 0) then  
        cancelEvent() 
        outputChatBox ( "Only army members can drive this car!", thePlayer ) 
    end 
end 

This is my meta.xml:

<meta> 
  
    <script src="rrtrucker_server.lua" /> 
  
</meta> 

Link to comment
There's no eventhandler attached to the function.

Hey! Thanks for the quick reply... But the first line says:

addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), 

What's the right way to do it?

I'm learning LUA so, be patient please...xD

Link to comment
armySkins = { 287, 217 } 
armycars = { 432, 520, 425, 548 } 
  
function enterVehicle ( theVehicle, seat, jacked ) 
if ( armycars[getElementModel ( theVehicle )] ) and ( not armySkins[getElementModel ( source )] ) and (seat == 0) then 
    cancelEvent() 
    outputChatBox ( "Only army members can drive this car!", source ) 
end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) -- this is the event. 

Link to comment

Thanks all!

I have this now..But it still doesn't work...xD

carristriction.lua:

armySkins = { 287, 217 } 
armycars = { 432, 520, 425, 548 } 
      
function enterVehicle ( theVehicle, seat, jacked ) 
if ( armycars[getElementModel ( theVehicle )] ) and ( not armySkins[getElementModel ( source )] ) and (seat == 0) then 
cancelEvent() 
outputChatBox ( "Only army members can drive this car!", source ) 
end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) -- this is the event. 

Meta.xml

<meta> 
  
    <script src="carristriction.lua" /> 
  
</meta> 

Link to comment

That's because of how you made the table, also, 'source' of 'onVehicleEnter' is the vehicle element, not the player who entered.

armySkins = 
    { 
        [ 287 ] = true, 
        [ 217 ] = true 
    } 
armycars = 
    { 
        [ 432 ] = true, 
        [ 520 ] = true, 
        [ 425 ] = true, 
        [ 548 ] = true 
    } 
  
function enterVehicle ( thePlayer, seat, jacked ) 
    if ( armycars [ getElementModel ( source ) ] ) and ( not armySkins [ getElementModel ( thePlayer ) ] ) and ( seat == 0 ) then 
        cancelEvent ( ) 
        outputChatBox ( "Only army members can drive this car!", thePlayer ) 
    end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) -- this is the event. 

Link to comment
That's because of how you made the table, also, 'source' of 'onVehicleEnter' is the vehicle element, not the player who entered.
armySkins = 
    { 
        [ 287 ] = true, 
        [ 217 ] = true 
    } 
armycars = 
    { 
        [ 432 ] = true, 
        [ 520 ] = true, 
        [ 425 ] = true, 
        [ 548 ] = true 
    } 
  
function enterVehicle ( thePlayer, seat, jacked ) 
    if ( armycars [ getElementModel ( source ) ] ) and ( not armySkins [ getElementModel ( thePlayer ) ] ) and ( seat == 0 ) then 
        cancelEvent ( ) 
        outputChatBox ( "Only army members can drive this car!", thePlayer ) 
    end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) -- this is the event. 

Hey man!

Thanks! This still doesnt work though... :(

The server doesnt even find the resource...

-Jay

Link to comment
That's because of how you made the table, also, 'source' of 'onVehicleEnter' is the vehicle element, not the player who entered.
armySkins = 
    { 
        [ 287 ] = true, 
        [ 217 ] = true 
    } 
armycars = 
    { 
        [ 432 ] = true, 
        [ 520 ] = true, 
        [ 425 ] = true, 
        [ 548 ] = true 
    } 
  
function enterVehicle ( thePlayer, seat, jacked ) 
    if ( armycars [ getElementModel ( source ) ] ) and ( not armySkins [ getElementModel ( thePlayer ) ] ) and ( seat == 0 ) then 
        cancelEvent ( ) 
        outputChatBox ( "Only army members can drive this car!", thePlayer ) 
    end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) -- this is the event. 

armySkins = 
    { 
        [ 287 ] = true, 
        [ 217 ] = true 
    } 
armycars = 
    { 
        [ 432 ] = true, 
        [ 520 ] = true, 
        [ 425 ] = true, 
        [ 548 ] = true 
    } 
  
function enterVehicle ( thePlayer, seat, jacked ) 
    if ( armycars [ getElementModel ( source ) ] ) and ( not armySkins [ getElementModel ( thePlayer ) ] ) and ( seat == 0 ) then 
        cancelEvent ( ) 
        outputChatBox ( "Only army members can drive this car!", thePlayer ) 
    end 
end 
addEventHandler("onVehicleStartEnter", root, enterVehicle ) 

Event onVehicleEnter could not be canceled , onVehicleStartEnter could be

Link to comment
Are you completely sure that you put it on the right folder? is it a folder or a zip?

YOU F****ING MADE IT! HOW DO YOU KNOW THESE THINGS...xD! I made it a ZIP file, and now it works...

Really, where did you learn all this? I really want to start learning scripting too... But it's very hard for me to understand it... Do you have any URL where I could start? (Exept for the MTA scripting tutorials.. :P)

(PS: Why does it make such a big difference between a normal folder?!)

Tnkx,

Jay

Link to comment
outputChatBox ( "#EE0000 Only army members can drive this car!", thePlayer, 255, 255, 255, true ) 

I said on the last argument, not a comma and 'true' on the string :roll:

Hahaha! you see... I'm a newbie...xD! Thanks man...Won't bother you any longer (for today :P )...

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