Is this possible?
#1

hey there peeps, my vision is to script some sort of vision perception for bots. I'm not much of a scripting marvel, here's a simple example: there's a bot walking back and forth and when he spots a player in front of him, the game is over... but there's one stupid as hell thing burning hole in my brain, the bots could also spot players behind walls. so I need some pawn experts to share their thoughts on how to script a script to prevent bots from spotting players behind solid objects.
Reply
#2

yes it can be done with PlayerToPoint
Reply
#3

PlayerToPoint is a old function from 0.1 but since 0.3(or was it 0.2 - forgot ) there is a native function called IsPlayerInRangeOfPoint, use that instead

But I am rly interested in the solution how he want to do it
Reply
#4

Hmm. I am thinking about something, but It won't work super good.
Try something like this:
Check for the player that's / that are near the NPC and check if he's near an object.
Do that with 'GetObjectPos(objectid, Float:X, Float:Y, Float:Z);'. Use an loop or something.
And with IsPlayerInRangeOfPoint you can check if he's near an object. However, this will then also work when it's like this:

pawn Код:
// Object (wall or something)
// Player

//^
//|
//|
// NPC
Do you understand it?
Reply
#5

You could always use the "MapAndreas" plugin which Kye put together some time ago to detect walls...
Reply
#6

let me explain a bit more of my intentions: guards (bots) walking / talking / smoking / wanking around Madd Doggs Mansion. your mission it to pass through guards without being spotted, steal a briefcase and escape with it... or something similar to that

Mr.Stranger, Nero_3D, Kwadre, RealCop228 thankyou all for your bright ideas.

Kwadre, my thoughts on your idea - I don't understand it... but on the other hand, I'm not going to use any Object related functions

RealCop228, I think I'm gonna take a closer look at MapAndreas.
Reply
#7

Making this sounds like fun to me
I could help you PM me i you want me to help
Reply
#8

Yep that sounds nice.

Well, Ive made such a function for my MFEx include (planned to release the whole thing, but now I want it to be unique for my server in dev )
It will only work, if the wall is thick enough, because MapAndreas uses a 1x1m square resolution.

However, I can live with this function beeing released, I hope it helps you.

pawn Код:
#if defined MapAndreas_Init
    stock IsPointVisibleFromPoint(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, &Float:length)
    {
        /*
            IsPointVisibleFromPoint checks the LOS between
            the points using MapAndreas.

            Params: x1/y1/z1 Point 1
                    x2/y2/z2 Point 2
                    &length: distance between both points (use it or leave it)
            Return: 1 if both points can see each other
                    0 if not
        */


        //Creating a 1m long vector between both points
        new Float:vx, Float:vy, Float:vz;
        vx = x1 - x2;
        vy = y1 - y2;
        vz = z1 - z2;
        length = GetPointToPoint(x1, y1, z1, x2, y2, z2);
        vx = vx / length;
        vy = vy / length;
        vz = vz / length;

        //Checking, if the line between them is below the ground at any time
        for(new i = 0; i < floatround(length); i ++)
        {
            x2 = x1 + i * vx;
            y2 = y1 + i * vy;
            z2 = z1 + i * vz;
            if(z2 <= GetGroundZ(x2, y2)) return 0;
        }
        return 1;
    }
   
    forward Float:GetGroundZ(Float:x, Float:y);
    Float:GetGroundZ(Float:x, Float:y)
    {
        /*
            This is just a shortcut for
            MapAndreas_FindZ_For2DCoord
            without the use of another variable

            Params: the x and y coord to get the z for
            Return: the z coord on the ground
        */

        new Float:gz;
        MapAndreas_FindZ_For2DCoord(x, y, gz);
        return gz;
    }
#endif

//Usage example:
new Float:x1, Float:x2, Float:y1, Float:y2, Float:z1, Float:z2, Float:distance;
GetPlayerPos(player1, x1, y1, z1);
GetPlayerPos(player2, x2, y2, z2);
if(IsPointVisibleFromPoint(x1, y1, z1, x2, y2, z2, distance))
{
    //Do something
}
Edit: Oh right, you also need any GetPointToPoint function. Just choose one (there are tons here in the forum) and rename it.
Reply
#9

thanks boelie, I'll be in touch.

Mauzen, your idea is ingenious! I have tried it, but it doesn't seem to be working.. unless I'm doing something wrong

I used your IsPointVisibleFromPoint code ... plus this one, found on forum:

pawn Код:
stock Float:PointToPoint(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
{
    x1 -= x2;
    y1 -= y2;
    z1 -= z2;
    return floatsqroot((x1 * x1) + (y1 * y1) + (z1 * z1));
}
downloaded MapAndreas plugin, and installed... tested it, everything is working fine.

next I connected an idle npc.
pawn Код:
ConnectNPC("TestBot", "npcidle");
I scripted a quick command for test...

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[256];
    new idx;
    cmd = strtok(cmdtext, idx);

    if(strcmp(cmd, "/test", true) == 0)
    {
        new Float:x1, Float:x2, Float:y1, Float:y2, Float:z1, Float:z2, Float:distance;
        GetPlayerPos(0, x1, y1, z1); // TestBot, who joined with id 0 naturally
        GetPlayerPos(playerid, x2, y2, z2);
        if(IsPointVisibleFromPoint(x1, y1, z1, x2, y2, z2, distance))
        {
            SendClientMessage(playerid, 0xFFFFFFFF, "Bot can see you from here.");
            return 1;
        }
        else return SendClientMessage(playerid, 0xFFFFFFFF, "Bot can't see you from here.");
    }
   
    return 0;
}
I've tried this command right infront of npc's face, behind walls, on the roof, and even there where sun doesn't shine... everytime it returns the "Bot can't see you" message. can you tell what's wrong?
Reply
#10

Oops, to be honest, ive never tested that function really well, I havent started with the scriptpart that I made it for yet. But it also didnt think I could make anything wrong, as this is a quite short function.
Im missing some time at the moment, but I will check it later that evening or more probable tomorrow.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)