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.

Is to possible to change TriggerArgs?

Share questions, scripts and tutorials related to the ScriptAPI in SFD.
Forum rules
By using the forum you agree to the following rules.
Post Reply
pillers
Meatbag
Posts: 3
Joined: Sun Dec 02, 2018 10:11 am

Is to possible to change TriggerArgs?

Post by pillers » Mon Dec 03, 2018 4:28 am

Hello, I am new to map making and I need some help with my script. firstly let me preface my issue by explaining what I want to happen. Image
Suppose a player pushes the button in the image above, the button will then activate the TimerTrigger on the left side of the image. The TimerTrigger calls the script method that controls the M60 to aim at the nearest player. Consequently however the nearest player will most likely be the player that just pushed the button, and that's not good. So my BIG question is how can I tell the game not to target the player that has pushed the button? I figured that their must be some way to get the args.Sender data from the button's TriggerArgs and push it into the TimerTrigger's TriggerArgs. I don't know maybe I'm going about this the wrong way hopefully the smart people in this forum could help me out.
0 x

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

Post by JakSparro98 » Wed Dec 05, 2018 12:07 am

pillers wrote:
Mon Dec 03, 2018 4:28 am
Hello, I am new to map making and I need some help with my script. firstly let me preface my issue by explaining what I want to happen. Image
Suppose a player pushes the button in the image above, the button will then activate the TimerTrigger on the left side of the image. The TimerTrigger calls the script method that controls the M60 to aim at the nearest player. Consequently however the nearest player will most likely be the player that just pushed the button, and that's not good. So my BIG question is how can I tell the game not to target the player that has pushed the button? I figured that their must be some way to get the args.Sender data from the button's TriggerArgs and push it into the TimerTrigger's TriggerArgs. I don't know maybe I'm going about this the wrong way hopefully the smart people in this forum could help me out.
You just need to exclude the player that is inside the arg.sender when it comes to find the nearest player from the helicopter, as you already said yourself, would you please share the code you currently use to control the weapon aiming to adapt the modification directly on it?
2 x

pillers
Meatbag
Posts: 3
Joined: Sun Dec 02, 2018 10:11 am

Post by pillers » Wed Dec 05, 2018 12:57 am

Code: Select all

public void LookAt(IObject target)
{
	if(target == null) 
	{	
		return;
	}
	IObjectFaceAtObject trigger = (IObjectFaceAtObject)Game.GetFirstObject("FaceAtTrigger");
	if(trigger != null)
	{
		trigger.SetTargetObject(target);
	}
	return;
}

public void Turret(TriggerArgs args)
{
		IObject turret = (IObject)Game.GetFirstObject("M60T");
		IObjectFaceAtObject trigger = (IObjectFaceAtObject)Game.GetFirstObject("FaceAtTrigger");
		IPlayer[] players = (from Q in Game.GetPlayers() where Q != null && !Q.IsDead && Q.GetWorldPosition().Y < turret.GetWorldPosition().Y select Q).ToArray();
		if(players != null && players.Length > 0) 
		{
			LookAt(players[RANDOM.Next(0, players.Length)]);
			Game.SpawnProjectile(ProjectileItem.M60, turret.GetWorldPosition(), new Vector2((float)Math.Cos(turret.GetAngle()) , (float)Math.Sin(turret.GetAngle()) ) );
		}
}
currently I've set it to only look for players that are below the turret ideally I would like permanent immunity for the player that pushed the button from the turrets targeting.
0 x

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

Post by JakSparro98 » Thu Dec 06, 2018 1:55 pm

@pillers This is the code:

Code: Select all

IPlayer HeliPlayer;
public void LookAt(IObject target) {
 if (target == null) {
  return;
 }
 IObjectFaceAtObject trigger = (IObjectFaceAtObject) Game.GetFirstObject("FaceAtTrigger");
 if (trigger != null) {
  trigger.SetTargetObject(target);
 }
 return;
}
public void ButtonPressed(TriggerArgs arg) {
 if (arg.Sender != null)
  HeliPlayer = (IPlayer) arg.Sender;
}


public void Turret(TriggerArgs args) {
 IObject turret = (IObject) Game.GetFirstObject("M60T");
 IObjectFaceAtObject trigger = (IObjectFaceAtObject) Game.GetFirstObject("FaceAtTrigger");
 IPlayer[] players = (from Q in Game.GetPlayers() where Q != null && Q.UniqueID != HeliPlayer.UniqueID && !Q.IsDead && Q.GetWorldPosition().Y < turret.GetWorldPosition().Y select Q).ToArray();
 float MinDistance = float.MaxValue;
 IPlayer NearestPlayer = null;
 foreach(IPlayer plr in players)
 if (Math.Abs((plr.GetWorldPosition() - turret.GetWorldPosition()).Length()) < MinDistance) {
  NearestPlayer = plr;
  MinDistance = Math.Abs((plr.GetWorldPosition() - turret.GetWorldPosition()).Length());
 }

 if (NearestPlayer != null) {
  Game.SpawnProjectile(ProjectileItem.M60, turret.GetWorldPosition(), new Vector2((float) Math.Cos(turret.GetAngle()), (float) Math.Sin(turret.GetAngle())));
  LookAt(NearestPlayer);
  Game.ShowPopupMessage("" + MinDistance);
 }
}
You also need to set ButtonPressed as script method of the helicopter button in order to store the player that pushed the button (only one player per time can be stored).

Let me know if it is what you asked.
2 x

pillers
Meatbag
Posts: 3
Joined: Sun Dec 02, 2018 10:11 am

Post by pillers » Sun Dec 16, 2018 11:24 am

YES! thank you very much. I'm sorry I couldn't respond to you sooner I had finals I was studying for but again thank you. This could not work any better <3
0 x

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest