Here you can find answered ScriptAPI topics.
-
pillers
- Meatbag
- Posts: 7
- Joined: Sun Dec 02, 2018 10:11 am
- Title: Deluxe Superfighter
- Age: 27
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.
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
-
JakSparro98
- Superfighter

- Posts: 530
- Joined: Fri Jul 15, 2016 7:56 pm
- Started SFD: PreAlpha 1.0.5
- Location: Rome, Italy
- Gender:
- Age: 27
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.
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: 7
- Joined: Sun Dec 02, 2018 10:11 am
- Title: Deluxe Superfighter
- Age: 27
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
-
JakSparro98
- Superfighter

- Posts: 530
- Joined: Fri Jul 15, 2016 7:56 pm
- Started SFD: PreAlpha 1.0.5
- Location: Rome, Italy
- Gender:
- Age: 27
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: 7
- Joined: Sun Dec 02, 2018 10:11 am
- Title: Deluxe Superfighter
- Age: 27
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