Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » gameobject lists-> which&when
gameobject lists-> which&when [message #457023] Thu, 06 October 2011 17:34 Go to next message
robbyke is currently offline  robbyke
Messages: 348
Registered: September 2010
Location: Belgium
Karma: 0
Recruit
with the way with the object lists i cant find out wich to use.
my problem :

created object.
attached a script
find out if soldier is near object with attached script

that last step wont work ive tried out some lists but im doubting if i can still find my newly created object like this or maybe i first have to see under wich class its now divided


Owner of kambot TT server

kambot.freeforums.org
Re: gameobject lists-> which&when [message #457025 is a reply to message #457023] Thu, 06 October 2011 18:52 Go to previous messageGo to next message
Gen_Blacky is currently offline  Gen_Blacky
Messages: 3250
Registered: September 2006
Karma: 1
General (3 Stars)
This should work depending on what exactly you want to do. Just modify it to suit your needs. Like check to see if script is attached to what ever and set how far the player should be or whatever.


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);
	GameObject *object = 0;
	SLNode<BaseGameObj> *x = GameObjManager::GameObjList.Head();
	while (x)
	{
		GameObject *o = (GameObject *)x->Data();
		if (o && As_SoldierGameObj(o))
		{
			Vector3 player_pos = Commands->Get_Position(o);
			float dist = Commands->Get_Distance(player_pos,obj_pos);
			if (dist < closestdist)
			{
				closestdist = dist;
				object = o;
			}
		}
		x = x->Next();
	}
	return object;
}


http://s18.postimage.org/jc6qbn4k9/bricks3.png
Re: gameobject lists-> which&when [message #457061 is a reply to message #457025] Fri, 07 October 2011 06:32 Go to previous messageGo to next message
jonwil is currently offline  jonwil
Messages: 3557
Registered: February 2003
Karma: 0
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
Re: gameobject lists-> which&when [message #457081 is a reply to message #457023] Fri, 07 October 2011 10:58 Go to previous messageGo to next message
robbyke is currently offline  robbyke
Messages: 348
Registered: September 2010
Location: Belgium
Karma: 0
Recruit
i had to use the first one i had to check if there was an object nearby with a certain script attached ive found it now. i checked if my obj was a veh or a soldier and i shouldnt have done that

Owner of kambot TT server

kambot.freeforums.org
Re: gameobject lists-> which&when [message #457120 is a reply to message #457061] Fri, 07 October 2011 18:08 Go to previous message
Gen_Blacky is currently offline  Gen_Blacky
Messages: 3250
Registered: September 2006
Karma: 1
General (3 Stars)
jonwil wrote on Fri, 07 October 2011 06:32



The SmartGameObjList is for soldiers and vehicles and should be used in this case as you will have less objects to check.



Ah okay, So if I was looking for a building gameobject I would use BuildingGameObjList.


http://s18.postimage.org/jc6qbn4k9/bricks3.png
Previous Topic: C&C_Mangalia
Next Topic: chatcommand
Goto Forum:
  


Current Time: Mon Dec 02 23:06:30 MST 2024

Total time taken to generate the page: 0.00755 seconds