All pastes #975940 Raw Edit

Stuff

public text v1 · immutable
·published 2008-04-07 21:06 UTC
rendered paste body
#include <a_samp>

#define FILTERSCRIPT
#if defined FILTERSCRIPT

new Line[MAX_PLAYERS];
new OnOff[MAX_PLAYERS];

public OnFilterScriptInit()
{
	print("----------------------");
	print(" Radio line v1 loaded ");
	print("----------------------");
	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}

#endif

public OnPlayerCommandText(playerid, cmdtext[])
{
	new string[100];
	new cmd[256], idx;
	cmd = strtok(cmdtext, idx);
	new tmp[256];
	new id;
	
	if(!strcmp("/r", cmd, true))
	{
		if(OnOff[playerid] == 1)
		{
			SendClientMessage(playerid, 0x2641FEAA, "Your radio is off");
		}
		else
		{
			for(new i = 0; i < MAX_PLAYERS; i++)
			{
				if(IsPlayerConnected(i))
				{
					if(Line[i] == Line[playerid])
					{
					    if(OnOff[i] == 0)
					    {
							new pname[26];
							GetPlayerName(playerid, pname, sizeof(pname));
							format(string, 256, "(radio %d) %s: %s", Line, pname, cmdtext[3]);
							SendClientMessage(i, 0x2641FEAA, string);
						}
					}
				}
			}
		}
		return 1;
	}
	
	if (strcmp("/cl", cmd, true) == 0)
	{
		tmp = strtok(cmdtext, idx);
		if(!strlen(tmp)) return SendClientMessage(playerid, 0x2641FEAA, "You didn't put in a line");
		id = strval(tmp);
		
		if(id >= 101 || id <= -1)
		{
			SendClientMessage(playerid, 0x2641FEAA, "Only lines 0 to 100 are susported");
		}
		else
		{
			Line[playerid] = id;
			format(string, 256, "Your radio line has been set to %d", id);
			SendClientMessage(playerid, 0x2641FEAA, string);
		}
		return 1;
	}
	
	if (strcmp("/ron", cmdtext, true) == 0)
	{
		SendClientMessage(playerid, 0x2641FEAA, "You have turned your radio on");
		OnOff[playerid] = 0;
		return 1;
	}
	if (strcmp("/roff", cmdtext, true) == 0)
	{
		SendClientMessage(playerid, 0x2641FEAA, "You have turned your radio off");
		OnOff[playerid] = 1;
		return 1;
	}
	return 0;
}

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

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