wajsic Posted March 14, 2011 Share Posted March 14, 2011 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. Link to comment
Castillo Posted March 14, 2011 Share Posted March 14, 2011 I don't get what do you mean, could you explain yourself better? Link to comment
wajsic Posted March 14, 2011 Author Share Posted March 14, 2011 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? Link to comment
proracer Posted March 14, 2011 Share Posted March 14, 2011 Well you can save the account data when the car is spawned. Link to comment
wajsic Posted March 15, 2011 Author Share Posted March 15, 2011 Would it work if I create marker and marker checks if is there an empty vehicle? It is possible that marker detect empty vehicle? Link to comment
Wojak Posted March 15, 2011 Share Posted March 15, 2011 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) Link to comment
wajsic Posted March 15, 2011 Author Share Posted March 15, 2011 Great! Now I just need to figure out how to. EDIT: Can someone give me a clue? Link to comment
Moderators Citizen Posted March 15, 2011 Moderators Share Posted March 15, 2011 This is more than a clue : 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 Link to comment
Wojak Posted March 15, 2011 Share Posted March 15, 2011 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? Link to comment
wajsic Posted March 15, 2011 Author Share Posted March 15, 2011 What if I use simple onMarkerHit event? https://wiki.multitheftauto.com/wiki/OnMarkerHit Link to comment
Feche1320 Posted March 15, 2011 Share Posted March 15, 2011 (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 March 16, 2011 by Guest Link to comment
Moderators Citizen Posted March 16, 2011 Moderators Share Posted March 16, 2011 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 Link to comment
Wojak Posted March 17, 2011 Share Posted March 17, 2011 Why you doesn't want use my script ? It should works perfectly people should avoid using stuff that they dont understand to well if it comes to scripting Link to comment
Moderators Citizen Posted March 17, 2011 Moderators Share Posted March 17, 2011 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 ^^ 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