
#include "script.h"
#include <string>
#include <ctime>
#include "keyboard.h"

bool getKeyPressed(int key)
{
	return (GetAsyncKeyState(key) & 0xFFFF) == 0x8001;
}

void update()
{
	Ped playerPed = PLAYER::PLAYER_PED_ID();
	const int numElements = 10;
	const int arrSize = numElements * 2 + 2;  //Start at index 2, and the odd elements are padding
	Any peds[arrSize];
	//0 index is the size of the array
	peds[0] = numElements;

	int count = PED::GET_PED_NEARBY_PEDS(PLAYER::PLAYER_PED_ID(), peds, -1);

	for (int i = 0; i < count; ++i)
	{
		int offsettedID = i * 2 + 2;
		if (ENTITY::DOES_ENTITY_EXIST(peds[offsettedID]) && (GetAsyncKeyState(0X55)))
		{
			PED::SET_PED_CAN_RAGDOLL(peds[offsettedID], TRUE);
			PED::SET_PED_TO_RAGDOLL(peds[offsettedID], 0, 0, 0, TRUE, TRUE, TRUE);
			PED::SET_PED_CAN_RAGDOLL(playerPed, TRUE);
			PED::SET_PED_TO_RAGDOLL(playerPed, 0, 0, 0, TRUE, TRUE, TRUE);
		}
		else if (ENTITY::DOES_ENTITY_EXIST(peds[offsettedID]) && (GetAsyncKeyState(0x49)))
		{
			PED::SET_PED_CAN_RAGDOLL(peds[offsettedID], TRUE);
			PED::SET_PED_TO_RAGDOLL(peds[offsettedID], 0, 0, 0, TRUE, TRUE, TRUE);
		}
		else if (ENTITY::DOES_ENTITY_EXIST(peds[offsettedID]) && (GetAsyncKeyState(0x4F)))
		{
			PED::SET_PED_CAN_RAGDOLL(playerPed, TRUE);
			PED::SET_PED_TO_RAGDOLL(playerPed, 0, 0, 0, TRUE, TRUE, TRUE);
		}

	}
}
void main()
{
	while (true)
	{
		update();
		WAIT(0);
	}
}


void ScriptMain() {
	main();
}



