Jump to content
Sign in to follow this  
brunohxcx

Land transporter script

Recommended Posts

hi, im trying to add a npc to drive around and transport players to some side missions.

_bus1 = creategroup CIVILIAN;
_vehicleName = vehicleVarName _bus;

_bus1 = createVehicle ["C_Hatchback_01_F", getMarkerPos "busspawn", [], 0, "NONE"];
createVehicleCrew _bus1;
_bus1 allowDamage false;

sleep 30;
_bus1 doMove (getmarkerpos "buswp1");
_bus1 doMove (getmarkerpos "busstop1");
sleep 30;
_bus1 doMove (getmarkerpos "buswp2");
_bus1 doMove (getmarkerpos "busstop2");
sleep 30;
_bus1 doMove (getmarkerpos "buswp3");
_bus1 doMove (getmarkerpos "busstop3");

this spawns a car wirh a driver, go to point A and wait 30 secs to go to next stop.

how can i make it check if there is any player nearby the stop marker?

if true it waits 30 sec, if false it goes to the next stop

and how can i make it loop forever?

Share this post


Link to post
Share on other sites

Hey, I had a crack at this, it's a bit rough but it should get your started:

[color="#FF8040"][color="#006400"][i]//[/i][/color]
[color="#006400"][i]//      Name: createTransportLoop[/i][/color]
[color="#006400"][i]//	Desc: Creates a transport route for an ai vehicle that stops for players and loops indefinitely		[/i][/color]
[color="#006400"][i]//	Author: Sli[/i][/color]
[color="#006400"][i]//      Return: Nothing[/i][/color]
[color="#006400"][i]//[/i][/color]

