Scripting 17 - Give/Remove player items

A smaller forum with a few tutorials how to get started with the ScriptAPI.
Forum rules
By using the forum you agree to the following rules.
Post Reply
User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1884
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 34

Scripting 17 - Give/Remove player items

Post by Gurt » Sun Aug 25, 2019 10:06 am

Scripting 17 - Give/Remove player items

Scripting in SFD assumes you have a fair knowledge of C#.

The following code demonstrates how to give a pistol and remove any katana from a player when the player push a button:

Code: Select all

public void ButtonPressed(TriggerArgs args)
{
	if (args.Sender is IPlayer) 
	{
		IPlayer plr = (IPlayer)args.Sender;
		if (plr.CurrentMeleeWeapon.WeaponItem == WeaponItem.KATANA) 
		{
			plr.RemoveWeaponItemType(WeaponItemType.Melee);
		}
		plr.GiveWeaponItem(WeaponItem.PISTOL);
	}
}
2 x
Gurt

Post Reply