Page 1 of 1

How do I apply a modifier to a player in-game?

Posted: Mon Dec 03, 2018 5:51 pm
by Ol1vver
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.

Re: How do I apply a modifier to a player in-game?

Posted: Mon Dec 03, 2018 6:16 pm
by Shark

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);
}


Other modifiers here
► Show Spoiler

Re: How do I apply a modifier to a player in-game?

Posted: Mon Dec 03, 2018 6:25 pm
by Sree
Shark wrote:
Mon Dec 03, 2018 6:16 pm

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);
}


You just need to set those modifiers once.

Re: How do I apply a modifier to a player in-game?

Posted: Mon Dec 03, 2018 6:38 pm
by Ol1vver
Shark wrote:
Mon Dec 03, 2018 6:16 pm

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);
}


Other modifiers here
► Show Spoiler
I was talking about ready modifiers, and not creating them.

Edit: Nevermind, thank you! But still, have ready modifiers and apply them to players is easier.

Re: How do I apply a modifier to a player in-game?

Posted: Tue Dec 04, 2018 2:42 pm
by Motto73
@@Ol1vver To set existing player modifiers to a player use this script:

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());
		}
	}
}
Then make your AreaTrigger and PlayerModifierInfo and name them [NAME] and [NAME]MOD, like in the following pictures:
Image
Image
(You can sert the ApplyModifiers to On Enter, On Exit or Script method, which works on both)