Jump to content

Car Ristriction...


DhrJay

Recommended Posts

Posted

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> 

Posted
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

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

Destruction Derby

Posted
This is my carristriction.lua:

This is my meta.xml:

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

You made it wrong, should be this

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

Posted

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> 

Posted

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. 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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

Posted

Why not? what does it say on the console?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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

F4MZM4.gif

Posted

My bad, I didn't notice it was wrong event used.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
Why not? what does it say on the console?
\

Well, that's the problem... It doesn't say anything at all...xD

It says: start: Resource could not be found.

Maybee it's my META:

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

Posted

Try writing "refresh" on the server console.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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

Posted

Actually, folders also work, I got most of my scripts on folders, the only thing that doesn't work is rar.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
Actually, folders also work, I got most of my scripts on folders, the only thing that doesn't work is rar.

Strange...But thanks anyways...!

Do you know how I could add colors to the message?

#EE0000

Posted

Define the color of outputChatBox, and set to 'true' the last argument of it.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
Define the color of outputChatBox, and set to 'true' the last argument of it.

Like this?

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

Posted
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:

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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

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