[color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]count[/b][/color] [color="#000000"]_this[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color] [color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_transportWaypoints[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#000000"]_this[/color][color="#8B3E2F"][b];[/b][/color]

[color="#006400"][i]// Create the transport and assign a crew for it[/i][/color]
[color="#1874CD"]_transportArray[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b]([/b][/color][color="#000000"]_this[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b],[/b][/color][color="#191970"][b]random[/b][/color] [color="#FF0000"]360[/color][color="#8B3E2F"][b],[/b][/color] [color="#7A7A7A"]"O_Truck_03_transport_F"[/color][color="#8B3E2F"][b],[/b][/color] [color="#000000"]west[/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]call[/b][/color] BIS_fnc_spawnVehicle[color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_transport[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_transportArray[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]createVehicleCrew[/b][/color] [color="#1874CD"]_transport[/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_transportDriver[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]driver[/b][/color] [color="#1874CD"]_transport[/color][color="#8B3E2F"][b];[/b][/color]

[color="#006400"][i]// Configuration[/i][/color]
[color="#1874CD"]_waitPeriod[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#FF0000"]30[/color][color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]// How long the transport should wait if there is people at a stop[/i][/color]
[color="#1874CD"]_radiusFromStop[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#FF0000"]30[/color][color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]// Radius around the stop to check for people[/i][/color]
[color="#1874CD"]_movingPeriod[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#FF0000"]5[/color][color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]// How quickly the transport should switch between waypoints [/i][/color]
[color="#1874CD"]_checkPeriod[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]// Default minimum check rate of the overall loop[/i][/color]
[color="#1874CD"]_transportTarget[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]// Start by going to stop #1[/i][/color]

TRANSPORT_ACTIVE [color="#8B3E2F"][b]=[/b][/color] [color="#000000"]true[/color][color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]// Set to false to end the bus loop if it's active (may take the sleep period to stop)[/i][/color]
[color="#1874CD"]_hasWaited[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#000000"]false[/color][color="#8B3E2F"][b];[/b][/color]

[color="#191970"][b]for[/b][/color] [color="#7A7A7A"]"_i"[/color] [color="#191970"][b]from[/b][/color] [color="#FF0000"]0[/color] [color="#191970"][b]to[/b][/color] [color="#FF0000"]1[/color] [color="#191970"][b]step[/b][/color] [color="#FF0000"]0[/color] [color="#191970"][b]do[/b][/color] [color="#8B3E2F"][b]{[/b][/color]

[color="#006400"][i]// If the bus dies, is stuck, or its driver is incapacitated, abort![/i][/color]
[color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]![/b][/color][color="#191970"][b]alive[/b][/color] [color="#1874CD"]_transport[/color] [color="#8B3E2F"][b]|[/b][/color][color="#8B3E2F"][b]|[/b][/color] [color="#8B3E2F"][b]![/b][/color][color="#191970"][b]canMove[/b][/color] [color="#1874CD"]_transport[/color]  [color="#8B3E2F"][b]|[/b][/color][color="#8B3E2F"][b]|[/b][/color] [color="#8B3E2F"][b]![/b][/color][color="#191970"][b]alive[/b][/color] [color="#1874CD"]_transportDriver[/color] [color="#8B3E2F"][b]|[/b][/color][color="#8B3E2F"][b]|[/b][/color] [color="#8B3E2F"][b]![/b][/color][color="#191970"][b]canMove[/b][/color] [color="#1874CD"]_transport[/color] [color="#8B3E2F"][b]|[/b][/color][color="#8B3E2F"][b]|[/b][/color] [color="#8B3E2F"][b]![/b][/color]TRANSPORT_ACTIVE[color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color] [color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#1874CD"]_nextStop[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_transportWaypoints[/color] [color="#191970"][b]select[/b][/color] [color="#1874CD"]_transportTarget[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_sleepTime[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_checkPeriod[/color][color="#8B3E2F"][b];[/b][/color]

[color="#006400"][i]// If the bus is outside the check radius for the stop, keep sending it to the position[/i][/color]
[color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_transport[/color] [color="#191970"][b]distance[/b][/color] [color="#1874CD"]_nextStop[/color] [color="#8B3E2F"][b]>[/b][/color] [color="#1874CD"]_radiusFromStop[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]then[/b][/color] [color="#8B3E2F"][b]{[/b][/color]	
	[color="#1874CD"]_transport[/color] [color="#191970"][b]doMove[/b][/color] [color="#1874CD"]_nextStop[/color][color="#8B3E2F"][b];[/b][/color]
	[color="#1874CD"]_sleepTime[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_movingPeriod[/color][color="#8B3E2F"][b];[/b][/color]
	[color="#191970"][b]systemChat[/b][/color] [color="#191970"][b]format[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]'Transport moving to %1 at %2'[/color][color="#8B3E2F"][b],[/b][/color] [color="#1874CD"]_transportTarget[/color][color="#8B3E2F"][b],[/b][/color] [color="#000000"]time[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#006400"][i]// If the bus is within range of the stop, check for commuters[/i][/color]
[color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_transport[/color] [color="#191970"][b]distance[/b][/color] [color="#1874CD"]_nextStop[/color] [color="#8B3E2F"][b]<[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_radiusFromStop[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]then[/b][/color] [color="#8B3E2F"][b]{[/b][/color]

	[color="#FF8040"][color="#006400"][i]// Find commuters/players in stop radius[/i][/color]
	[color="#1874CD"]_hasCommuters[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]  
	[color="#8B3E2F"][b]{[/b][/color] [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]isPlayer[/b][/color] [color="#000000"]_x[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]then[/b][/color] [color="#8B3E2F"][b]{[/b][/color]  [color="#1874CD"]_hasCommuters[/color] [color="#191970"][b]pushBack[/b][/color] [color="#000000"]_x[/color][color="#8B3E2F"][b];[/b][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#8B3E2F"][b]}[/b][/color] [color="#191970"][b]count[/b][/color] [color="#8B3E2F"][b]([/b][/color] [color="#1874CD"]_nextStop[/color] [color="#191970"][b]nearEntities[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"Man"[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b],[/b][/color] [color="#1874CD"]_radiusFromStop[/color][color="#8B3E2F"][b]][/b][/color] [color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]>[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b];[/b][/color] [/color]


	[color="#006400"][i]// If there are people there and we've not already waited, stop for wait period[/i][/color]
	[color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]count[/b][/color] [color="#1874CD"]_hasCommuters[/color] [color="#8B3E2F"][b]>[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#FF0000"]1[/color] [color="#8B3E2F"][b]&[/b][/color][color="#8B3E2F"][b]&[/b][/color] [color="#8B3E2F"][b]![/b][/color][color="#1874CD"]_hasWaited[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]then[/b][/color] [color="#8B3E2F"][b]{[/b][/color]

		[color="#1874CD"]_sleepTime[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_waitPeriod[/color][color="#8B3E2F"][b];[/b][/color] [color="#1874CD"]_hasWaited[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#000000"]true[/color][color="#8B3E2F"][b];[/b][/color]
		[color="#191970"][b]systemChat[/b][/color] [color="#191970"][b]format[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]'Transport stopped at %1 until %2'[/color][color="#8B3E2F"][b],[/b][/color] [color="#1874CD"]_transportTarget[/color][color="#8B3E2F"][b],[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#000000"]time[/color] [color="#8B3E2F"][b]+[/b][/color] [color="#1874CD"]_waitPeriod[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]

	[color="#8B3E2F"][b]}[/b][/color] [color="#191970"][b]else[/b][/color] [color="#8B3E2F"][b]{[/b][/color]

		[color="#1874CD"]_hasWaited[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#000000"]false[/color][color="#8B3E2F"][b];[/b][/color]

		[color="#006400"][i]// Otherwise, find the next stop, loop back to the start if we're at the end of the array[/i][/color]
		[color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_transportTarget[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]count[/b][/color] [color="#1874CD"]_transportWaypoints[/color] [color="#8B3E2F"][b]-[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]then[/b][/color] [color="#8B3E2F"][b]{[/b][/color]	[color="#1874CD"]_transportTarget[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b];[/b][/color] [color="#8B3E2F"][b]}[/b][/color] [color="#191970"][b]else[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#1874CD"]_transportTarget[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_transportTarget[/color] [color="#8B3E2F"][b]+[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b];[/b][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]			
		[color="#1874CD"]_sleepTime[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_checkPeriod[/color][color="#8B3E2F"][b];[/b][/color]		

	[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#191970"][b]sleep[/b][/color] [color="#1874CD"]_sleepTime[/color][color="#8B3E2F"][b];[/b][/color]

[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
[/color]

All you need to do is an array of points (positions) and it will create the AI vehicle and do the rest. You may need to fiddle with how/who the AI vehicle is spawned by, especially in MP as if the groups aren't configured correctly they might not do what you want. I just used BIS_fnc_spawnVehicle to easily make a demonstration vehicle.

[color="#FF8040"][color="#8B3E2F"][b][[/b][/color]   [color="#8B3E2F"][b][[/b][/color][color="#FF0000"]34943[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]12123[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#FF0000"]33223[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]13333[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#FF0000"]32113[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]13333[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b]][/b][/color] [color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]execVM[/b][/color] 'createTransportLoop.sqf'[color="#8B3E2F"][b];[/b][/color][/color]

Assuming your positions aren't likely to change , my favourite method of getting all that position data is creating markers in the editor like this:

wRFS3dC.jpg

And then using this function when the mission loads to find all the positions:

[color="#FF8040"][color="#006400"][i]//[/i][/color]
[color="#006400"][i]//      Name: findAllMarkers[/i][/color]
[color="#006400"][i]//	Desc: Finds all markers of a given stem and returns all positions as an array[/i][/color]
[color="#006400"][i]//	Author: Sli[/i][/color]
[color="#006400"][i]//      Return: Array [Marker positions][/i][/color]
[color="#006400"][i]//[/i][/color]

findAllMarkers [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b]{[/b][/color]

[color="#191970"][b]private[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"_stem"[/color][color="#8B3E2F"][b],[/b][/color] [color="#7A7A7A"]"_a"[/color][color="#8B3E2F"][b],[/b][/color] [color="#7A7A7A"]"_d"[/color][color="#8B3E2F"][b],[/b][/color] [color="#7A7A7A"]"_max"[/color][color="#8B3E2F"][b],[/b][/color] [color="#7A7A7A"]"_endIf"[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#1874CD"]_stem[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#000000"]_this[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]// String with the beginning part of the marker name[/i][/color]
[color="#1874CD"]_endIf[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]isNil[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#000000"]_this[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]1[/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]then[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#000000"]false[/color] [color="#8B3E2F"][b]}[/b][/color] [color="#191970"][b]else[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#000000"]_this[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]// End early if we're missing a marker (default: false)[/i][/color]
[color="#1874CD"]_max[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]isNil[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#000000"]_this[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]2[/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]then[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#FF0000"]50[/color] [color="#8B3E2F"][b]}[/b][/color] [color="#191970"][b]else[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#000000"]_this[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]2[/color][color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]// Absolute maximum number of markers in this series (default: 50)[/i][/color]

[color="#1874CD"]_a[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#191970"][b]for[/b][/color] [color="#7A7A7A"]"_s"[/color] [color="#191970"][b]from[/b][/color] [color="#FF0000"]0[/color] [color="#191970"][b]to[/b][/color] [color="#1874CD"]_max[/color] [color="#191970"][b]step[/b][/color] [color="#FF0000"]1[/color] [color="#191970"][b]do[/b][/color] [color="#8B3E2F"][b]{[/b][/color]			

	[color="#1874CD"]_m[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]getMarkerPos[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]format[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]'%1_%2'[/color][color="#8B3E2F"][b],[/b][/color] [color="#1874CD"]_stem[/color][color="#8B3E2F"][b],[/b][/color] [color="#1874CD"]_s[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color]		
	[color="#1874CD"]_d[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]vectorMagnitude[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_m[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color]

	[color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_d[/color] [color="#8B3E2F"][b]<[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#FF0000"]0[/color] [color="#8B3E2F"][b]&[/b][/color][color="#8B3E2F"][b]&[/b][/color] [color="#1874CD"]_endIf[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color] [color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]// End loop early if the marker chain is incomplete[/i][/color]
	[color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_d[/color] [color="#8B3E2F"][b]>[/b][/color] [color="#FF0000"]0[/color] [color="#8B3E2F"][b]&[/b][/color][color="#8B3E2F"][b]&[/b][/color] [color="#8B3E2F"][b]![/b][/color][color="#1874CD"]_endIf[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]then[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#1874CD"]_a[/color] [color="#191970"][b]pushBack[/b][/color] [color="#1874CD"]_m[/color][color="#8B3E2F"][b];[/b][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]// Marker is valid, so add it to the array[/i][/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#1874CD"]_a[/color]

[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

It accepts a marker "stem" i.e "stop" and then finds all markers in a series, such as stop_0, stop_1, stop_2 etc and returns their positions as an array. So the transport route above might work a bit like this:

[color="#FF8040"][color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"stop"[/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]call[/b][/color] findAllMarkers[color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]execVM[/b][/color] 'createTransportLoop.sqf'[color="#8B3E2F"][b];[/b][/color][/color]

Made with KK's SQF to BBCode Converter

Edited by chrisnic

Share this post


Link to post
Share on other sites

Here is my attempt

//[ markers, vehicleType, wait time, stop radius, spawn location ] execvm "busStop.sqf"
//Markers <ARRAY> or <STRING> - either an ARRAY of markers OR a base name STRING of markers to look for
//VehicleType <STRING> - a vehicle class name to spawn
//Wait Time <NUMBER> - time in seconds to wait at a waypoint
//Stop Radius <NUMBER> - distance in meters a player must be to a waypoint for the vehicle to Wait, will also wait if there is a player passenger
//Spawn Location <POSTION> or <STRING> - initial position to spawn vehicle at position or marker name, first WP used if not supplied

//example
//will look for markers named busStop_0 to busStop_#
//will create a C_Hatchback_01_F and driver
//will wait for 30 seconds if there is a player within 10 meters of a waypoint
//nul = [] execvm "busStop.sqf"


_transportWPMarkers = [ _this, 0, "busStop", [ [], "" ] ] call BIS_fnc_param;
_transportVehicleType = [ _this, 1, "C_Hatchback_01_F", [ "" ] ] call BIS_fnc_param;
_waitPeriod = [ _this, 2, 30, [ 0 ] ] call BIS_fnc_param;
_stopRadius = [ _this, 3, 10, [ 0 ] ] call BIS_fnc_param;
_busSpawn = [ _this, 4, "", [ [], "" ] ] call BIS_fnc_param;

switch ( true ) do {

//Have we supplied an array of markers
case ( typeName _transportWPMarkers == typeName [] ) : {
	//Check markers for errors
	{
		//If not a valid marker
		if ( getMarkerPos _x isEqualTo [ 0, 0, 0 ] ) then {
			//Display error
			[ "Supplied marker <%1> is invalid", _x ] call BIS_fnc_error;
		};
	}forEach _transportWPMarkers;
};

//Have we supplied a base name for markers
case ( typeName _transportWPMarkers == typeName "" ) : {
	//Get all markers
	_markers = allMapMarkers;
	//Add underscore to base name
	_baseName = _transportWPMarkers + "_";
	//Get length of base name
	_baseNameLength = ( count _baseName );
	_transportWPMarkers = [];
	//Check each marker
	{
		//Get marker name
		_name = _x;
		//does the marker start with base name
		if ( _name select [ 0, _baseNameLength ] == _baseName ) then {
			//Add it to transport WPs
			_transportWPMarkers pushBack _name;
		};
	}forEach _markers;
	//Sort markers by suffix number
	_transportWPMarkers = [ _transportWPMarkers, [ _baseNameLength ], {
		parseNumber ( _x select [ _input0 + 1, ( count _x ) - 1 ] )
	} ] call BIS_fnc_sortBy;
};
};


//Was a spawn position not supplied
if ( _busSpawn == "" ) then {
//Set spawn position at first WP
_busSpawn = getMarkerPos ( _transportWPMarkers select 0 );
}else{
//Is supplied spawn position a string ( marker )
if ( typeName _busSpawn == typeName "" ) then {
	//Is the marker invalid
	if ( getMarkerPos _busSpawn isEqualTo [ 0, 0, 0 ] ) then {
		//Throw error
		[ "Supplied spawn marker <%1> is invalid", _busSpawn ] call BIS_fnc_error;
	}else{
		//Get marker position
		_busSpawn = getMarkerPos _busSpawn;
	};
};
};

//Create vehicle and driver at first WP
_group = createGroup civilian;
_vehicle = createVehicle [ _transportVehicleType, _busSpawn , [], 0, "NONE" ];
_crew = [ _vehicle, _group ] call BIS_fnc_spawnCrew;


//for each marker
{
//Get marker position
_pos = getMarkerPos ( _transportWPMarkers select _forEachIndex ) ;

//Create WP
_wp = _group addWaypoint [ _pos, 0 ];
_wp setWaypointType "MOVE";
_wp setWaypointBehaviour "CARELESS";
_wp setWaypointCombatMode "BLUE";
_wp setWaypointCompletionRadius 0;

//If there is a player within _stopRadius of the WP OR we have a player onboard,  Wait at the waypoint for _waitPeriod seconds
_wp setWaypointStatements [ format[ "
	if ( isnil 'wpTimeout' ) then {
		wpTimeout = time + %1;
	};
	if ( { isPlayer _x }count ( %2 nearEntities [['Man'], %3 ] ) > 0 || { isplayer _x && alive _x }count ( crew ( vehicle this )) > 0 ) then {
		if ( time >= wpTimeout ) then {
			true
		}else{
			false
		};
	}else{
		true
	};
", _waitPeriod, _pos, _stopRadius ],
"wpTimeout = nil" ];

}forEach _transportWPMarkers;

//Create a last WP at the starting WP of CYCLE
_wp = _group addWaypoint [ getMarkerPos ( _transportWPMarkers select 0 ) , 0 ];
_wp setWaypointType "CYCLE";
_wp setWaypointCompletionRadius 0;

and TEST mission

Edited by Larrow

Share this post


Link to post
Share on other sites

woah.. u are the best guys, thanks

Here is my attempt

//[ markers, vehicleType, wait time, stop radius, spawn location ] execvm "busStop.sqf"
//Markers <ARRAY> or <STRING> - either an ARRAY of markers OR a base name STRING of markers to look for
//VehicleType <STRING> - a vehicle class name to spawn
//Wait Time <NUMBER> - time in seconds to wait at a waypoint
//Stop Radius <NUMBER> - distance in meters a player must be to a waypoint for the vehicle to Wait, will also wait if there is a player passenger
//Spawn Location <POSTION> or <STRING> - initial position to spawn vehicle at position or marker name, first WP used if not supplied

//example
//will look for markers named busStop_0 to busStop_#
//will create a C_Hatchback_01_F and driver
//will wait for 30 seconds if there is a player within 10 meters of a waypoint
//nul = [] execvm "busStop.sqf"


_transportWPMarkers = [ _this, 0, "busStop", [ [], "" ] ] call BIS_fnc_param;
_transportVehicleType = [ _this, 1, "C_Hatchback_01_F", [ "" ] ] call BIS_fnc_param;
_waitPeriod = [ _this, 2, 30, [ 0 ] ] call BIS_fnc_param;
_stopRadius = [ _this, 3, 10, [ 0 ] ] call BIS_fnc_param;
_busSpawn = [ _this, 4, "", [ [], "" ] ] call BIS_fnc_param;

switch ( true ) do {

//Have we supplied an array of markers
case ( typeName _transportWPMarkers == typeName [] ) : {
	//Check markers for errors
	{
		//If not a valid marker
		if ( getMarkerPos _x isEqualTo [ 0, 0, 0 ] ) then {
			//Display error
			[ "Supplied marker <%1> is invalid", _x ] call BIS_fnc_error;
		};
	}forEach _transportWPMarkers;
};

//Have we supplied a base name for markers
case ( typeName _transportWPMarkers == typeName "" ) : {
	//Get all markers
	_markers = allMapMarkers;
	//Add underscore to base name
	_baseName = _transportWPMarkers + "_";
	//Get length of base name
	_baseNameLength = ( count _baseName );
	_transportWPMarkers = [];
	//Check each marker
	{
		//Get marker name
		_name = _x;
		//does the marker start with base name
		if ( _name select [ 0, _baseNameLength ] == _baseName ) then {
			//Add it to transport WPs
			_transportWPMarkers pushBack _name;
		};
	}forEach _markers;
	//Sort markers by suffix number
	_transportWPMarkers = [ _transportWPMarkers, [ _baseNameLength ], {
		parseNumber ( _x select [ _input0 + 1, ( count _x ) - 1 ] )
	} ] call BIS_fnc_sortBy;
};
};


//Was a spawn position not supplied
if ( _busSpawn == "" ) then {
//Set spawn position at first WP
_busSpawn = getMarkerPos ( _transportWPMarkers select 0 );
}else{
//Is supplied spawn position a string ( marker )
if ( typeName _busSpawn == typeName "" ) then {
	//Is the marker invalid
	if ( getMarkerPos _busSpawn isEqualTo [ 0, 0, 0 ] ) then {
		//Throw error
		[ "Supplied spawn marker <%1> is invalid", _busSpawn ] call BIS_fnc_error;
	}else{
		//Get marker position
		_busSpawn = getMarkerPos _busSpawn;
	};
};
};

//Create vehicle and driver at first WP
_group = createGroup civilian;
_vehicle = createVehicle [ _transportVehicleType, _busSpawn , [], 0, "NONE" ];
_crew = [ _vehicle, _group ] call BIS_fnc_spawnCrew;


//for each marker
{
//Get marker position
_pos = getMarkerPos ( _transportWPMarkers select _forEachIndex ) ;

//Create WP
_wp = _group addWaypoint [ _pos, 0 ];
_wp setWaypointType "MOVE";
_wp setWaypointBehaviour "CARELESS";
_wp setWaypointCombatMode "BLUE";
_wp setWaypointCompletionRadius 0;

//If there is a player within _stopRadius of the WP OR we have a player onboard,  Wait at the waypoint for _waitPeriod seconds
_wp setWaypointStatements [ format[ "
	if ( isnil 'wpTimeout' ) then {
		wpTimeout = time + %1;
	};
	if ( { isPlayer _x }count ( %2 nearEntities [['Man'], %3 ] ) > 0 || { isplayer _x && alive _x }count ( crew ( vehicle this )) > 0 ) then {
		if ( time >= wpTimeout ) then {
			true
		}else{
			false
		};
	}else{
		true
	};
", _waitPeriod, _pos, _stopRadius ],
"wpTimeout = nil" ];

}forEach _transportWPMarkers;

//Create a last WP at the starting WP of CYCLE
_wp = _group addWaypoint [ getMarkerPos ( _transportWPMarkers select 0 ) , 0 ];
_wp setWaypointType "CYCLE";
_wp setWaypointCompletionRadius 0;

and TEST mission

i take a try at your test mission, its exactly what im looking for, but when i port it to my mission, the car dont stop in any waypoint.

and how can i lock the driver seat? because i can jump to driver seat even when the car is in movement.

Share this post


Link to post
Share on other sites

Sorry taken a while to get back to you...

but when i port it to my mission, the car dont stop in any waypoint.

Can you tell me how you have set it up? marker names and how you are starting the script.

There is a slight error in the script when sorting the markers.

		//Sort markers by suffix number
	_transportWPMarkers = [ _transportWPMarkers, [ _baseNameLength ], {
		parseNumber ( _x select [ [color="#00FF00"]_input0, 4[/color] ] )
	} ] call BIS_fnc_sortBy;

Change this part of the script to look like the above.

how can i lock the driver seat? because i can jump to driver seat even when the car is in movement.

Mmm i cant in the test mission, I even set it up on Stratis to check and i cant

Maybe lock the drivers position once the vehicle is created, something like...

//Create vehicle and driver
_group = createGroup civilian;
_vehicle = createVehicle [ _transportVehicleType, _busSpawn , [], 0, "NONE" ];
_crew = [ _vehicle, _group ] call BIS_fnc_spawnCrew;
waitUntil { !isNull ( driver _vehicle ) };
_vehicle lockDriver true;

Edited by Larrow

Share this post


Link to post
Share on other sites

np man, take your time..

there is no rush :D

now i ported from your test mission and works perfectly :cool:

this solved the change seat stuff.. thanks

//Create vehicle and driver

_group = createGroup civilian;

_vehicle = createVehicle [ _transportVehicleType, _busSpawn , [], 0, "NONE" ];

_crew = [ _vehicle, _group ] call BIS_fnc_spawnCrew;

waitUntil { !isNull ( driver _vehicle ) };

_vehicle lockDriver true;

im having troble with the car maneuvering inside towns, they hit buildings sometimes and at the end of the line it also stuck if there is any building or wall near..

how can i add non stop waypoints? i think its a way to solve those problems and also a needed thing to make curves safer

im also trying to spawn multiple cars but have no success yet..

thanks

Share this post


Link to post
Share on other sites

Just logged in to reply.

If this script is important then I'd suggest to abandon the idea. Even with performance-costly AI driving mods, the driving is still unstable and unreliable. With vanilla, it will cause only headache in MP :)

If I was thinking only for myself, I would say to keep trying, only because down the line I may learn something from your efforts.

But I am also thinking of your sanity, so I suggest to ensure that any AI driving in your scenario is novelty-only and functionally unimportant.

To put it mildly, AI drivers will (1.40) ram into anything and everything, especially near intersections and when in danger.

Share this post


Link to post
Share on other sites
im having troble with the car maneuvering inside towns, they hit buildings sometimes and at the end of the line it also stuck if there is any building or wall near..
I have to agree with MDCCLXXVI on this. AI driving is terrible and if it is an important part of your mission ( how players are going to get to your side missions) then considering another method maybe better for your health :D.
i think its a way to solve those problems and also a needed thing to make curves safer
By curves do you mean your are micro managing your routes via waypoints? In my limited testing i found doing this made AI driving even worse and they were best left in general to work it out for themselves. BUT AI driving is again terrible.
how can i add non stop waypoints?
Could maybe add a text field to the marker, as long as its a EmptyIcon type then the text will not show on the map in game, say a text field of "noStop" and then wrap the waypointStatement part of the script in an If statement , e..g...

	[color="#00FF00"]if ( markerText ( _transportWPMarkers select _forEachIndex ) != "noStop" ) then {[/color]

	//If there is a player within _stopRadius of the WP OR we have a player onboard,  Wait at the waypoint for _waitPeriod seconds
	_wp setWaypointStatements [ format[ "
		if ( isnil 'wpTimeout' ) then {
			wpTimeout = time + %1;
		};
		if ( { isPlayer _x }count ( %2 nearEntities [['Man'], %3 ] ) > 0 || { isplayer _x && alive _x }count ( crew ( vehicle this )) > 0 ) then {
			if ( time >= wpTimeout ) then {
				true
			 }else{
				false
			 };
		}else{
			true
		};
	", _waitPeriod, _pos, _stopRadius ],
	"wpTimeout = nil" ]; 

[color="#00FF00"]};[/color]

Untested

So it sets the marker as a waypoint to go to in the code previous to this, but if the marker has noStop in the text field it does not add the statement (which holds the code for waiting).

Edited by Larrow

Share this post


Link to post
Share on other sites

And a cute .gif by Genesis92x sums it up:

https://dl.dropboxusercontent.com/u/38334795/BIAI.gif (1343 kB)

The issue from my understanding is that the integrated AI driving FSM from BIS, does a nearEntities scan of the route in front of it, for potential collisions. Many objects, such as those depicted on the road in the video in this thread ( http://forums.bistudio.com/showthread.php?187450-VCOM-AI-Driving-Mod ) are not detected in a nearEntities scan, so the AI does not try to avoid them.

Also for larger objects like houses, the AI references the center of the model, which could be 5-10 meters from the edge of the model. So the AI thinks it is going around by giving the house 3-4 meters space, when in reality it is colliding with the wall.

The situation is even more glum when less-simulated objects like trees, rocks, and most walls are thrown in. The AI quite simply does not see them in time to react, or even in combat may treat them as an infantry unit treats them, as an object to hide behind. So in combat / danger, you may even see AI drivers zoom into walls/rocks/trees, using them as infantry would use them; for cover. Of course the fragile vehicles do not take this well, and you may find your vehicles are missing wheels/tires after only a short time.

Of course we cannot actually see the code, to see how it actually is, so the above is just speculation from what I have observed.

What Genesis92x did in his AI driving script, was create and attach small objects to the corners of all the models near the vehicle as it is moving. The AI detects these small objects with no problem, and so it can more easily see the true outline/size of an obstruction, rather than relying on a single data point in the center of the model, if the model is even detected in the driving scan at all.

Edited by MDCCLXXVI

Share this post


Link to post
Share on other sites

Heh was having a mess around with this today, Agia Marina Bus Route, lol. Very rough just messing around.

Share this post


Link to post
Share on other sites

well im using a heli taxi script called by radio to go to side missions and its working fine, about the bus script.. some friends have interest on this script, so ill keep trying .. thanks a lot for your help :)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×