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.

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

Here you can find answered ScriptAPI topics.
Forum rules
By using the forum you agree to the following rules.
Post Reply
User avatar
Ol1vver
Superfighter
Superfighter
Posts: 69
Joined: Mon Nov 19, 2018 4:55 pm
SFD Account: olv
SFD Alias: olv
Started SFD: PreAlpha 1.6.4
Gender:

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

Post by Ol1vver » Mon Dec 03, 2018 5:51 pm

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.
0 x

User avatar
Shark
Superfighter
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

Post by Shark » 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
0 x
Just me The Predator!

User avatar
Sree
Superfighter
Superfighter
Posts: 325
Joined: Sun May 08, 2016 8:19 pm
SFD Account: phasmic
SFD Alias: sree
Gender:
Age: 23

Post by Sree » Mon Dec 03, 2018 6:25 pm

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.
0 x

User avatar
Ol1vver
Superfighter
Superfighter
Posts: 69
Joined: Mon Nov 19, 2018 4:55 pm
SFD Account: olv
SFD Alias: olv
Started SFD: PreAlpha 1.6.4
Gender:

Post by Ol1vver » Mon Dec 03, 2018 6:38 pm

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.
1 x

User avatar
Motto73
Superfighter
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

Post by Motto73 » Tue Dec 04, 2018 2:42 pm

@@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)
2 x
Image

Post Reply