FCNPC Bot seems bugged
#1

Hi,

So I'm using FCNPC, but I've got a small problem.
The torso of the NPC keeps flashing; like normal, invisible.
Does someone know the cause, or how to fix this issue?

Thanks in advance,
Arjan
Reply
#2

What do you mean flashing? Can you provide a SS?
Reply
#3

I can't really provide a screenshot because it happens so fast, although the upper part of the body just goes invisible for like a few hundred milliseconds and then it turns back to normal. And this seems to happen when I update the NPC.

This is the script I'm using:

Код:
public OnPlayerUpdate(playerid)
{
  	new Float:px, Float:py, Float:pz, Float:bx, Float:by, Float:bz;
  	GetPlayerPos(playerid, px, py, pz);
  	FCNPC_GetPosition(spawningNPC, bx, by, bz);

  	if(GetPlayerDistanceFromPoint(playerid, bx, by, bz) <= 10)
    {
    	FCNPC_AimAt(spawningNPC, px, py, pz, 1);
    }else
    {
    	FCNPC_StopAim(spawningNPC);
    }

	return 1;
}
Reply
#4

The thing I have noticed is the head and upper body actually detaching from the body, and raising to the top left corner of the player's screen when setting aim data. I believe this is due to an angle the NPC can't actually aim at, and therefore the upper body is forced to re-adjust(although it may just be a scripted bug).

Also do you realize every time the player updates if they are not in range of that point StopAim is called? That may very well be the issue, try using this stock in place of FCNPC_AimAt, and FCNPC_StopAim.

pawn Код:
stock FCNPC_AimAtEx(playerid, Float: x, Float: y, Float: z, shoot)
{
     if(FCNPC_AimAt(playerid, x, y, z, shoot)) Aiming[playerid] = true;
     return 1;
}
pawn Код:
FCNPC_StopAimEx(playerid)
{
       if(Aiming[playerid] == true) {
              FCNPC_StopAim(playerid);
              Aiming[playerid] = false;
       }
       return 1;
}
Also, try using zones. The best way is to use y_zones or streamer zones.
Reply
#5

'Aiming' was not defined so I created: 'new Aiming[MAX_PLAYERS];'.
The bot is acting the same way as before, therefore the the problem still exists :/
Reply
#6

The Aiming variable needs to be a boolean to work properly with my example. Simply:
pawn Код:
new bool: Aiming[MAX_PLAYERS];
Reply
#7

It didn't do much either.

I got a screenshot though.
Reply
#8

Yeah the aim data seems to be off. Try offsetting the player's coordinates and see what works. Also, try using this function(by StrickenKid - converted to work for NPC's by me) to set the NPC facing the player.

pawn Код:
stock SetNPCFacingPlayer(playerid, facingid)
{
    new Float:Px, Float:Py, Float: Pa;
    new Float:x,Float:y,Float:z;
    GetPlayerPos(facingid,x,y,z);
    #pragma unused z
    FCNPC_GetPosition(playerid, Px, Py, Pa);
    Pa = floatabs(atan((y-Py)/(x-Px)));
    if (x <= Px && y >= Py) Pa = floatsub(180, Pa);
    else if (x < Px && y < Py) Pa = floatadd(Pa, 180);
    else if (x >= Px && y <= Py) Pa = floatsub(360.0, Pa);
    Pa = floatsub(Pa, 90.0);
    if (Pa >= 360.0) Pa = floatsub(Pa, 360.0);
    return FCNPC_SetAngle(playerid, Pa);
}
Reply
#9

Quote:
Originally Posted by Abagail
Посмотреть сообщение
Yeah the aim data seems to be off. Try offsetting the player's coordinates and see what works. Also, try using this function(by StrickenKid - converted to work for NPC's by me) to set the NPC facing the player.

pawn Код:
stock SetNPCFacingPlayer(playerid, facingid)
{
    new Float:Px, Float:Py, Float: Pa;
    new Float:x,Float:y,Float:z;
    GetPlayerPos(facingid,x,y,z);
    #pragma unused z
    FCNPC_GetPosition(playerid, Px, Py, Pa);
    Pa = floatabs(atan((y-Py)/(x-Px)));
    if (x <= Px && y >= Py) Pa = floatsub(180, Pa);
    else if (x < Px && y < Py) Pa = floatadd(Pa, 180);
    else if (x >= Px && y <= Py) Pa = floatsub(360.0, Pa);
    Pa = floatsub(Pa, 90.0);
    if (Pa >= 360.0) Pa = floatsub(Pa, 360.0);
    return FCNPC_SetAngle(playerid, Pa);
}
So I would use this function before I do the AimAt?
Reply
#10

Quote:
Originally Posted by arjanforgames
Посмотреть сообщение
So I would use this function before I do the AimAt?
Hey, mate. I know about your problem. Early I had the same, but when I rescripted all with 0 and use quaternions after spawning all became alright. No one flashing, just look at your code lines sometimes you can forget about something about pvar and another FCNPC requires to scripting right, it's sounds fun, but it's right
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)