All pastes #104552 Raw Edit

Y_Less

public text v1 · immutable
#104552 ·published 2006-07-28 23:56 UTC
rendered paste body
#include <a_samp>
#include <core>

#define DELAY_TIME 30000
#define FILE_NAME "Y_Messages.txt"

new gDelay = DELAY_TIME;

new gLastCall = 0;

public OnFilterScriptInit()
{
	// Do my usual fancy stuff here
	print("\r\n====================================");
	print("|                                  |");
	print("|     YMessage Announcer System    |");
	print("|     -------------------------    |");
	print("|                                  |");
	print("| By Alex \"Y_Less\" Cole - (c) 2006 |");
	print("|               v0.3               |");
	print("====================================\r\n");

	ShowRandomMessage(false);

	new h, m, s;
	gettime(h, m, s);

	gLastCall = ((h * 3600) + (m * 60) + s) * 1000;

	//printf("%d, %d", gLastCall, gDelay);

	return 0;
}

public OnPlayerConnect(playerid)
{
	CheckRand();
	return 0;
}

CheckRand()
{
	new h, m, s;
	gettime(h, m, s);

	h = ((h * 3600) + (m * 60) + s) * 1000;
	//printf("%d, %d", h, h - gLastCall);

	if (((h < gDelay) && (((h + 86400000) - gLastCall) > gDelay)) || ((h - gLastCall) > gDelay))
	{
		ShowRandomMessage();
		gLastCall = h;
	}
}

ShowRandomMessage(a = true)
{
	new text[512];
	new num, index;
	new File:yfile;
	//print("go");

	if (fexist(FILE_NAME))
	{
	    if ((yfile = fopen(FILE_NAME, io_read)))
		{
	    fread(yfile, text);
	    num = strval(strtok(text, index));

	    if (a)
	    {
		    num = random(num);
		    index = 0;
			while ((fread(yfile, text)) && (index <= num))
			{
				if (text[0] == '}')
			    {
			        index++;
			    }
			    else if ((index == num) && (text[0] != '{'))
			    {
					SendClientMessageToAll(0x00FF00FF, text);
			    }
			}
		}
		else
		{
			gDelay = strval(strtok(text, index));
		}

		fclose(yfile);
	}
	else
	{
		print("yAd Error: Could not open file, please ensure you have a scriptfiles directory");
	}
	}
	else
	{
	    print("yAd Error: Messages file not found");
	}
}

public strtok(const string[], &index)
{
	new length = strlen(string);
	while ((index < length) && (string[index] <= ' '))
	{
		index++;
	}

	new offset = index;
	new result[32];
	while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof (result) - 1)))
	{
		result[index - offset] = string[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}

public OnPlayerRequestClass(playerid, classid)
{
	CheckRand();
	return 0;
}

public OnPlayerDisconnect(playerid)
{
	CheckRand();
	return 0;
}

public OnPlayerSpawn(playerid)
{
	CheckRand();
	return 0;
}

public OnPlayerDeath(playerid, killerid, reason)
{
	CheckRand();
	return 0;
}

public OnVehicleSpawn(vehicleid)
{
	CheckRand();
	return 0;
}

public OnVehicleDeath(vehicleid, killerid)
{
	CheckRand();
	return 0;
}

public OnPlayerText(playerid)
{
	CheckRand();
	return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
	CheckRand();
	return 0;
}

public OnPlayerInfoChange(playerid)
{
	CheckRand();
	return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	CheckRand();
	return 0;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
	CheckRand();
	return 0;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
	CheckRand();
	return 0;
}

public OnPlayerEnterCheckpoint(playerid)
{
	CheckRand();
	return 0;
}

public OnPlayerLeaveCheckpoint(playerid)
{
	CheckRand();
	return 0;
}