Jump to content
trader5050

Can't seem to access game objects properly?

Recommended Posts

Hello,

I'm trying to expand upon the Miami Mod patrol capability by having units self-direct to incidents. The problem is that I can't seem to identify anything/anyone.

I'm trying:

		GameObjectList list = Game::GetGameObjects();
		for(int i=0; i<list.GetNumObjects(); i++)
		{
			GameObject obj = list.GetObject(i);
						
			/* cars */
			if (obj.GetType()==TYPE_VEHICLE) {
			
				
			
			}
			
			/* people */
			if (obj.GetType()==TYPE_PERSON) {
				
				/* injured? */
				Person prsn(&obj);
				
				if (prsn.IsInjured() || prsn.IsComatose()) {
					Mission::PlayHint("Found an injured person!");
					somethingToDo=true;
				}
				
			}
			
			/* start chase */
			if (somethingToDo) {
				Mission::PlayHint("Found a rescue activity!");
				sendRescue(v,obj);
				break;
			}
			
		}

I was also checking for gangsters, etc., but nothing ever triggers. Any help is appreciated!

Link to comment
Share on other sites

1 hour ago, trader5050 said:

 

You need to have that piece of code repeat every second or so in order for the game to actually detect things that AI can auto-dispatch to. With that in mind, the script must also be smart enough to know that the function for dispatching only needs to execute once and never again, and the vehicle itself can be interrupted by user input. 

I don't recommend using the full GetGameObjects list as it lags the game out when run at a constant pace.

Other issues you may come across is effectively parking the unit once on scene, and considerations like "what if the gate at the station is closed" or "what if this vehicle AI pathfinding gets stuck"

Link to comment
Share on other sites

4 hours ago, trader5050 said:

Is there anything I can force to run every second?

Only thing I can think of atm is force deploying an invisible object that runs in a loop with a 1 second sleep.

This is it actually, the only way to do anything on a repeat basis.

Repeat/recursion scripts are known to lag the game badly as explained. Be sure to tread carefully from this point forward.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...