logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline alexguirre  
#1 Posted : Thursday, August 6, 2015 3:51:00 AM(UTC)
alexguirre


Rank: Member

Groups: Registered
Joined: 6/17/2015(UTC)
Posts: 87
Spain

Was thanked: 1 time(s) in 1 post(s)
Using this flag it considers all peds, humans and animals when I think it should only return the animals. Hre is my test code:
Code:

Ped animal = (Ped)World.GetClosestEntity(player.Position, 10.0f, GetEntitiesFlags.ConsiderAnimalPeds);
if (animal.Exists())
{
    animal.Velocity = animal.UpVector * 5.0f;
}

I'm using the latest version, at this moment is Open Alpha - 0.20.641.4077.

Edited by user Thursday, August 6, 2015 4:00:48 AM(UTC)  | Reason: Not specified

Offline Stealth22  
#2 Posted : Thursday, August 6, 2015 7:49:11 PM(UTC)
Stealth22


Rank: Moderator

Groups: Registered, Moderator
Joined: 7/9/2015(UTC)
Posts: 70
Canada

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
ConsiderAnimalPeds makes sense to me...it should include animals when searching for nearby Peds.

A workaround isn't difficult though. I'm not sure if this is the best solution, but here goes.

If you take a look at the NPC model list: http://ecb2.biz/releases/GTAV/lists/npcs.txt

You'll notice that all the animal models start with "a_c_". Thank Rockstar for adding type prefixes to their models, haha.

You could do something like this:

(Forgive me, as I'm more a VB.NET guy than C#, but I'll try my best haha)

EDIT: This code is untested, but it should work...

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using Rage;

class MyClass
    {

        public void DoSomething()
        {
            List<Entity> entityList = World.GetEntities(Game.LocalPlayer.Character.Position, 10f, GetEntitiesFlags.ConsiderAnimalPeds).ToList();

            Ped animal = (Ped) (from x in entityList where x.Model.Name.StartsWith("a_c_") orderby x.Position.DistanceTo(Game.LocalPlayer.Character.Position) select x).FirstOrDefault<Entity>();

            if (animal != null)
            {
                //do something here (animal will be null if no animal was found)
                if (animal.Exists())
                {
                    animal.Velocity = animal.UpVector * 5.0f;
                }
            }
        }
    }



In order to use Vector3.DistanceTo, you'll need this Vector3Extensions class, courtesy of LMS.

Code:
using Rage;

public static class Vector3Extension
    {
        public static Vector3 Around(this Vector3 start, float radius)
        {
            // Random direction.
            Vector3 direction = Vector3Extension.RandomXY();
            Vector3 around = start + (direction * radius);
            return around;
        }

        public static float DistanceTo(this Vector3 start, Vector3 end)
        {
            return (end - start).Length();
        }

        public static Vector3 RandomXY()
        {
            Random random = new Random(Environment.TickCount);

            Vector3 vector3 = new Vector3();
            vector3.X = (float)(random.NextDouble() - 0.5);
            vector3.Y = (float)(random.NextDouble() - 0.5);
            vector3.Z = 0.0f;
            vector3.Normalize();
            return vector3;
        }
    }

Edited by user Thursday, August 6, 2015 7:54:43 PM(UTC)  | Reason: Not specified

Offline alexguirre  
#3 Posted : Thursday, August 6, 2015 10:24:47 PM(UTC)
alexguirre


Rank: Member

Groups: Registered
Joined: 6/17/2015(UTC)
Posts: 87
Spain

Was thanked: 1 time(s) in 1 post(s)
Thanks I will try that.

Edited by user Thursday, August 6, 2015 10:27:14 PM(UTC)  | Reason: Not specified

Offline alexguirre  
#4 Posted : Friday, August 7, 2015 12:28:36 AM(UTC)
alexguirre


Rank: Member

Groups: Registered
Joined: 6/17/2015(UTC)
Posts: 87
Spain

Was thanked: 1 time(s) in 1 post(s)
Originally Posted by: Stealth22 Go to Quoted Post
ConsiderAnimalPeds makes sense to me...it should include animals when searching for nearby Peds.

A workaround isn't difficult though. I'm not sure if this is the best solution, but here goes.

If you take a look at the NPC model list: http://ecb2.biz/releases/GTAV/lists/npcs.txt

You'll notice that all the animal models start with "a_c_". Thank Rockstar for adding type prefixes to their models, haha.

You could do something like this:

(Forgive me, as I'm more a VB.NET guy than C#, but I'll try my best haha)

EDIT: This code is untested, but it should work...



It doesn't work. I think I know why, it is because Model.Name returns a hash, for example the model name of Franklin is "player_one" but it returns "0x5e3da4a4"

EDIT: also that hash changes everytime you enter the game

Edited by user Friday, August 7, 2015 12:51:35 AM(UTC)  | Reason: Not specified

Offline Stealth22  
#5 Posted : Friday, August 7, 2015 2:06:27 AM(UTC)
Stealth22


Rank: Moderator

Groups: Registered, Moderator
Joined: 7/9/2015(UTC)
Posts: 70
Canada

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Originally Posted by: alexguirre Go to Quoted Post
It doesn't work. I think I know why, it is because Model.Name returns a hash, for example the model name of Franklin is "player_one" but it returns "0x5e3da4a4"

EDIT: also that hash changes everytime you enter the game


What the heck? That's weird.

I use Model.Name in Code 3 Callouts, and it works fine...although that's for vehicles, not for peds.

Maybe MulleDK19 or LMS can chime in?
Offline alexguirre  
#6 Posted : Friday, August 7, 2015 2:07:33 AM(UTC)
alexguirre


Rank: Member

Groups: Registered
Joined: 6/17/2015(UTC)
Posts: 87
Spain

Was thanked: 1 time(s) in 1 post(s)
Originally Posted by: Stealth22 Go to Quoted Post
Originally Posted by: alexguirre Go to Quoted Post
It doesn't work. I think I know why, it is because Model.Name returns a hash, for example the model name of Franklin is "player_one" but it returns "0x5e3da4a4"

EDIT: also that hash changes everytime you enter the game


What the heck? That's weird.

I use Model.Name in Code 3 Callouts, and it works fine...although that's for vehicles, not for peds.

Maybe MulleDK19 or LMS can chime in?


Yes, Model.Name works with vehicles but with all the other entities it returns a hash
Offline MulleDK19  
#7 Posted : Friday, August 7, 2015 9:50:54 AM(UTC)
MulleDK19


Rank: Developer

Groups: Administrators
Joined: 5/20/2015(UTC)
Posts: 322
Man
Denmark

Was thanked: 22 time(s) in 18 post(s)
This is a bug, yes.

For now you can use the following work-around:
Code:
Ped[] animals = World.GetEntities(position, 10f, GetEntitiesFlags.ConsiderAnimals).Where(p => !p.IsHuman).ToArray();


(Internal issue #72)
We're now on Twitter!
Don't PM me with RAGE Plugin Hook issues (use the Technical Issues forum), and don't add me as a friend unless I know you.

If you need help developing using RAGE Plugin Hook, or just want to chat, join our IRC channel on freenode.
Links are on the front page of the website http://ragepluginhook.net.

Please note, that people may be idling, and response could take a while.
I suggest you stay for at least half an hour after asking your question (Or just stay forever).
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.