using GTA;
using System;
using System.IO;
using System.Windows.Forms;
using GTA.Native;
using GTA.Math;

public class MaskAlwaysOn : Script
{
    private Prop mask;
	private Prop belt;
	private Prop armor;
    private bool maskOn = false;
	private bool beltOn = false;
	private bool armorOn = false;
	
    public MaskAlwaysOn()
    {
        KeyUp += OnKeyUp;
    }

	
    void OnKeyUp(object sender, KeyEventArgs e)
    {
        Ped playerPed = Game.Player.Character;
		//Mask On/Off for one-player mode
        if (e.KeyCode == Keys.NumPad7)
        {
            if (maskOn)
            {
                if (mask != null)
                {
                    mask.Detach();
                    mask.Delete();
                }
                maskOn = false;
            }
            else
            {
                mask = World.CreateProp(new Model("prop_welding_mask_01"), Vector3.Zero, false, false);
                mask.FreezePosition = true;
                mask.IsInvincible = true;
                Function.Call(Hash.SET_ENTITY_PROOFS, mask, true, true, true, true, true, true, true, true);
                mask.AttachTo(playerPed, Function.Call<int>(Hash.GET_PED_BONE_INDEX, playerPed.Handle, Bone.FACIAL_facialRoot.GetHashCode()), new Vector3(0, .1f, 0), new Vector3(90 * 3, 0, 0));
                maskOn = true;
            }
        }
		//Mask on/off for online or NPC character skin
		if (e.KeyCode == Keys.NumPad9)
        {
            if (maskOn)
            {
                if (mask != null)
                {
                    mask.Detach();
                    mask.Delete();
                }
                maskOn = false;
            }
            else
            {
                mask = World.CreateProp(new Model("prop_welding_mask_01"), Vector3.Zero, false, false);
                mask.FreezePosition = true;
                mask.IsInvincible = true;
                Function.Call(Hash.SET_ENTITY_PROOFS, mask, true, true, true, true, true, true, true, true);
                mask.AttachTo(playerPed, Function.Call<int>(Hash.GET_PED_BONE_INDEX, playerPed.Handle, Bone.FACIAL_facialRoot.GetHashCode()), new Vector3(.1f, .001f, 0), new Vector3(90 * 2, 90, 0));
                maskOn = true;
            }
        }
		//Belt AND armor on/off
		if (e.KeyCode == Keys.NumPad1)
        {
            if (beltOn)
            {
                if (belt != null)
                {
                    belt.Detach();
                    belt.Delete();
					armor.Detach();
                    armor.Delete();
                }
                beltOn = false;
				armorOn = false;
            }
            else
            {
                belt = World.CreateProp(new Model("prop_weld_torch"), Vector3.Zero, false, false);
                belt.FreezePosition = true;
                belt.IsInvincible = true;
                Function.Call(Hash.SET_ENTITY_PROOFS, belt, true, true, true, true, true, true, true, true);
                belt.AttachTo(playerPed, Function.Call<int>(Hash.GET_PED_BONE_INDEX, playerPed.Handle, Bone.SKEL_Pelvis.GetHashCode()), new Vector3(0, .15f, 0), new Vector3(90 * 3, 0, 0));
                beltOn = true;
				armor = World.CreateProp(new Model("prop_glasscutter_01"), Vector3.Zero, false, false);
                armor.FreezePosition = true;
                armor.IsInvincible = true;
                Function.Call(Hash.SET_ENTITY_PROOFS, armor, true, true, true, true, true, true, true, true);
                armor.AttachTo(playerPed, Function.Call<int>(Hash.GET_PED_BONE_INDEX, playerPed.Handle, Bone.SKEL_Spine3.GetHashCode()), new Vector3(.1f, .1f, 0), new Vector3(90 * 2, 90, 0));
				armorOn = true;
            }
        }
		//Mask AND BELT AND ARMOR on/off for online or NPC character skin
		if (e.KeyCode == Keys.NumPad3)
        {
            if (beltOn)
            {
                if (belt != null)
                {
                    belt.Detach();
                    belt.Delete();
                }
                beltOn = false;
            }
			if (maskOn)
            {
                if (mask != null)
                {
					mask.Detach();
                    mask.Delete();
                }
				maskOn = false;
            }
			if (armorOn)
            {
                if (armor != null)
                {
					armor.Detach();
                    armor.Delete();
                }
				armorOn = false;
            }
            else
            {
                belt = World.CreateProp(new Model("prop_weld_torch"), Vector3.Zero, false, false);
                belt.FreezePosition = true;
                belt.IsInvincible = true;
                Function.Call(Hash.SET_ENTITY_PROOFS, belt, true, true, true, true, true, true, true, true);
                belt.AttachTo(playerPed, Function.Call<int>(Hash.GET_PED_BONE_INDEX, playerPed.Handle, Bone.SKEL_Pelvis.GetHashCode()), new Vector3(0, .15f, 0), new Vector3(90 * 3, 0, 0));
                beltOn = true;
				mask = World.CreateProp(new Model("prop_welding_mask_01"), Vector3.Zero, false, false);
                mask.FreezePosition = true;
                mask.IsInvincible = true;
                Function.Call(Hash.SET_ENTITY_PROOFS, mask, true, true, true, true, true, true, true, true);
                mask.AttachTo(playerPed, Function.Call<int>(Hash.GET_PED_BONE_INDEX, playerPed.Handle, Bone.FACIAL_facialRoot.GetHashCode()), new Vector3(.1f, .001f, 0), new Vector3(90 * 2, 90, 0));
                maskOn = true;
				armor = World.CreateProp(new Model("prop_glasscutter_01"), Vector3.Zero, false, false);
                armor.FreezePosition = true;
                armor.IsInvincible = true;
                Function.Call(Hash.SET_ENTITY_PROOFS, armor, true, true, true, true, true, true, true, true);
                armor.AttachTo(playerPed, Function.Call<int>(Hash.GET_PED_BONE_INDEX, playerPed.Handle, Bone.SKEL_Spine3.GetHashCode()), new Vector3(.1f, .1f, 0), new Vector3(90 * 2, 90, 0));
				armorOn = true;
            }
        }
    }
}