Working on It
EDIT :
Done
You will need
- ZCMD (or you may convert the command to other processor)
- sscanf
WORKING
Add this to top
Yes this is an include file.
STOCKS
pawn Код:
native Load();
native End();
native ShowNoticeForPlayer(playerid);
native ShowNoticeForAll();
native SetNotice(msg[],playerid=-1);
Add Load() under OngameModeInIt() or maybe under OnFilterScriptInit()
Add End() under OnGameModeExit() or under OnFilterScriptExit()
Load basically load's up the textdraws and End destroy's them.
SetNotice(msg[],playerid=-1)
Here playerid is optional parameter.
It is only used if you want to SendClientMessage that he was able to change notice or not.
pawn Код:
//Example
SetNotice("This is notice Text");
//Set's notice text to "This is notice Text"
ShowNoticeForPlayer(playerid)
It shows the notice for a playerid
pawn Код:
public OnPlayerConnect(playerid)
{
ShowNoticeForPlayer(playerid);
}
Similar is the working for ShowNoticeForAll();
It will show notice to all players connected.
Some Defines
pawn Код:
#define NoticePath "/Server/notice.ini"
#define MAX_NL 128
NoticePath is the directory where the notice is stored.
MAX_NL is Maximum Length of Notice which is by default at 128.
CODE
pawn Код:
/*native Load();
native End();
native ShowNoticeForPlayer(playerid);
native ShowNoticeForAll();
native SetNotice(msg[],playerid=-1);
*/
#define NoticePath "/Server/notice.ini"
#define MAX_NL 128
new Text:TextdrawNotice;
new Text:TextdrawBack;
new Text:ins;
new notice[MAX_NL];
new bool:changed = false;
new on[MAX_PLAYERS] = -1;
#define PRESSED(%0) \
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
stock Load()
{
TextdrawNotice = TextDrawCreate(280.000000, 184.000000, "This is a new Text");
TextDrawAlignment(TextdrawNotice, 2);
TextDrawBackgroundColor(TextdrawNotice, 255);
TextDrawFont(TextdrawNotice, 1);
TextDrawLetterSize(TextdrawNotice, 0.400000, 3.000000);
TextDrawColor(TextdrawNotice, -16776961);
TextDrawSetOutline(TextdrawNotice, 1);
TextDrawSetProportional(TextdrawNotice, 1);
TextdrawBack = TextDrawCreate(0.000000, 0.000000, "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~");
TextDrawBackgroundColor(TextdrawBack, 255);
TextDrawFont(TextdrawBack, 1);
TextDrawLetterSize(TextdrawBack, 0.500000, 3.099999);
TextDrawColor(TextdrawBack, -1);
TextDrawSetOutline(TextdrawBack, 0);
TextDrawSetProportional(TextdrawBack, 1);
TextDrawSetShadow(TextdrawBack, 1);
TextDrawUseBox(TextdrawBack, 1);
TextDrawBoxColor(TextdrawBack, 200);
TextDrawTextSize(TextdrawBack, 651.000000, 40.000000);
ins = TextDrawCreate(17.000000, 374.000000, "Press ENTER button to dismiss.");
TextDrawFont(ins, 1);
TextDrawLetterSize(ins, 0.249999, 1.000000);
TextDrawColor(ins, 0xFFFFFFFF);
TextDrawSetProportional(ins, 1);
TextDrawSetShadow(ins, 1);
new File:f = fopen(NoticePath, io_read);
fread(f,notice,MAX_NL);
fclose(f);
return 1;
}
stock End()
{
TextDrawDestroy(TextdrawNotice);
TextDrawDestroy(TextdrawBack);
TextDrawDestroy(ins);
return 1;
}
stock SetNotice(msg[],playerid=-1)
{
if(playerid!=-1)
{
if(msg[0] == '0' && msg[1] == '\0')
{
SendClientMessage(playerid,-1,"Notice has been disabled.");
}
else
{
SendClientMessage(playerid,-1,"Notice has been changed.");
}
}
new File:f = fopen(NoticePath, io_write);
fwrite(f,msg);
fclose(f);
changed = true;
return 1;
}
stock ShowNoticeForPlayer(playerid)
{
if(changed == true)
{
new File:f = fopen(NoticePath, io_read);
fread(f,notice,MAX_NL);
fclose(f);
}
if((notice[0] == '0' && notice[1] == '\0') || notice[1] == '\0') return printf("Unable to show notice for %d as notice is disabled",playerid);
on[playerid] = 1;
TextDrawSetString(TextdrawNotice,notice);
TextDrawShowForPlayer(playerid,TextdrawBack);
TextDrawShowForPlayer(playerid,ins);
TextDrawShowForPlayer(playerid,TextdrawNotice);
TogglePlayerSpectating(playerid,true);
changed = false;
return 1;
}
stock ShowNoticeForAll()
{
if(changed == true)
{
new File:f = fopen(NoticePath, io_read);
fread(f,notice,MAX_NL);
fclose(f);
}
if((notice[0] == '0' && notice[1] == '\0') || notice[1] == '\0') return printf("Unable to show notice for %d as notice is disabled",playerid);
for(new playerid = 0;playerid<MAX_PLAYERS;++playerid)
{
if(!IsPlayerConnected(playerid)) continue;
on[playerid] = 1;
TextDrawSetString(TextdrawNotice,notice);
TextDrawShowForPlayer(playerid,TextdrawBack);
TextDrawShowForPlayer(playerid,ins);
TextDrawShowForPlayer(playerid,TextdrawNotice);
TogglePlayerSpectating(playerid,true);
}
changed = false;
return 1;
}
CMD:setnotice(playerid,params[])
{
// if(!IsPlayerAdmin(playerid)) return 0; //You may even add your admin variables
new msg[MAX_NL];
if(sscanf(params,"s[MAX_NL]",msg)) return SendClientMessage(playerid,-1,"Usage : /setnotice [MESSAGE]");
SetNotice(msg,playerid);
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(on[playerid] == 1)
{
if(PRESSED(KEY_SECONDARY_ATTACK))
{
TextDrawHideForPlayer(playerid,TextdrawNotice);
TextDrawHideForPlayer(playerid,TextdrawBack);
TextDrawHideForPlayer(playerid,ins);
on[playerid] = -1;
TogglePlayerSpectating(playerid,false);
}
}
return 0;
}