Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » Find nearest vehicle?
Re: Find nearest vehicle? [message #446651 is a reply to message #446647] Sat, 07 May 2011 08:19 Go to previous messageGo to previous message
Omar007 is currently offline  Omar007
Messages: 1711
Registered: December 2007
Location: Amsterdam
Karma:
General (1 Star)
Something like this should do the trick. Thumbs Up

GameObject * getClosestVehicle(GameObject *sourceObject)
{
	GenericSLNode *x = SmartGameObjList->HeadNode;
	float closestDist = FLT_MAX;
	Vector3 sourceDist = Commands->Get_Position(sourceObject);
	GameObject *closestVeh = NULL;
	
	while (x)
	{
		GameObject *o = (GameObject *)x->NodeData;
		if (o && o != sourceObject && Is_Vehicle(o))
		{
			Vector3 TargetPos = Commands->Get_Position(o);
			float distance = Commands->Get_Distance(sourceDist, TargetPos);
			if (distance < closestDist)
			{
				closestDist = distance;
				closestVeh = o;
			}
		}
		x = x->NodeNext;
	}
	
	return closestVeh;
}


NOTE: This code might not be 100% because I wrote it down quickly in Notepad.


http://tiberiumredux.omarpakker.nl/Old Unused Parts/Plaatjes/PromoteBanner_Hades_small.jpg

[Updated on: Sun, 08 May 2011 13:00]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: attach vehicle
Next Topic: modifying weapons&ammos with serverside scripts.dll
Goto Forum:
  


Current Time: Mon Dec 23 13:55:02 MST 2024

Total time taken to generate the page: 0.00874 seconds