[Tutorial] Newbie chat for RP or other.
#1


Hi there this is my first release
And i made this alone.
tell me how i can improve the code. or make i shorter

It's a simple newbie chat
Admin can write nonstop normal player need to wait 30 seconds.

Add this symbol and forward:
Код:
new NewbieTimer[MAX_PLAYERS];
forward NewbTimer(playerid);
OnPlayerConnect:
add
Код:
NewbieTimer[playerid] = 0;
This is the full command:
Код:
if(strcmp(cmd, "/newb", true) == 0)
{
	if(PlayerInfo[playerid][pMuted] == 1)
	{
		SendClientMessage(playerid, COLOR_GREY, "You are muted from the newbie chat channel.");
		return 1;
	}
	if(NewbieTimer[playerid] > 0)
	{
		format(string, sizeof(string), "You must wait %d between each message.", NewbieTimer[playerid]);
		SendClientMessage(playerid, COLOR_GREY, string);
		return 1;
	}
	new result[64];
	new length = strlen(cmdtext);
	new offset = idx;
	while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
	{
		result[idx - offset] = cmdtext[idx];
		idx++;
	}
	result[idx - offset] = EOS;
	if(!strlen(result))
	{
	SendClientMessage(playerid, COLOR_NEWBIE, "{33CCFF}USAGE:{FFFFFF} /newb [text]");
    return 1;
	}
	if(PlayerInfo[playerid][pAdmin] < 1)
	{
		NewbieTimer[playerid] = 30;
	}
	if(PlayerInfo[playerid][pAdmin]<1)
	{
		format(string, sizeof(string), "** Newbie %s: %s", GetPlayerNameEx(playerid), result);
	}
	if(PlayerInfo[playerid][pAdmin] == 1)
	{
		format(string, sizeof(string), "** Moderator %s: %s", GetPlayerNameEx(playerid), result);
	}
	if(PlayerInfo[playerid][pAdmin] >= 2)
	{
		format(string, sizeof(string), "** Admin %s: %s", GetPlayerNameEx(playerid), result);
	}
	foreach(Player, n)
	{
			SetTimer("NewbTimer", 25000, 0);
			SendClientMessage(n, COLOR_NEWBIE, string);
	}
	return 1;
}

This is the public for NewbTimer to wait 30 seconds.

Код:
public NewbTimer(playerid)
{
	NewbieTimer[playerid] = 0;
	return 1;
}
Hope it's good
Enjoy

Reply
#2

First off, this isn't a tutorial, you're just giving code. This could be placed in useful snippets at the least.

Second, the method you use isn't even that good, I suggest using a switch.

Good luck.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)