Stopping npcs
#1

Hi, I am wanting to freeze my npc when it detects someone Infront of them, I know it's possible, PRRP have done it. Thanks.
Reply
#2

Please, I need to find out how to do this.
Reply
#3

See taxi_ls_test.pwn in the server package. (in the npcmodes directory)
Reply
#4

pawn Код:
new Float: fA, Float: X, Float: Y, Float: Z, Float: nX, Float: nY;
GetPlayerFacingAngle(npcid, fA);
GetPlayerPos(npcid, X, Y, Z);

nX = X + ( 2.0 * floatcos(fA, degrees) );
nY = Y + ( 2.0 * floatsin(fA, degrees) );

if(IsPlayerInRangeOfPoint(playerid, nX, nY, Z)) return true; // his at the loc
Basic structure. Not tested.
Reply
#5

How would I get the npcs ID?
Reply
#6

Quote:
Originally Posted by -Luis
Посмотреть сообщение
How would I get the npcs ID?
AS MP2 said, just check the code used in taxi_ls_test.pwn (comes with the server package)
Reply
#7

Quote:
Originally Posted by -Luis
Посмотреть сообщение
How would I get the npcs ID?
Good idea!


One way you could possibly do this is to:

1. Use the file functions and write as the file header the NPC's name.
2. Connect the NPC
3. Go to OnPlayerRequestSpawn
4.
pawn Код:
if(IsPlayerNPC(playerid)) { "STEP5" }
5. Check inside the little code whether there is a file created with his name.
6. If this has been set out correctly and he has a file create a basic array "new g_NpcID[MAX_PLAYERS];"
7. g_NpcID[MAX_PLAYERS] = playerid;
8. Get the NPC ID:
pawn Код:
new
    playerid
;
for(new i; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i) && IsPlayerNPC(i))
{
    GetPlayerPos(g_NpcID[i], X, Y, Z);
    for(new all; all < MAX_PLAYERS; all++)
    {
       if(IsPlayerInRangeOfPoint(all, nX, nY, Z)) //Basic calculation said before
       {
       }
    }
}
something like this.

HOWEVER. Hooking the file creation method to ConnectNPC would be the best idea i guess lol
Reply
#8

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
pawn Код:
new Float: fA, Float: X, Float: Y, Float: Z, Float: nX, Float: nY;
GetPlayerFacingAngle(npcid, fA);
GetPlayerPos(npcid, X, Y, Z);

nX = X + ( 2.0 * floatcos(fA, degrees) );
nY = Y + ( 2.0 * floatsin(fA, degrees) );

if(IsPlayerInRangeOfPoint(playerid, nX, nY, Z)) return true; // his at the loc
Basic structure. Not tested.
I've been using this and here's my code, which fails I know xD, is there any problems with it?
pawn Код:
forward BotChecks(playerid);
public BotChecks(playerid)
{
    new Float:pPos[3], Float:Pos[3], Float:npPos[4], Float:nPos[3], string[100], id;
    GetPlayerPos(id, npPos[0], npPos[1], npPos[2]);
    GetPlayerFacingAngle(id, npPos[3]);
    Pos[0] = npPos[0] + ( 15.5 * floatcos(npPos[3], degrees) );
    Pos[1] = npPos[1] + ( 15.5 * floatsin(npPos[3], degrees) );
    if(IsPlayerInRangeOfPoint(playerid, 15.5, Pos[0], Pos[1], npPos[2]))
    {
        TogglePlayerControllable(id, 0);
        SetTimer("NPCFreeze", 6000, false);
    }
    return 1;
}

forward NPCFreeze(playerid);
public NPCFreeze(playerid)
{
    new string[128], id;
    format(string, sizeof(string), "%s[%d]: {FFFFFF}Hey! %s move out the way. I'm trying to do my job here!", Name(id), id, Name(playerid));
    SendClientMessageToAll(GetPlayerColor(id), string);
    TogglePlayerControllable(id, 1);
    return 1;
}
Reply
#9

Quote:
Originally Posted by -Luis
Посмотреть сообщение
I've been using this and here's my code, which fails I know xD, is there any problems with it?
pawn Код:
forward BotChecks(playerid);
public BotChecks(playerid)
{
    new Float:pPos[3], Float:Pos[3], Float:npPos[4], Float:nPos[3], string[100], id;
    GetPlayerPos(id, npPos[0], npPos[1], npPos[2]);
    GetPlayerFacingAngle(id, npPos[3]);
    Pos[0] = npPos[0] + ( 15.5 * floatcos(npPos[3], degrees) );
    Pos[1] = npPos[1] + ( 15.5 * floatsin(npPos[3], degrees) );
    if(IsPlayerInRangeOfPoint(playerid, 15.5, Pos[0], Pos[1], npPos[2]))
    {
        TogglePlayerControllable(id, 0);
        SetTimer("NPCFreeze", 6000, false);
    }
    return 1;
}

forward NPCFreeze(playerid);
public NPCFreeze(playerid)
{
    new string[128], id;
    format(string, sizeof(string), "%s[%d]: {FFFFFF}Hey! %s move out the way. I'm trying to do my job here!", Name(id), id, Name(playerid));
    SendClientMessageToAll(GetPlayerColor(id), string);
    TogglePlayerControllable(id, 1);
    return 1;
}
looks right though the ID has no value to it. Meaning it's set default as '0'

To get the ID try attempt of my method. It works for my zombie script
Reply
#10

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
Good idea!


One way you could possibly do this is to:

1. Use the file functions and write as the file header the NPC's name.
2. Connect the NPC
3. Go to OnPlayerRequestSpawn
4.
pawn Код:
if(IsPlayerNPC(playerid)) { "STEP5" }
5. Check inside the little code whether there is a file created with his name.
6. If this has been set out correctly and he has a file create a basic array "new g_NpcID[MAX_PLAYERS];"
7. g_NpcID[MAX_PLAYERS] = playerid;
8. Get the NPC ID:
pawn Код:
new
    playerid
;
for(new i; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i) && IsPlayerNPC(i))
{
    GetPlayerPos(g_NpcID[i], X, Y, Z);
    for(new all; all < MAX_PLAYERS; all++)
    {
       if(IsPlayerInRangeOfPoint(all, nX, nY, Z)) //Basic calculation said before
       {
       }
    }
}
something like this.

HOWEVER. Hooking the file creation method to ConnectNPC would be the best idea i guess lol
I don't really understand this for some reason.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)