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(out, 128, "TNPC:%s", msg);
SendCommand(out);
}
public OnClientMessage(color, text[]){
...
new msg[128];
format(msg, 128, "Setting my pos to %f %f %f", x, y, z);
echo(msg);
SetMyPos(x, y, z);
new Float:res[3];
GetMyPos(res[0], res[1], res[2]);
format(msg, 128, "My new pos: %f %f %f", res[0], res[1], res[2]);
echo(msg);
GetMyPos(res[0], res[1], res[2]);
format(msg, 128, "My new pos: %f %f %f", res[0], res[1], res[2]);
echo(msg);
}
// --- In Gamemode
public OnPlayerCommandText(playerid, cmdtext[]) {
if (!IsPlayerNPC(playerid)) return 1;
new Float:pp[3];
GetPlayerPos(playerid, pp[0], pp[1], pp[2]);
printf("OnPlayerCommandText(%i, %f %f %f)", playerid, pp[0], pp[1], pp[2]);
if (!strcmp("TNPC:", cmdtext, true, 5)) {
new msg[128];
strmid(msg, cmdtext, 5, 128);
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:40] Incoming connection: 127.0.0.1:63685
[21/01/2014 19:14:41] [npc:join] T_Mike has joined the server (0:127.0.0.1)
[21/01/2014 19:14:41] OnPlayerCommandText(0, 0.000000 0.000000 0.000000)
[21/01/2014 19:14:41] - [NPC 0] Setting my pos to -2180.750000 -2431.780029 35.523399
[21/01/2014 19:14:41] OnPlayerCommandText(0, 0.000000 0.000000 0.000000)
[21/01/2014 19:14:41] - [NPC 0] My new pos: -2180.750000 -2431.780029 35.523399
[21/01/2014 19:14:41] OnPlayerCommandText(0, 0.000000 0.000000 0.000000)
[21/01/2014 19:14:41] - [NPC 0] My new pos: 0.000010 0.000000 0.000000
[21/01/2014 19:14:41] OnPlayerCommandText(0, 0.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