[NPC FS] Instant server crash
#1

Hello,

My server crashes when trying to run it. It stops while/after reading the filterscript (according to the logfile). I tried running an empty GM too, but that did not work either. Everything works when I disable this FS. I used the loops and all so I can add new buses to an INI file later on.

server.cfg
Код:
echo Executing Server Config...
lanmode 0
rcon_password password
maxplayers 50
port 7777
hostname Sydcul's SA-MP Server
gamemode0 grandlarc 1
filterscripts bus
announce 0
query 1
chatlogging 0
weburl www.sydcul.com
onfoot_rate 40
incar_rate 40
weapon_rate 40
stream_distance 300.0
stream_rate 1000
maxnpc 10
logtimeformat [%H:%M:%S]
bus.pwn (filterscript)
Код:
// © 2013 Sydcul. All rights reserved.
#include <a_samp>

new bus[][4][MAX_PLAYER_NAME+1] = {
	//Format: player/recording name, vehicle id, fare per IRL second
	{"Fred", 400, 10, 0}
};

public OnFilterScriptInit()
{
	print("Bus v1.0 - by Sydcul");
	for(new i = 0; i < sizeof bus[]; i++) {
	    ConnectNPC(bus[i][0][0], "bus");
 		bus[i][3][0] = CreateVehicle(bus[i][1][0], 0.0, 0.0, 5.0, 0.0, 3, 3, 5000);
	}
	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}

public OnPlayerSpawn(playerid)
{
    if(IsPlayerNPC(playerid))
  	{
    	for(new i = 0; i < sizeof bus[]; i++) {
    	    new npcname[MAX_PLAYER_NAME];
    		GetPlayerName(playerid, npcname, sizeof(npcname));
	        if(!strcmp(npcname, bus[i][0][0], true))
    		{
    	    	SetPlayerSkin(playerid, 253);
      			PutPlayerInVehicle(playerid, bus[i][3][0], 0);
   			}
		}
    	return 1;
  	}
	return 1;
}
bus.pwn (npc mode)
Код:
#include <a_npc>

new name[MAX_PLAYER_NAME+1];

public OnNPCConnect(myplayerid)
{
    GetPlayerName(myplayerid, name, sizeof(name));
}

public OnRecordingPlaybackEnd() {
	StartRecordingPlayback(1, name);
}

public OnNPCEnterVehicle(vehicleid, seatid){
	StartRecordingPlayback(1, name);
}

public OnNPCExitVehicle(){
	StopRecordingPlayback();
}
Logfile:
Код:
SA-MP Dedicated Server
----------------------
v0.3x-R2, ©2005-2013 SA-MP Team

[15:30:27] 
[15:30:27] Server Plugins
[15:30:27] --------------
[15:30:27]  Loaded 0 plugins.

[15:30:27] 
[15:30:27] Filterscripts
[15:30:27] ---------------
[15:30:27]   Loading filterscript 'bus.amx'...
[15:30:27] Bus v1.0 - by Sydcul
Reply
#2

Any ideas?
Reply
#3

I wonder if anyone knows.
Reply
#4

Load crashdetect plugin.
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Load crashdetect plugin.
Whoops, couldn't find the binaries for crashdetect, but you did for me. Thanks a lot.
Reply
#6

So now I've got this.
Код:
[19:57:56] [npc:join] Fred has joined the server (0:127.0.0.1)
[19:57:57] [debug] Run time error 4: "Array index out of bounds"
[19:57:57] [debug]  Accessing element at index 1 past array upper bound 0
[19:57:57] [debug] AMX backtrace:
[19:57:57] [debug] #0 000002a8 in public OnPlayerSpawn (0x00000000) from bus_fs.amx
[19:58:12] [npc:part] Fred has left the server (0:0)
The code:
Код:
public OnPlayerSpawn(playerid)
{
    if(IsPlayerNPC(playerid))
  	{
    	for(new i = 0; i < sizeof(bus); i++) {
    		new npcname[MAX_PLAYER_NAME];
			GetPlayerName(playerid, npcname, sizeof(npcname));
  			if(!strcmp(npcname, bus[i][0][0], true))
  			{
    	    	SetPlayerSkin(playerid, 253);
      			PutPlayerInVehicle(playerid, bus[i][3][0], 0);
			}
		}
    	return 1;
  	}
	return 1;
}
The initial crash was because of a sizeof() when there was no size set.
Reply
#7

