Quantcast

Jump to content

» «
Photo

{C++} Exclude Player From Loop In an Array

2 replies to this topic
motorsport71
  • motorsport71

    newbie modder

  • Members
  • Joined: 20 Oct 2009

#1

Posted 2 weeks ago

So i am trying to build a script that excludes the player from the array. Now i took this straight out of Alexander Blade's Script Hook SDK and it does as it says but also includes the player. I am a noob when it comes to C++ and was hoping to get some advice on how to remove my player character.

Ped peds[ARR_SIZE];
	count = worldGetAllPeds(peds, ARR_SIZE);

	// randmoize peds
	if (pedUpdateTime + 200 < GetTickCount())
	{
		pedUpdateTime = GetTickCount();
		for (int i = 0; i < count; i++)
		{
			// if (rand() % 2 != 0) continue;
			if (peds[i] != playerPed && PED::IS_PED_HUMAN(peds[i]) && !ENTITY::IS_ENTITY_DEAD(peds[i]))
			{
				for (int component = 0; component < 12; component++)
				{
					if (rand() % 2 != 0) continue;
					for (int j = 0; j < 100; j++)
					{
						int drawable = rand() % 10;
						int texture = rand() % 10;
						if (PED::IS_PED_COMPONENT_VARIATION_VALID(peds[i], component, drawable, texture))
						{
							PED::SET_PED_COMPONENT_VARIATION(peds[i], component, drawable, texture, 0);
							break;
						}
					}
				}
			}
		}
	}

The script works perfect and i have it on a toggle. I just need to exclude the player. Anyone have any ideas?

 

Thanks

motorsport71


Jitnaught
  • Jitnaught

    Grass tastes bad

  • Members
  • Joined: 24 Aug 2013
  • United-States

#2

Posted 2 weeks ago Edited by Jitnaught, 2 weeks ago.

It looks like it's ignoring the player, judging by the "if (peds[i] != playerPed". Make sure that playerPed is set to PLAYER::PLAYER_PED_ID().


motorsport71
  • motorsport71

    newbie modder

  • Members
  • Joined: 20 Oct 2009

#3

Posted 2 weeks ago

Thanks man. Works correctly now





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users