Hello,
I need a script that applies a modifier to a player when touching an AreaTrigger.
Example:
I have an AreaTrigger. Upon entering, a modifier with Id: ThisMod applies (that slows down the player), and whenever he exits, a modifier with Id: ThatMod applies (that returns the player's original properties).
I know this is possible, but I'm not sure how.
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.
New to the forum? Say hello in this topic! Also make sure to read the rules.
How do I apply a modifier to a player in-game?
Forum rules
By using the forum you agree to the following rules.
By using the forum you agree to the following rules.
- Shark
- Superfighter
- Posts: 299
- Joined: Sat Mar 19, 2016 3:28 pm
- Title: The Predator
- SFD Alias: http://i.imgur.com/sQSmWvB.png
- Started SFD: 1.6.4
- Gender:
- Age: 23
Code: Select all
public void Slow(TriggerArgs args){
IPlayer player = (IPlayer)args.Sender;
PlayerModifiers modify = player.GetModifiers();
player.SetModifiers(modify);
modify.SprintSpeedModifier=0.5f;
player.SetModifiers(modify);
modify.RunSpeedModifier=0.5f;
player.SetModifiers(modify);
}
public void Normal(TriggerArgs args){
IPlayer player = (IPlayer)args.Sender;
PlayerModifiers modify = player.GetModifiers();
player.SetModifiers(modify);
modify.SprintSpeedModifier=-2;
player.SetModifiers(modify);
modify.RunSpeedModifier=-2;
player.SetModifiers(modify);
}
► Show Spoiler
0 x
Just me The Predator!
- Sree
- Superfighter
- Posts: 325
- Joined: Sun May 08, 2016 8:19 pm
- SFD Account: phasmic
- SFD Alias: sree
- Gender:
- Age: 23
You just need to set those modifiers once.Shark wrote: ↑Mon Dec 03, 2018 6:16 pmCode: Select all
public void Slow(TriggerArgs args){ IPlayer player = (IPlayer)args.Sender; PlayerModifiers modify = player.GetModifiers(); player.SetModifiers(modify); modify.SprintSpeedModifier=0.5f; player.SetModifiers(modify); modify.RunSpeedModifier=0.5f; player.SetModifiers(modify); } public void Normal(TriggerArgs args){ IPlayer player = (IPlayer)args.Sender; PlayerModifiers modify = player.GetModifiers(); player.SetModifiers(modify); modify.SprintSpeedModifier=-2; player.SetModifiers(modify); modify.RunSpeedModifier=-2; player.SetModifiers(modify); }
0 x
- Ol1vver
- Superfighter
- Posts: 69
- Joined: Mon Nov 19, 2018 4:55 pm
- SFD Account: olv
- SFD Alias: olv
- Started SFD: PreAlpha 1.6.4
- Gender:
I was talking about ready modifiers, and not creating them.Shark wrote: ↑Mon Dec 03, 2018 6:16 pmOther modifiers hereCode: Select all
public void Slow(TriggerArgs args){ IPlayer player = (IPlayer)args.Sender; PlayerModifiers modify = player.GetModifiers(); player.SetModifiers(modify); modify.SprintSpeedModifier=0.5f; player.SetModifiers(modify); modify.RunSpeedModifier=0.5f; player.SetModifiers(modify); } public void Normal(TriggerArgs args){ IPlayer player = (IPlayer)args.Sender; PlayerModifiers modify = player.GetModifiers(); player.SetModifiers(modify); modify.SprintSpeedModifier=-2; player.SetModifiers(modify); modify.RunSpeedModifier=-2; player.SetModifiers(modify); }
► Show Spoiler
Edit: Nevermind, thank you! But still, have ready modifiers and apply them to players is easier.
1 x
- Motto73
- Superfighter
- Posts: 316
- Joined: Mon May 09, 2016 7:35 am
- Title: Lazy ass
- SFD Account: Motto73
- Started SFD: Multiplayer Test Demo
- Location: Sunny City
- Gender:
- Age: 24
@@Ol1vver To set existing player modifiers to a player use this script:
Then make your AreaTrigger and PlayerModifierInfo and name them [NAME] and [NAME]MOD, like in the following pictures:
(You can sert the ApplyModifiers to On Enter, On Exit or Script method, which works on both)
Code: Select all
public void ApplyModifiers(TriggerArgs args)
{
if(args.Sender!=null && args.Sender is IPlayer)
{
string src=(args.Caller as IObject).CustomId+"MOD";
if(Game.GetSingleObjectByCustomId(src) != null)
{
var player = args.Sender as IPlayer;
var mods = Game.GetSingleObjectByCustomId(src) as IObjectPlayerModifierInfo;
(args.Sender as IPlayer).SetModifiers(mods.GetModifiers());
}
}
}
(You can sert the ApplyModifiers to On Enter, On Exit or Script method, which works on both)
2 x