SA-MP Forums Archive
Stopping npcs - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Stopping npcs (/showthread.php?tid=296140)



Stopping npcs - Luis- - 09.11.2011

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.


Re: Stopping npcs - Luis- - 10.11.2011

Please, I need to find out how to do this.


Re: Stopping npcs - MP2 - 10.11.2011

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


Re: Stopping npcs - Lorenc_ - 10.11.2011

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.


Re: Stopping npcs - Luis- - 10.11.2011

How would I get the npcs ID?


Re: Stopping npcs - SiJ - 10.11.2011

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)


Re: Stopping npcs - Lorenc_ - 10.11.2011

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


Re: Stopping npcs - Luis- - 11.11.2011

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;
}



Re: Stopping npcs - Lorenc_ - 11.11.2011

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


Re: Stopping npcs - Luis- - 12.11.2011

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.