Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

Need help to make a script... again

Here you can find answered ScriptAPI topics.
Forum rules
By using the forum you agree to the following rules.
Post Reply
Mr Argon
Fighter
Fighter
Posts: 14
Joined: Sat Mar 09, 2019 2:22 am
SFD Account: LeoniiiXD (steam)
SFD Alias: Mr. Argon
Started SFD: Pre-Alpha 1.8.2c
Location: Argentina
Gender:
Age: 15
Contact:

Need help to make a script... again

Post by Mr Argon » Fri Apr 05, 2019 4:41 am

Well... I'm making a survival map in wich you have to protect an AI controlled bot, a doctor who is working while you fight against enemies...

It has two behaviors, one for "working" wich is actually a loop of player commands that makes him go back an forth throught a room, and the second behavior is for fighting enemies. I use an AreaTrigger to detect when an enemy gets inside the room and it enables input for the doctor and clears his command queue.

The problem here is that I can't manage to get the first behavior triggered again when the room is clear and no alive enemies are inside.

This is my script, tell me if you need screenshots or something else.
//=========================
// SCRIPT REGISTER OBJECTS
//=========================

private IPlayer p_doctor = null;

// DOCTOR SPAWN
//===================

public void DocSpawn(TriggerArgs args)
{
	p_doctor = (args as CreateTriggerArgs).CreatedObject as IPlayer;
}

// DOCTOR STARTS WORKING
//===================

public void StartWorkingLoop(TriggerArgs args)
{
	IObjectTrigger WorkLoopTrigger = (Game.GetSingleObjectByCustomID("StartWorkingLoopTrigger")as IObjectTrigger);
	{
		p_doctor.SetInputEnabled(false);
		WorkLoopTrigger.Trigger();
	}
}

// DOCTOR ALERTS NEARBY ENEMIES
//====================

public void DoctorEnterFightMode(TriggerArgs args)
{
	IObjectTrigger DoctorSpeechAlert = (Game.GetSingleObjectByCustomID("DoctorAlertSpeechTrigger")as IObjectTrigger);
	IObjectTrigger CheckDoctorLifeLoop = (Game.GetSingleObjectByCustomID("CheckLifeLoopTimer")as IObjectTrigger);
	{
		if (!p_doctor.IsDead && !p_doctor.IsInputEnabled)
			{
				p_doctor.SetInputEnabled(true);
				DoctorSpeechAlert.Trigger();
				CheckDoctorLifeLoop.Trigger();
			}
	}
}

// DOCTOR NEEDS HELP DURING FIGHT
//====================

public void CheckDoctorLife(TriggerArgs args)
{
	IObjectTrigger DoctorSpeechHelp = (Game.GetSingleObjectByCustomID("DoctorHelpSpeechTrigger")as IObjectTrigger);
	IObjectTrigger CheckDoctorLifeLoop = (Game.GetSingleObjectByCustomID("CheckLifeLoopTimer")as IObjectTrigger);
	{
		if (!p_doctor.IsDead && p_doctor.IsInputEnabled && p_doctor.GetHealth() <= 60)
		{
			DoctorSpeechHelp.Trigger();
			CheckDoctorLifeLoop.SetEnabled(false);
		}
	}
}

// ENEMIES TRIGGER DOCTOR FIGHT MODE
//====================

public void CheckEntrance(TriggerArgs args)
{
	IObjectTrigger DoctorFightTrigger = (Game.GetSingleObjectByCustomID("DoctorFightTrigger")as IObjectTrigger);
	{
		if ((args.Sender is IPlayer) && ((IPlayer)args.Sender).GetTeam() == PlayerTeam.Team2 && !((IPlayer)args.Sender).IsDead)
			{
				DoctorFightTrigger.Trigger();
			}
	}
}
1 x

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 478
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 20

Post by JakSparro98 » Fri Apr 05, 2019 12:04 pm

@Mr Argon You also need to provide the setup map of the bot (if you don't want to publish the final map itself), with relative triggers and command connections, I tried to guess what the original setup was with their triggers and timers but it seems I cannot replicate the behavior.
0 x

Mr Argon
Fighter
Fighter
Posts: 14
Joined: Sat Mar 09, 2019 2:22 am
SFD Account: LeoniiiXD (steam)
SFD Alias: Mr. Argon
Started SFD: Pre-Alpha 1.8.2c
Location: Argentina
Gender:
Age: 15
Contact:

Post by Mr Argon » Sat Apr 06, 2019 12:24 am

Here´s the template map I'm using.

https://mega.nz/#!cl1kBQSC!t2INwXtJeE06 ... b-vJ7GlWXU
0 x

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 478
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 20

Post by JakSparro98 » Sat Apr 06, 2019 2:05 am

Mr Argon wrote:
Sat Apr 06, 2019 12:24 am
Here´s the template map I'm using.

https://mega.nz/#!cl1kBQSC!t2INwXtJeE06 ... b-vJ7GlWXU
thanks, I've added some code to count alive enemies inside the area, I've added a list and a timer to loop this check and if there are no alive enemies inside that list StartWorkingLoop will be called, on map startup you will still need to call it from another trigger, since the timer will only call the method if there were enemies that entered the area and then they died.

Here is the updated template map, let me know if it was what you wanted.
2 x

Mr Argon
Fighter
Fighter
Posts: 14
Joined: Sat Mar 09, 2019 2:22 am
SFD Account: LeoniiiXD (steam)
SFD Alias: Mr. Argon
Started SFD: Pre-Alpha 1.8.2c
Location: Argentina
Gender:
Age: 15
Contact:

Post by Mr Argon » Sat Apr 06, 2019 2:15 am

It's just what I need, thank you very much! The only things that keeps annoying me is that I actually don't understand the new script, but I think it's only about learning more about c# and making more maps.
0 x

Post Reply