It shouldn't have crashed the server because sizeof returns 1 (it's correct) and it should be called only once with i equal to 0.

You can normally debug it:
pawn Код:
public OnPlayerSpawn(playerid)
{
    if(IsPlayerNPC(playerid))
    {
        printf("DEBUG: sizeof(bus) -> %i", sizeof(bus));
        new npcname[MAX_PLAYER_NAME];
        GetPlayerName(playerid, npcname, sizeof(npcname));
        for(new i = 0; i < sizeof(bus); i++)
        {
            printf("DEBUG: OnPlayerSpawn -> i: %i", i);
            if(!strcmp(npcname, bus[i][0][0], true))
            {
                SetPlayerSkin(playerid, 253);
                PutPlayerInVehicle(playerid, bus[i][3][0], 0);
            }
        }
        return 1;
    }
    return 1;
}
and let's see what size is going to return and how many times the loop is called.

Crashdetect can also help on the debugging by compiling your scripts with debug info (-d3): https://github.com/Zeex/samp-plugin-...ith-debug-info

Do both and start the server, let the NPC connect to the server and post again what it printed.
Reply
#8

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
It shouldn't have crashed the server because sizeof returns 1 (it's correct) and it should be called only once with i equal to 0.

You can normally debug it:
pawn Код:
public OnPlayerSpawn(playerid)
{
    if(IsPlayerNPC(playerid))
    {
        printf("DEBUG: sizeof(bus) -> %i", sizeof(bus));
        new npcname[MAX_PLAYER_NAME];
        GetPlayerName(playerid, npcname, sizeof(npcname));
        for(new i = 0; i < sizeof(bus); i++)
        {
            printf("DEBUG: OnPlayerSpawn -> i: %i", i);
            if(!strcmp(npcname, bus[i][0][0], true))
            {
                SetPlayerSkin(playerid, 253);
                PutPlayerInVehicle(playerid, bus[i][3][0], 0);
            }
        }
        return 1;
    }
    return 1;
}
and let's see what size is going to return and how many times the loop is called.

Crashdetect can also help on the debugging by compiling your scripts with debug info (-d3): https://github.com/Zeex/samp-plugin-...ith-debug-info

Do both and start the server, let the NPC connect to the server and post again what it printed.
WTF, your code didn't crash the server (neither did mine, but crashdetect showed stuff).

Код:
[20:11:30] [npc:join] Fred has joined the server (0:127.0.0.1)
[20:11:30] DEBUG: sizeof(bus) -> 1
[20:11:30] DEBUG: OnPlayerSpawn -> i: 0
[20:11:45] [npc:part] Fred has left the server (0:0)
That is correct, I think, as Fred is the first player to join and there is one bus (Fred). He immediately disconnects, tho. I have no anticheat/register (I use the pawno>new gamemode)

P.S. Big clucker
Reply
#9

I really don't know why crashdetect showed that.

Take a look: https://sampforum.blast.hk/showthread.php?tid=95034
At the bottom of the first post -> Common problems
Reply
#10

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
I really don't know why crashdetect showed that.

Take a look: https://sampforum.blast.hk/showthread.php?tid=95034
At the bottom of the first post -> Common problems
The exact same tut I used. The stuff from my last post was generated by your code, and not by crashdetect (in fact crashdetect didn't generate anything). Just to clarify.

So I used the debug flag.
Код:
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase

Header size:            400 bytes
Code size:             1400 bytes
Data size:              740 bytes
Stack/heap size:      16384 bytes; estimated max. usage=36 cells (144 bytes)
Total requirements:   18924 bytes
But I doubt you need that info.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)