Jump to content
itchboy

Fire and Smoke Damage Script [Need Help]

Recommended Posts

After doing all those cars and trucks, I decided I should finally let this see the light of day.

Its a script that makes people not wearing oxygen tanks cough when an object is burning.

int DummyGroup = 29;object DummyFireCheck : CommandScript{	DummyFireCheck()	{	}	bool CheckTarget(GameObject *Caller, Actor *Target, int ChildID)	{	}	void PushActions(GameObject *Caller, Actor *Target, int childID)	{		GameObjectList gol1 = Game::GetGameObjects(TYPE_OBJECT);		for(int a = 0; a < gol1.GetNumObjects(); a++)		{			GameObject obj = gol1.GetObject(a);			obj.PushActionExecuteCommand(ACTION_APPEND, "DummyBurningCheck", &obj, 0, false);		}	}};object DummyBurningCheck : CommandScript{	DummyBurningCheck()	{		SetGroupID(DummyGroup);	}	bool CheckTarget(GameObject *Caller, Actor *Target, int ChildID)	{	}	void PushActions(GameObject *Caller, Actor *Target, int childID)	{		GameObject b(Caller);		if(b.IsBurning())		{			GameObjectList PersonInRange = b.GetObjectsInRange(200.f, ACTOR_PERSON);			for(int k = 0; k < PersonInRange.GetNumObjects(); k++)			{				bool IsSpecialFireFighter = false;				Person p(PersonInRange.GetObject(k));				if(p.GetPersonType() == PT_FIREFIGHTER_MASK)				{					IsSpecialFireFighter = true;				}				if(!IsSpecialFireFighter && !p.IsInjured())				{					p.Hurt(INJUREREASON_ENERGY, 10.f);					int random = Math::rand();					if (random % 4 == 0)					{						if (!p.IsPulling() && (p.IsIdle() || p.IsWaiting()))						{							p.PushActionInterruptAnim(ACTION_INSERT, "cough");							if (p.GetGender() == GENDER_MALE)								Audio::PlaySample3D("mod:Audio/FX/voices/man/0/contamination01.wav", p.GetPosition());							else if (p.GetGender() == GENDER_FEMALE)								Audio::PlaySample3D("mod:Audio/FX/voices/woman/0/contamination01.wav", p.GetPosition());							else if (p.GetGender() == GENDER_CHILD)								Audio::PlaySample3D("mod:Audio/FX/voices/child/0/contamination01.wav", p.GetPosition());						}					}				}				if (p.IsInjured())					p.SetBloodPuddle(false);			}		}		b.PushActionWait(ACTION_NEWLIST, 4.f);		b.PushActionExecuteCommand(ACTION_APPEND, "DummyBurningCheck", &b, 0, false);	}};

Now, my issue with this is that everytime the script is executed (it is intended to function as a loop), it causes massive lag. This is because EVERY object in the map has to be checked if it burns, and then the people need to react accordingly. I have tried adding a condition that only checks objects with FireObjects, but it makes little difference. The second major issue is that it only works on objects, not on houses, openhouses or vehicles.

Can any of the scripting masters help? Thanks.

Link to comment
Share on other sites

ERS Berlin has this (although its mission based) maybe check that out? I can't help you sorry..

They achieve that using a mission script. I made one for use in freeplay, which is based on a looped command script. Both of our scripts though are based from the smoke element of Mission 2.

Thanks for trying to help.

Link to comment
Share on other sites

I'm no expert on scripting at all, but perhaps instead of checking every object it can check if there are any particle effects active (eg smoke and/or flames)?

I tried this at first, but the game does not have a function to look for active particles. It only allows me to select any of the following in the for loop:

	TYPE_UNKNOWN,	TYPE_OBJECT,	TYPE_PERSON,	TYPE_HOUSE,	TYPE_VEHICLE,	TYPE_OPEN_HOUSE

I also tried this fucntion as an if condition: GetNumActiveFireChilds()

But it causes a script error because the function is intended to be uses in conjunction with an integer value.

Link to comment
Share on other sites

I have virtually no scripting experience in em4 outside of minor edits. That in mind, what about this?

(I'm assuming GetNumActiveFireChilds returns an integer as how many objects are burning)

If GetNumActiveFireChilds >0, then activate your script that finds them. That way you're only reading a number every loop unless there's an active burn.

Link to comment
Share on other sites

I have virtually no scripting experience in em4 outside of minor edits. That in mind, what about this?

If GetNumActiveFireChilds (I'm assuming returns an integer as how many objects are burning) >0, then activate your script that finds them. That way you're only reading a number every loop unless there's an active burn.

Good idea. That would definitely reduce the CPU strain, but I still have to figure out how to link GetNumActiveFireChilds() to each burning object and then link them to the people within range of the burning object so that the people will cough and take damage.

Still waiting on Hoppah or bma to give light to the situation.

Link to comment
Share on other sites

Fair point. I guess I assumed that was a base game variable.

Would it be good enough to just add the animation to the part of the script where people are injured by the fire? Or are you specifically looking to have uninjured people cough that aren't in the danger zone as well?

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...