//----------------------------//
//     Skryim Shout v0.4      //
//           by               //
//        bdking00            //
//----------------------------//
using GTA;
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using GTA.Native;
using GTA.Math;

public class Skyrim_Shout : Script
{
    int shout_strength;

    int shout_radius;

    string soundLoc;

    private ScriptSettings config;

    public Skyrim_Shout()
    {
        config = ScriptSettings.Load("scripts\\skyrim_shout.ini");


        Tick += OnTick;
        KeyDown += OnKeyDown;
        KeyUp += OnKeyUp;

        Interval = 10;

        soundLoc = config.GetValue<string>("Sound", "SoundLoc", "");
        shout_strength = config.GetValue<int>("Strength", "ShoutStrength", 100);
        shout_radius = config.GetValue<int>("Radius", "ShoutRadius", 100);
    }
    void OnTick(object sender, EventArgs e)
    {
    }

    void OnKeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Add && e.KeyCode == Keys.F6 && shout_strength <= 2000)
        {
            shout_strength = shout_strength + 1;
            GTA.UI.ShowSubtitle("Shout Strength is now " + shout_strength.ToString());
        }
        else
        {
            shout_strength = 2000;
        }
        if (e.KeyCode == Keys.Subtract && e.KeyCode == Keys.F5 && shout_strength >= 10)
        {
            shout_strength = shout_strength - 1;
            GTA.UI.ShowSubtitle("Shout Strength is now " + shout_strength.ToString());
        }
        else
        {
            shout_strength = 10;
        }
    }

    void DeletePEDArray(Ped[] pedObj)
    {
        for (int i = 0; i < pedObj.Length; i++)
        {
            pedObj[i] = null;
        }
        pedObj = null;
    }

    void DeleteVEHArray(Vehicle[] vObj)
    {
        for (int i = 0; i < vObj.Length; i++)
        {
            vObj[i] = null;
        }
        vObj = null;
    }

    void OnKeyUp(object sender, KeyEventArgs e)
    {
        Ped player = Game.Player.Character;

        Ped[] ped = World.GetNearbyPeds(player, shout_radius);

        Vehicle[] veh = World.GetNearbyVehicles(player, shout_radius);

        if (e.KeyCode == Keys.Delete)
        {
            System.Media.SoundPlayer plyr = new System.Media.SoundPlayer(@soundLoc);
            plyr.Play();

            Wait(1000);

            for (int i = 0; i < ped.Length; i++)
            {
                shoutPed(player, ped[i]);
            }
            for (int i = 0; i < veh.Length; i++)
            {
                shoutVeh(player, veh[i]);
            }
            DeletePEDArray(ped);
            DeleteVEHArray(veh);

        }
    }

    void shoutPed(Ped Player, Ped ped)
    {
        Function.Call(Hash.SET_PED_TO_RAGDOLL, ped, 8000, 8000, 0, 1, 1, 1);
        ped.Velocity.Equals(shout_strength);
        ped.ApplyForce(Player.ForwardVector * shout_strength);
    }

    void shoutVeh(Ped player, Vehicle veh)
    {
        float vehStrength = shout_strength - 10;
        veh.ApplyForce(player.ForwardVector * vehStrength);
    }
}