[Include] Simple AI Police Officer NPC using RNPC
#21

@qq757679895

Put the example that Mauzen done

pawn Code:
new rp = CreateRNPCPolice("Officerino", 280);
AddRPOLWaypoint(rp, 2029.42, 1354.34, 10.5);
AddRPOLWaypoint(rp, 2033.55, 1286.21, 10.5);
AddRPOLWaypoint(rp, 2079.03, 1286.00, 10.5);
AddRPOLWaypoint(rp, 2079.02, 1362.08, 10.5);
StartRPOLRoute(rp);
Reply
#22

Why the police can not move.
Reply
#23

Woah, awesome.
Reply
#24

Nice Include.
Reply
#25

Quote:
Originally Posted by [FeK]DraKiNs
View Post
Good working Mauzen !!
I am creating a system of zombies, advise the use of RNPC !!

Kill NPC
pawn Code:
// top of gm
new tirosLevados[MAX_PLAYERS];

// onplayer update
static targetplayer,  Keys,ud,lr;
GetPlayerKeys(playerid,Keys,ud,lr);
targetplayer = GetPlayerTargetPlayer(playerid);

if(targetplayer != INVALID_PLAYER_ID && Keys == KEY_FIRE || Keys == 132)
{
    if(IsPlayerNPC(targetplayer)) {
        tirosLevados[targetplayer]++;
        SetPVarInt(playerid, "timesTick", GetTickCount());
        if(tirosLevados[targetplayer] > 20) { // 20 shoots +-
            SpawnPlayer(targetplayer);
            OnPlayerDeath(targetplayer, playerid, GetPlayerWeapon(playerid));
            tirosLevados[targetplayer] = 0;
          }
    }
}


Follow
pawn Code:
CHK_RowMoviment(n, moviment) {

    if(moviment > rowNPCMove[n]) {
        return false;
    }
   
    static
        rowSTR[3][32];

    format(rowSTR[0], 32, "rowNPC%dX", moviment);
    format(rowSTR[1], 32, "rowNPC%dY", moviment);
    format(rowSTR[2], 32, "rowNPC%dZ", moviment);

    return IsPlayerInRangeOfPoint(n, 1.5, GetPVarFloat(n, rowSTR[0]),GetPVarFloat(n, rowSTR[1]),GetPVarFloat(n, rowSTR[2]));
}

EXE_RowMoviment(n) {

    if(!rowNPCMove[n] || execROWMoviment[n] > (rowNPCMove[n] - 1))  {
        return false;
    }

    if(execROWMoviment[n]) {
        if(!CHK_RowMoviment(n, execROWMoviment[n]-1)) {
            return false;
        }
    }

   
    static
        rowSTR[4][32];


    if(execROWMoviment[n] > 1) {
        for(new i = execROWMoviment[n]-1; i > -1; i--) {
            format(rowSTR[0], 32, "rowNPC%dX", i);
            format(rowSTR[1], 32, "rowNPC%dY", i);
            format(rowSTR[2], 32, "rowNPC%dZ", i);
            format(rowSTR[3], 32, "rowNPC%dS", i);

            DeletePVar(n,rowSTR[0]);
            DeletePVar(n,rowSTR[1]);
            DeletePVar(n,rowSTR[2]);
            DeletePVar(n,rowSTR[3]);
        }
    }
   
    format(rowSTR[0], 32, "rowNPC%dX", execROWMoviment[n]);
    format(rowSTR[1], 32, "rowNPC%dY", execROWMoviment[n]);
    format(rowSTR[2], 32, "rowNPC%dZ", execROWMoviment[n]);
    format(rowSTR[3], 32, "rowNPC%dS", execROWMoviment[n]);
   
    MoveRNPC(n, GetPVarFloat(n, rowSTR[0]),GetPVarFloat(n, rowSTR[1]),GetPVarFloat(n, rowSTR[2]),GetPVarFloat(n, rowSTR[3]));

    return execROWMoviment[n]++;
}

ADD_RowMoviment(n, Float:x, Float:y, Float:z, Float:s) {

    static str[32];

    format(str, 32, "rowNPC%dX", rowNPCMove[n]);
    SetPVarFloat(n, str, x);
   
    format(str, 32, "rowNPC%dY", rowNPCMove[n]);
    SetPVarFloat(n, str, y);
   
    format(str, 32, "rowNPC%dZ", rowNPCMove[n]);
    SetPVarFloat(n, str, z);
   
    format(str, 32, "rowNPC%dS", rowNPCMove[n]);
    SetPVarFloat(n, str, s);

    return rowNPCMove[n]++;
}
Now use:
pawn Code:
ADD_RowMoviment(npcid, x-0.1, y-0.1, z,0.006);
// MoveRNPC(npcid, x-0.1, y-0.1, z,0.006);
EXE_RowMoviment(npcid);
pawn Code:
new execROWMoviment[MAX_PLAYERS];
new rowNPCMove[MAX_PLAYERS];
This follows exactly where the player walks. It can also be optimized ..

- So the NPC does not fly on the wall, or walk inside them or fly into holes
I'm looking forward to your zombies npc
Reply
#26

Quote:
Originally Posted by qq757679895
View Post
Why the police can not move.
Its a problem with the RNPC plugin, that im currently fixing. Start the route some seconds after creating the npc with a timer, and it will work.
Reply
#27

I used the death of NPC script, I killed him, how resurrect it.

I knelt down, he can not hit.
Reply
#28

The plugin doesn't include any death system. You should do it by yourself in some ways.
Reply
#29

Yep, I didnt consider any deaths in it. Youll probably need to restart the playback when the npc respawned, e.g. by calling OnNPCFinishPlayback manually.

Also heres an example code i just PMed someone, to fix the problems with NPCs not moving after spawn:
pawn Code:
new pol;
public OnGameModeInit() {
    SetTimer("ConnectAllNPCs", 5000, 0);
}

public ConnectAllNPCs() {
    // Connect the NPC after the gamemode is loaded
    pol = ConnectRNPC("Police");
    // Add all waypoints or other NPCs...
    SetTimer("StartAllRoutes", 500, 0);
}

public StartAllRoutes() {
    StartRPOLRoute(pol);
    // etc
}
Reply
#30

You need to fill this array
pawn Code:
new rpol[MAX_RNPC_POLICE][RPol_enum] = {{-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1},
        {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1},
        {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1} };
and add/remove more {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1} until it got the correct size. I was too lazy to hook a init function that fills the array automaitcally
Reply
#31

Officer pickups just first RPOLWaypoint and not continues on others. He just stand's in same position after picking the first RPOLWaypoint. Tried many ways, but npc do the same
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)