SA-MP Forums Archive
Something wrong with default NPC's - 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: Something wrong with default NPC's (/showthread.php?tid=489264)



Something wrong with default NPC's - therainycat - 21.01.2014

Hi.

I have connected NPC to my server successfully, and now trying to change it's position - no result.
Here are some letters:

PHP код:
// --- In NPC mode
stock echo(msg[]){
    new 
out[128];
    
format(out128"TNPC:%s"msg);
    
SendCommand(out);
}
public 
OnClientMessage(colortext[]){
    ...
    new 
msg[128];
    
format(msg128"Setting my pos to %f %f %f"xyz);
    echo(
msg);
    
SetMyPos(xyz);
    new 
Float:res[3];
    
GetMyPos(res[0], res[1], res[2]);
    
format(msg128"My new pos: %f %f %f"res[0], res[1], res[2]);
    echo(
msg);
    
GetMyPos(res[0], res[1], res[2]);
    
format(msg128"My new pos: %f %f %f"res[0], res[1], res[2]);
    echo(
msg);
}
// --- In Gamemode
public OnPlayerCommandText(playeridcmdtext[]) {
    if (!
IsPlayerNPC(playerid)) return 1;
    
    new 
Float:pp[3];
    
GetPlayerPos(playeridpp[0], pp[1], pp[2]);
    
printf("OnPlayerCommandText(%i, %f %f %f)"playeridpp[0], pp[1], pp[2]);
    
    if (!
strcmp("TNPC:"cmdtexttrue5)) {
        new 
msg[128];
        
strmid(msgcmdtext5128);
        
printf("- [NPC %i] %s",playerid,msg);
        return 
1;
    }

When i start this thing, I have such a situation in server log (server_log.txt and console):
PHP код:
[21/01/2014 19:14:40Incoming connection127.0.0.1:63685
[21/01/2014 19:14:41] [npc:joinT_Mike has joined the server (0:127.0.0.1)
[
21/01/2014 19:14:41OnPlayerCommandText(00.000000 0.000000 0.000000)
[
21/01/2014 19:14:41] - [NPC 0Setting my pos to -2180.750000 -2431.780029 35.523399
[21/01/2014 19:14:41OnPlayerCommandText(00.000000 0.000000 0.000000)
[
21/01/2014 19:14:41] - [NPC 0My new pos: -2180.750000 -2431.780029 35.523399
[21/01/2014 19:14:41OnPlayerCommandText(00.000000 0.000000 0.000000)
[
21/01/2014 19:14:41] - [NPC 0My new pos0.000010 0.000000 0.000000
[21/01/2014 19:14:41OnPlayerCommandText(00.000000 0.000000 0.000000
As you can see, there was no action between "GetMyPos" and the second "GetMyPos" (as they are going in the row), but position skiped to 0.0 0.0 0.0 with some kind of magic.

And one more thing: when I call GetPlayerPos(npc_id, x, y, z) with an existing NPC (checked twice with IsPlayerConnected and IsPlayerNPC), in some cases the server crashes (the only line in backtrace is GetPlayerPos).

Server version: 0.3z RC2

Any ideas? Thanks for answers