Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!   (92,919 visits to this link)

    2. News

    1. GTA Online

      1. Find Lobbies & Players
      2. Guides & Strategies
      3. Vehicles
      4. Content Creator
      5. Help & Support
    2. Crews

      1. Events
      2. Recruitment
    1. Grand Theft Auto Series

    2. GTA Next

    3. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    4. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    12. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption 2

    2. Red Dead Redemption

    3. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Forum Support

    2. Site Suggestions

Sign in to follow this  
GTBunny

worldGetAllPeds - applying single action to each Ped

Recommended Posts

GTBunny

Hi all,

 

I'm using worldGetAllPeds() to iterate through all current pedestrians ("duh"), but struggling to find a way to track individual peds within that pool.

 

My situation is that I want to be able to apply a force to each ped once, then leave them alone; however, if I apply an action to each Ped in the worldGetAllPeds() array, it happens every frame because I can't note that I've already done something to a Ped, so I need to be able to track each individual Ped and whether or not I've already 'touched' them. (For example, I want to apply a vertical force to each Ped just once, but it applies every frame, so they go f***ing nuts.)

 

Each Ped's ID within worldGetAllPeds() -- their position in the resulting array -- can be changed at any time, so can be different from one frame to another; in practice, they keep the same ID for seconds at a time, then it randomly changes, as shown in this video (ID changes from 8 to 7), using the code below:

 

/*THIS FILE IS A PART OF GTA V SCRIPT HOOK SDKhttp://dev-c.com© Alexander Blade 2015*/#include "script.h"#include "keyboard.h"#include <iostream>#include <string>#include <ctime>#include <vector>using namespace std;#pragma warning(disable : 4244 4305) // double <-> float conversionsstruct UniquePed{	int pool_id;	Ped ped;};// Adapted from message() by Luucky @ http://gtaforums.com/topic/803745-text-drawing/// Thanks!// Important: x, y = 0.0 to 1.0void DrawLabel(string label, float x, float y, float scale, bool centered = false){	char* text = (char *)label.c_str();	if (centered)	{		UI::SET_TEXT_CENTRE(true);	}	UI::_SET_TEXT_ENTRY("STRING");	UI::_ADD_TEXT_COMPONENT_STRING(text);	UI::SET_TEXT_FONT(0);	UI::SET_TEXT_SCALE(scale, scale);	UI::SET_TEXT_COLOUR(255, 255, 255, 255);	UI::SET_TEXT_WRAP(0.0, 1.0);	UI::SET_TEXT_DROPSHADOW(2, 2, 0, 0, 0);	UI::SET_TEXT_EDGE(1, 0, 0, 0, 205);	UI::SET_TEXT_LEADING(true);	UI::SET_TEXT_OUTLINE();	UI::_DRAW_TEXT(x, y);}void main(){	const int ARR_SIZE = 1024;	string msg = "";	Ped ped[ARR_SIZE];	Vector3 pedcoords;	int ped_count = 0;	int loop = 0;	float px = 0.0;	float py = 0.0;	int peds = 0;	while (true)	{		ped_count = worldGetAllPeds(ped, ARR_SIZE);		for (loop = 0; loop < ped_count; loop++)		{			if (ped[loop] != PLAYER::GET_PLAYER_PED(PLAYER::PLAYER_ID()))			{				pedcoords = ENTITY::GET_ENTITY_COORDS(ped[loop], false);				if (ENTITY::IS_ENTITY_ON_SCREEN(ped[loop]))				{					if (GRAPHICS::_WORLD3D_TO_SCREEN2D(pedcoords.x, pedcoords.y, pedcoords.z, &px, &py))					{						msg = "Ped: " + to_string(loop);						DrawLabel(msg, px, py, 0.25, true);					}				}			}		}		WAIT(0);	}}void ScriptMain(){	srand(GetTickCount());	main();}

I've tried adding each Ped to a 'Vector' and comparing, but that doesn't seem to work so far. I'm definitely not a C++ master, so may be going about it the wrong way...

 

Has anyone actually done this and can provide advice on the basic method that would be necessary to apply an action to each Ped in the current pool just once, which would of course mean being able to track them individually?

 

Hope this makes sense...

Edited by GTBunny

Share this post


Link to post
Share on other sites
GTBunny

Just looking back at this, I did find an ungodly hack of a workaround -- I set 'flag' to an apparently unused ped config flag value, 409. Setting/checking this flag once applied to a ped, I was able to tell if I'd processed it. The value 409 could of course be used by GTA in future, or even in places I'd simply not run into it being used, but it seemed to work:

                        if (!PED::GET_PED_CONFIG_FLAG(ped[loop], flag, true))                        {                            PED::SET_PED_CONFIG_FLAG(ped[loop], flag, true);                            //PED::APPLY_DAMAGE_TO_PED(ped[loop], 100, true);                            ENTITY::APPLY_FORCE_TO_ENTITY_CENTER_OF_MASS(ped[loop], 1, randfrom(-3.0, 3.0), randfrom(-3.0, 3.0), 20.0, true, true, true, true);                        }

Just posting in case anyone else runs into the need for this...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.