Problem regarding loading a function with SetTimer
#1

Hello all.

I have a strange problem here. So I have a function, say, to load a map. And I use timer to load that function:

Код:
function:LoadMap(mapname[])
{
	new file[100];
	format(file, sizeof(file), MAP_LOCATION, mapname);
	if(!fexist(file)) return printf("FATAL ERROR: Failed to load map files %s (File doesnt exist in scriptfiles directory)!", file);

	LoadMapSettings(mapname);
	print("\n============================================");
	print("Currently loading....");
	printf("Mapname: %s", MapConfig[MAP_NAME]);
	printf("Author: %s", MapConfig[MAP_AUTHOR]);
	printf("Version: %s", MapConfig[MAP_VERSION]);
	print("============================================");

	printf("[MAP: %s] Map settings loaded!", MapConfig[MAP_NAME]);

	LoadMapDynamicObjects(MapConfig[MAP_CONFIGURATION_NAME]);

	new randomload = random(sizeof(Maplist));
	SetTimerEx("LoadMap", MapConfig[MAP_TIME], false, "s", Maplist[randomload]);

	return 1;
}
I already have this code in OnGamemodeInIt to run the function the first time:

Код:
public OnGameModeInit()
{
	LoadMap("shipment"); 
        return 1;
}
Take a look at this code in that function above

Код:
	new file[100];
	format(file, sizeof(file), MAP_LOCATION, mapname);
	if(!fexist(file)) return printf("FATAL ERROR: Failed to load map files %s (File doesnt exist in scriptfiles directory)!", file)
....and look at this:



I don't understand how could this happen. And sometimes it even tries to load the first message I give to the server, say when I entered a password in the dialog box the first time I connect to the server. And sometimes it load the message I typed to the chat.

And note that:
1. I am aware of SetTimer bug regarding passing strings or array, and I fixed (or at least I hope it is really fixed) from an include <fixes2.inc>


serverlog.txt
Код:
[16:54:03] Currently loading....
[16:54:03] Mapname: Cargoship
[16:54:03] Author: playbox12
[16:54:03] Version: v0.1
[16:54:03] ============================================
[16:54:03] [MAP: Cargoship] Map settings loaded!
[16:54:03] [MAP: cargoship]  229 objects loaded!
[16:54:06] 
============================================
[16:54:06] Currently loading....
[16:54:06] Mapname: Shipment
[16:54:06] Author: playbox12
[16:54:06] Version: v0.1
[16:54:06] ============================================
[16:54:06] [MAP: Shipment] Map settings loaded!
[16:54:06] [MAP: shipment]  381 objects loaded!
[16:54:09] 
============================================
[16:54:09] Currently loading....
[16:54:09] Mapname: Shipment
[16:54:09] Author: playbox12
[16:54:09] Version: v0.1
[16:54:09] ============================================
[16:54:09] [MAP: Shipment] Map settings loaded!
[16:54:09] [MAP: shipment]  381 objects loaded!
[16:54:10] [connection] 127.0.0.1:54656 requests connection cookie.
[16:54:11] [connection] incoming connection: 127.0.0.1:54656 id: 0
[16:54:11] [join] RedBaron has joined the server (0:127.0.0.1)
[16:54:12] FATAL ERROR: Failed to load map files codsamp/Maps/127.0.0.1 (File doesnt exist in scriptfiles directory)!
[16:55:28] [part] RedBaron has left the server (0:1)
So the function works just fine until I join the server and seems like I just messed it up.

What is causing this problem...?
Reply
#2

Do you have the folders created correctly?
Reply
#3

Quote:
Originally Posted by Speedpro
Посмотреть сообщение
Do you have the folders created correctly?
Yes I do.

You can see that it actually load the file from the folders properly.... but until I join the server it messes up.
Reply
#4

Why this is still called once the map is loaded ?
pawn Код:
new file[100];
    format(file, sizeof(file), MAP_LOCATION, mapname);
    if(!fexist(file)) return printf("FATAL ERROR: Failed to load map files %s (File doesnt exist in scriptfiles directory)!", file)
Reply
#5

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
Why this is still called once the map is loaded ?
pawn Код:
new file[100];
    format(file, sizeof(file), MAP_LOCATION, mapname);
    if(!fexist(file)) return printf("FATAL ERROR: Failed to load map files %s (File doesnt exist in scriptfiles directory)!", file)
Because I need to check if it successfully load the map from the folder.

EDIT: I'm not using that function twice. I'm just trying to say that you should take a look at the function I pointed out. If this is a misunderstanding?
Reply
#6

So the problem is that the invalid calling of function (that opens the map files) when connecting to server right?
Can u post the onplayerconnect?
Reply
#7

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
So the problem is that the invalid calling of function (that opens the map files) when connecting to server right?
Can u post the onplayerconnect?
Blank. Nothing is added to OnPlayerConnect.

Код:
public OnPlayerConnect(playerid)
{
	return 1;
}
Any ideas?
Reply
#8

Bump. Any ideas?
Reply
#9

Ok im not sure what causing this from the source you provided as you said there is nothing on onplayerconnect

The function LodMap undergoes infinite recursion right?
Код:
function:LoadMap(mapname[])
{
	/***Rest of the code**/
	new randomload = random(sizeof(Maplist));
	SetTimerEx("LoadMap", MapConfig[MAP_TIME], false, "s", Maplist[randomload]);

	return 1;
}
I dont know why you calling it inside the function itself if you correct that logic there we can find some better result.



Next thing i wanted to point out that you can easily pass the array index instead of string to timer and process the index from function body.(But in the gamemodeint you should pass the index manually not by random).
Код:
new randomload = random(sizeof(Maplist));
	SetTimerEx("LoadMap", MapConfig[MAP_TIME], false, "i", randomload);
Код:
function:LoadMap(index)
{
	new file[100];
	format(file, sizeof(file), MAP_LOCATION, Maplist[index]);
	if(!fexist(file)) return printf("FATAL ERROR: Failed to load map files %s (File doesnt exist in scriptfiles directory)!", file);

	LoadMapSettings(Maplist[index]);
	print("\n============================================");
	print("Currently loading....");
	printf("Mapname: %s", MapConfig[MAP_NAME]);
	printf("Author: %s", MapConfig[MAP_AUTHOR]);
	printf("Version: %s", MapConfig[MAP_VERSION]);
	print("============================================");

	printf("[MAP: %s] Map settings loaded!", MapConfig[MAP_NAME]);

	LoadMapDynamicObjects(MapConfig[MAP_CONFIGURATION_NAME]);

	

	return 1;
}
Код:
public OnGameModeInit()
{
	LoadMap(index_of_shipment_goes_here); 
        return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)