Jump to content

Vehicle close to coordinates


wajsic

Recommended Posts

Posted

Hello!

As you can see in title I want to make script which "look" if is vehicle which are gonna be spawned close to coordinates with another vehicle. Acctualy it have check if is there another vehicle. If is there mustn't spawn it.

Posted

Ok... I have a script which:

1. Teleport me to house

2. Spawns a car in front of garage.

Problem is, when I type in a command it tp me and spawns a car. So I want to prevenet car spawn if one is there already

Do you know what I mean?

Posted

Would it work if I create marker and marker checks if is there an empty vehicle? It is possible that marker detect empty vehicle?

Posted
Would it work if I create marker and marker checks if is there an empty vehicle? It is possible that marker detect empty vehicle?

yes if the Marker is serverside, you will check it serverside, and the vehicle has a syncer (is in range of 140 game distance units from any player)

  • Moderators
Posted

This is more than a clue :mrgreen: :

function yourFunction () 
    local marker = createMarker( ... ) -- create your marker where you want 
    local veh = getVehicleInMarker( marker ) -- we try to get the vehicle in the marker  
    if ( veh ) then 
        if ( isAnEmptyVeh( veh ) ) then 
            outputChatBox( "There is a vehicle in the marker and it's not empty !" ) 
        else 
            outputChatBox( "There is no vehicle in the marker but it's empty !" ) 
        end 
    else 
        outputChatBox( "There is no vehicle in the marker !" ) 
    end 
end 
  
  
function getVehicleInMarker( theMarker ) 
    local veh = false 
    for k,i in ipairs ( getElementsByType( "vehicle" ) ) do -- we get all vehicles in the server 
        if ( isElementWithinMarker( i, theMarker ) ) then -- if a vehicle is in the marker 
            veh = i -- we store the vehElement in veh 
            break -- Exit the loop 
        end 
    end 
    return veh  -- Return the vehElement( = there is a vehicle in the marker)  or false ( = no vehicle in the marker ) 
end 
  
function isAnEmptyVeh( theVeh ) 
    if ( getElementType ( theVeh ) == "vehicle" ) then -- we get if theVeh is really a vehicle 
        local tablePassenger = getVehicleOccupants( theVeh ) -- we get all passengers in the vehicle 
        local passengers = #tablePassenger -- we get how many lines in the table ( 1 line by passenger ) 
        if ( passengers <= 0 ) then -- if there are no passengers 
            return true -- we return true 
        end 
        return false -- false otherwise 
    end 
end 

If you don't understand my code, tell me it :wink:

Posted

hmm...

createMarker creates a element node in resorce dynamic map and rerurn a pointer of that element, iven if the pointer is lical, the element is not destroyed with the variable ( also 'if ( veh ) then' is wrong, it should be' if isElement( veh ) then')

so every time yourFunction () is called, new marker is created, and it is not destroyed. Is tat good?

Posted (edited)
function isInRange(element, radius, x, y, z) 
    local oldposx, oldposy, oldposz = getElementPosition(element) 
    local tempposx = (oldposx-x); 
    local tempposy = (oldposy-y); 
    local tempposz = (oldposz-z); 
    if(((tempposx < radius) and (tempposx > -radius)) and ((tempposy < radius) and (tempposy > -radius)) and ((tempposz < radius) and (tempposz > -radius))) then 
        return 1 
    else 
        return 0 
    end 
end 

You can use that, put a radious of 3 at least.

Edited by Guest
  • Moderators
Posted

Yeah I can make a destroyElement for the marker but he can do that alone ?:

function yourFunction () 
    local marker = createMarker( ... ) -- create your marker where you want 
    local veh = getVehicleInMarker( marker ) -- we try to get the vehicle in the marker 
    if ( veh ) then 
        if ( isAnEmptyVeh( veh ) ) then 
            outputChatBox( "There is a vehicle in the marker and it's not empty !" ) 
        else 
            outputChatBox( "There is no vehicle in the marker but it's empty !" ) 
        end 
    else 
        outputChatBox( "There is no vehicle in the marker !" ) 
    end 
    destroyElement( marker ) 
end 

onMarkerHit is triggered only when an element enter in the marker, so if you create a marker on the vehicle, this event is not triggered.

Why you doesn't want use my script ? It should works perfectly :roll:

Posted
Why you doesn't want use my script ? It should works perfectly :roll:

people should avoid using stuff that they dont understand to well if it comes to scripting ;)

  • Moderators
Posted
people should avoid using stuff that they dont understand to well if it comes to scripting

He added me on skype and I made a very long explaination ( 1 hour ) and when I told him new things ( like tables or for k, i in ipairs ), I explained it and I show him an exemple full annotated,then I ask him if he understand it.

And I can say that it's a good student ^^

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