Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » gameobject lists-> which&when
Re: gameobject lists-> which&when [message #457061 is a reply to message #457025] Fri, 07 October 2011 06:32 Go to previous messageGo to previous message
jonwil is currently offline  jonwil
Messages: 3557
Registered: February 2003
Karma:
General (3 Stars)

This code will work better
#include "GameObjManager.h"
#include "SoldierGameObj.h"
GameObject *Get_Nearest_Solider(GameObject *obj) // Get the nearest solider next to a object
{
	float closestdist = FLT_MAX;
	Vector3 obj_pos = Commands->Get_Position(obj);
	SmartGameObj *object = 0;
	for (SLNode<SmartGameObj>* node = GameObjManager::SmartGameObjList.Head(); node; node = node->Next())
	{
		SmartGameObj* object = node->Data();
		if (o && o->As_SoldierGameObj())
		{
			Vector3 player_pos = Commands->Get_Position(o);
			float dist = Commands->Get_Distance(player_pos,obj_pos);
			if (dist < closestdist)
			{
				closestdist = dist;
				object = o;
			}
		}
	}
	return object;
}

That code will find the closest soldier to the passed in object.
The SmartGameObjList is for soldiers and vehicles and should be used in this case as you will have less objects to check.


Jonathan Wilson aka Jonwil
Creator and Lead Coder of the Custom scripts.dll
Renegade Engine Guru
Creator and Lead Coder of TT.DLL
Official member of Tiberian Technologies
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: C&C_Mangalia
Next Topic: chatcommand
Goto Forum:
  


Current Time: Sun Dec 01 15:47:53 MST 2024

Total time taken to generate the page: 0.00653 seconds