Jump to content

Script is not working. Please help me.


Recommended Posts

It's a client side script. The script should get all the vehicles and skip the crook vehicle (non police car), then get the distance between the police vehicles and normal ones and if the distance is more than 1000, output a message.

The error : "lua:27: attempt to compare nil with number"

So for some reason I keep getting a nil value on the distance, also how can I make it output only one message, so it won't spam the chat after each frame.

policeVehicles = { [416]=true,[574]=true, [433]=true, [427]=true, [490]=true, [528]=true, [407]=true, [544]=true, [523]=true, [598]=true, [596]=true, [597]=true, [599]=true, [432]=true, [601]=true, [428]=true, [497]=true, [510]=true, [564]=true}   
  
  
  
function enter(theVehicle,seat) 
     
    copCar = policeVehicles[getElementModel(getPedOccupiedVehicle(getLocalPlayer()))] 
     
    if not copCar then 
        for iCount = 1, #getElementsByType 'vehicle' do 
            if ( getElementsByType 'vehicle' [ iCount ] == getPedOccupiedVehicle ( getLocalPlayer() ) ) then 
                doLoop ( iCount + 1, getLocalPlayer() ) 
                pVehicle = getElementsByType 'vehicle' [ iCount ] 
                fX, fY, fZ = getElementPosition ( getLocalPlayer() ) 
                fVehicleX, fVehicleY, fVehicleZ = getElementPosition ( pVehicle ) 
                fDistance = getDistanceBetweenPoints3D ( fVehicleX, fVehicleY, fVehicleZ, fX, fY, fZ ) 
                outputChatBox( fDistance ) 
                getDistance( ) 
            end 
        end 
    end 
end 
addEventHandler ( "onClientPlayerVehicleEnter", getRootElement(), enter ) 
     
         
    function getDistance( ) 
        if ( fDistance <= 1000) then 
            cancelEvent() 
            else 
            outputChatBox( "Escaped" ) 
        end 
    end 
     
addEventHandler ( "onClientRender", getRootElement(), getDistance ) 
  

Link to comment
fDistance is nil. It is not defined.

What about fDistance = getDistanceBetweenPoints3D ( fVehicleX, fVehicleY, fVehicleZ, fX, fY, fZ ) ? isn't it global?

About spam:

https://wiki.multitheftauto.com/wiki/OnClientRender

This event is triggered every time GTA renders a new frame. It is required for the DirectX drawing functions, and also useful for other clientside operations that have to be applied repeatedly with very short time differences between them.

I need it to get the distance between the cars, I know what it does. I just wanted to output the message once, which I guess it isn't possible with the clientrender event

Link to comment

Just a little tips:

First of all - You better use https://wiki.multitheftauto.com/wiki/OnC ... StartEnter

This is triggered, when a player is beginning to enter the vehicle. Just when he press F or G. I think, this is what you want.

Line 17. may causes permanent errors. Better use outputChatBox( tostring(fDistance) )

You better never use outputChatBox within a onClientRender function. This may cause a high client cpu load when it is repeated (what you call as spam the chat).

So your structure should be:

checking the OnClientVehicleStartEnter event within a function, checking the distance and if the distance not match then cancel the event and do the outputChatBox :-)

Hope that helps :-)

CU

Link to comment
Just a little tips:

First of all - You better use https://wiki.multitheftauto.com/wiki/OnC ... StartEnter

This is triggered, when a player is beginning to enter the vehicle. Just when he press F or G. I think, this is what you want.

Line 17. may causes permanent errors. Better use outputChatBox( tostring(fDistance) )

You better never use outputChatBox within a onClientRender function. This may cause a high client cpu load when it is repeated (what you call as spam the chat).

So your structure should be:

checking the OnClientVehicleStartEnter event within a function, checking the distance and if the distance not match then cancel the event and do the outputChatBox :-)

Hope that helps :-)

CU

This is the gamemode:

When the crook reaches a certain distance from the cop vehicles, the server should output a message saying "Escaped". And OnClientVehicleStartEnter didn't solve the problem, because this is played on Race gamemode

But thanks anyways.

if anyone knows how to fix it, please help me.

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