//===== rAthena Script =======================================
//= Message Man
//===== By: ==================================================
//= Vicious
//===== Current Version: =====================================
//= 1.0
//===== Compatible With: =====================================
//= rAthena SVN
//===== Description: =========================================
//= a message board where you can post and read messages
//===== Additional Comments: =================================
//= 
//============================================================

geffen,122,102,4	script	Message Man	774,{
	mes "[Robert]";
	mes "Hello, I am here to serve you. Enjoy my service. ^_-";
	next;
	mes "[Robert]";
	mes "Please keep in mind, that all messages are wiped once every two days";
	mes "-Msg From Creator- In new version this will be set able, look forward to this! -End Msg From Creator-";
	next;
L_Menu01:
	mes "[Robert]";
	mes "What would you like to do??";
	next;
	if((getgmlevel() >= 90)) menu "Public board",L_pubgmmenu,"Gm Board",L_gmmenu,"Close Public Board",L_clospub,"Open Public Board",L_openpub;
	if(($messagepubclose == 1)) goto L_pubclosed;
	menu "Read messages!",L_readmsg,"Post a message!",L_Postmsg,"Leave",L_leave;
L_pubgmmenu:
	if(($messagepubclose == 1)) goto L_pubclosed;
	menu "Re-set the rotation",L_setrot,"Reset Message",L_Clearmsgs,"Read messages!",L_readmsg,"Post a message!",L_Postmsg,"Leave",L_leave;
L_gmmenu:
	menu "Read messages!",L_gmboardread,"Post a Message!",L_gmboardpost,"Reset Messages",L_gmboardreset;

L_openpub:
	mes "[Robert]";
	mes "Are you sure?";
	menu "Yes",-,"No",L_openpubn;
	mes "[Robert]";
	mes "It is done.";
	close2;
	set $messagepubclose,0;
	end;

L_openpubn:
	mes "[Robert]";
	mes "Very well it shall remain closed.";
	close;

L_pubclosed:
	mes "[Robert]";
	mes "Im sorry. The public boards are currently Closed.";
	close;

L_clospub:
	mes "[Robert]";
	mes "Are you sure?";
	next;
	menu "Yes.",-,"No",L_closepubn;
	mes "[Robert]";
	mes "Very well I will not allow anyone into the public board.";
	close2;
	set $messagepubclose,1;
	end;

L_closepubn:
	mes "[Robert]";
	mes "Have a nice day";
	close;

L_gmboardreset:
	mes "[Robert]";
	mes "This will require atleast 2 GM's approval to reset the gm board.";
	mes "-Msg From Creator- This is bugged same gm can vote twice. Planned to revise in next version. -End Msg From Creator-";
	next;
	menu "Vote for reset.",L_gmboardresetvote,"Back to main.",L_Menu01,"Leave.",L_leave;

L_gmboardresetvote:
	callfunc "F_gmresetcheck";
	set @tempid,getcharid(0);
	set $gmboardresetvotenumb,$gmboardresetvotenumb+1;
	set $gmboardresetvoted[$gmboardresetvotenumb],1;
	set $gmboardresetvoteid[$gmboardresetvotenumb],@tempid;
	set @tempid,0;
	set $gmboardreset,$gmboardreset-1;
	mes "[Robert]";
	mes "Thank you.";
	next;
	if(($gmboardreset == 0)) goto L_gmresetdone;
	if(($gmboardreset >= 1)) goto L_gmresetnotdone;
	close;

L_gmresetdone:
	deletearray $gmmessageboardpost$[1],$gmmessageboardpostnumber;
	deletearray $gmmessageboardpostdate$[1],$gmmessageboardpostnumber;
	deletearray $gmmessageboardpostname$[1],$gmmessageboardpostnumber;
	deletearray $gmmessageboardeditdate$[1],$gmmessageboardpostnumber;
	deletearray $gmboardresetvoted[1],$gmboardresetvotenumber;
	deletearray $gmboardresetvoted[1],$gmboardresetvotenumber;
	deletearray $gmboardresetvoteid[1],$gmboardresetvotenumber;
	set $gmboardresetvotenumber,0;
	set $gmboardreset,2;
	mes "[Robert]";
	mes "The reset has been done.";
	close;

L_gmresetnotdone:
	mes "[Robert]";
	mes "There needs to be "+$gmboardreset+" more gm(s) approval to do the reset.";
	close;

L_gmboardread:
	if(($gmmessageboardpostnumber == 0)) goto L_msgno;
	callfunc "F_gmmessage";
	end;

L_gmboardpost:
	if(($gmmessageboardpostnumber >= 127)) goto L_postmsgyestm;
	set @gmmessageboardpostername$,strcharinfo(0);
	set @gmmessageboarddate$,gettimestr("%Y-%m/%d %H:%M:%S",21);
	set $gmmessageboardpostnumber,$gmmessageboardpostnumber+1;
	input @gmmsgboardmsgt$;
	set $gmmessageboardpost$[$gmmessageboardpostnumber],@gmmsgboardmsgt$;
	set $gmmessageboardpostdate$[$gmmessageboardpostnumber],@gmmessageboarddate$;
	set $gmmessageboardpostname$[$gmmessageboardpostnumber],@gmmessageboardpostername$;
	mes "[Robert]";
	mes "Here is what your message looks like";
	next;
	mes "Posted by: "+$gmmessageboardpostname$[$gmmessageboardpostnumber]+".";
	mes "On: "+$gmmessageboardpostdate$[$gmmessageboardpostnumber]+".";
	mes $gmmessageboardpost$[$gmmessageboardpostnumber];
	close;


L_setrot:
	set $@determinedayrotation,gettime(4); //this determines the day rotation for clearing messages.
	if(($@determinedayrotation == 0)) set $rotation,0;
	if(($@determinedayrotation == 1)) set $rotation,1;
	if(($@determinedayrotation == 2)) set $rotation,0;
	if(($@determinedayrotation == 3)) set $rotation,1;
	if(($@determinedayrotation == 4)) set $rotation,0;
	if(($@determinedayrotation == 5)) set $rotation,1;
	if(($@determinedayrotation == 6)) set $rotation,0;
	mes "It is done.";
	close;

L_Clearmsgs:
	mes "[Robert]";
	mes "Are you sure?";
	next;
	menu "Yes",L_clearmsgsy,"No thanks.",L_Menu01;

L_clearmsgsy:
	deletearray $messageboardpost$[1],$messageboardpostnumber;
	deletearray $messageboardpostdate$[1],$messageboardpostnumber;
	deletearray $messageboardpostname$[1],$messageboardpostnumber;
	deletearray $messageboardeditdate$[1],$messageboardpostnumber;
	deletearray $mymessage[1],$messageboardpostnumber;
	set $messageboardpostnumber,0;
	mes "[Robert]";
	mes "It is done.";
	close;

L_leave:
	close;

L_Postmsg:
	mes "[Robert]";
	mes "What do you want to say in your message?";
	next;
	set @msgboardmsgt$,0;
	input @msgboardmsgt$;
	mes "[Robert]";
	mes "are you sure this is the message you want?";
	mes @msgboardmsgt$;
	next;
	menu "Yes!",L_postmsgyes,"No let me re-do it!",L_Postmsg,"Ive changed my mind let me leave.",lleave;

L_postmsgyes:
	if(($messageboardpostnumber >= 127)) goto L_postmsgyestm;
	set @messageboardpostername$,strcharinfo(0);
	set @messageboarddate$,gettimestr("%Y-%m/%d %H:%M:%S",21);
	set $messageboardpostnumber,$messageboardpostnumber+1;
	set @mymessage2,$messageboardpostnumber;
	set $mymessage[$messageboardpostnumber],5;
	set $messageboardpost$[$messageboardpostnumber],@msgboardmsgt$;
	set $messageboardpostdate$[$messageboardpostnumber],@messageboarddate$;
	set $messageboardpostname$[$messageboardpostnumber],@messageboardpostername$;
	mes "[Robert]";
	mes "here is what your message looks like";
	next;
	mes "Posted by: "+$messageboardpostname$[$messageboardpostnumber]+".";
	mes "On: "+$messageboardpostdate$[$messageboardpostnumber]+".";
	mes $messageboardpost$[$messageboardpostnumber];
	close;

L_postmsgyestm:
	set @mesboardmsgt$,0;
	mes "[Robert]";
	mes "Im sorry your going to have to wait till more space opens up for messages, it should be in 1 or 2 days =)";
	close;

lleave:
	deletearray $messageboardpost$[@tempview],@tempview;
	deletearray $messageboardpostname$[@tempview],@tempview;
	deletearray $messageboardpostdate$[@tempview],@tempview;
	deletearray $mymessage[@tempview],@tempview;
	set $messageboardpostnumber,$messageboardpostnumber-1;
	set @msgboardmsgt$,0;
	close;

L_readmsg:
	if(($messageboardpostnumber == 0)) goto L_msgno;
	callfunc "F_message";
	end;

L_msgno:
	mes "[Robert]";
	mes "There are currently no messages.";
	close;

OnInit:
	set $gmboardreset,2;
	set $gmboardresetvotenumb,0;
	end;

OnInterIfInitOnce:
	set $@determinedayrotation,gettime(4); //this determines the day rotation for clearing messages.
	if(($@determinedayrotation == 0)) set $rotation,0;
	if(($@determinedayrotation == 1)) set $rotation,1;
	if(($@determinedayrotation == 2)) set $rotation,0;
	if(($@determinedayrotation == 3)) set $rotation,1;
	if(($@determinedayrotation == 4)) set $rotation,0;
	if(($@determinedayrotation == 5)) set $rotation,1;
	if(($@determinedayrotation == 6)) set $rotation,0;
	end;


OnSun1200:
	if(($rotation == 1)) end;
	deletearray $messageboardpost$[1],$messageboardpostnumber;
	deletearray $messageboardpostdate$[1],$messageboardpostnumber;
	deletearray $messageboardpostname$[1],$messageboardpostnumber;
	deletearray $mymessage[1],$messageboardpostnumber;
	set $messageboardpostnumber,0;
	end;

OnSat1200:
	if(($rotation == 0)) end;
	deletearray $messageboardpost$[1],$messageboardpostnumber;
	deletearray $messageboardpostdate$[1],$messageboardpostnumber;
	deletearray $messageboardpostname$[1],$messageboardpostnumber;
	deletearray $mymessage[1],$messageboardpostnumber;
	set $messageboardpostnumber,0;
	end;

OnMon1200:
	if(($rotation == 1)) end;
	deletearray $messageboardpost$[1],$messageboardpostnumber;
	deletearray $messageboardpostdate$[1],$messageboardpostnumber;
	deletearray $messageboardpostname$[1],$messageboardpostnumber;
	deletearray $mymessage[1],$messageboardpostnumber;
	set $messageboardpostnumber,0;
	end;

OnTue1200:
	if(($rotation == 0)) end;
	deletearray $messageboardpost$[1],$messageboardpostnumber;
	deletearray $messageboardpostdate$[1],$messageboardpostnumber;
	deletearray $messageboardpostname$[1],$messageboardpostnumber;
	deletearray $mymessage[1],$messageboardpostnumber;
	set $messageboardpostnumber,0;
	end;

OnWed1200:
	if(($rotation == 1)) end;
	deletearray $messageboardpost$[1],$messageboardpostnumber;
	deletearray $messageboardpostdate$[1],$messageboardpostnumber;
	deletearray $messageboardpostname$[1],$messageboardpostnumber;
	deletearray $mymessage[1],$messageboardpostnumber;
	set $messageboardpostnumber,0;
	end;

OnThu1200:
	if(($rotation == 0)) end;
	deletearray $messageboardpost$[1],$messageboardpostnumber;
	deletearray $messageboardpostdate$[1],$messageboardpostnumber;
	deletearray $messageboardpostname$[1],$messageboardpostnumber;
	deletearray $mymessage[1],$messageboardpostnumber;
	set $messageboardpostnumber,0;
	end;

OnFri1200:
	if(($rotation == 1)) end;
	deletearray $messageboardpost$[1],$messageboardpostnumber;
	deletearray $messageboardpostdate$[1],$messageboardpostnumber;
	deletearray $messageboardpostname$[1],$messageboardpostnumber;
	deletearray $mymessage[@tempview],@tempview;
	set $messageboardpostnumber,0;
	end;
}

function	script	F_gmresetcheck	{
	set @tempcheck,0;
L_top:
	set @tempcheck,@tempcheck+1;
	if(($gmboardresetvoted[@tempview] == 1)) goto L_votecheck;
	if(($gmboardresetvoted[@tempview] == 0)) return;
	goto L_top;
	end;
L_votecheck:
	set @tempcheckid,0;
	set @tempcheckid,getcharid(0);
	if(($gmboardresetvoteid[@tempview] != @tempcheckid)) goto L_top;
	if(($gmboardresetvoteid[@tempview] == @tempcheckid)) goto L_voted;
	end;
}

function	script	F_gmmessage	{
	set @tempview,0;
L_top:
	set @tempview,@tempview+1;
	mes "Posted By: "+$gmmessageboardpostname$[@tempview]+".";
	mes "On: "+$gmmessageboardpostdate$[@tempview]+".";
	mes $gmmessageboardpost$[@tempview]+".";
	menu "Next Message",L_top2;
L_top2:
	if(($gmmessageboardpostnumber > @tempview)) goto L_top;
	close;
}

function	script	F_message	{
	set @tempview,0;
L_top:
	set @tempview,@tempview+1;
	mes "Posted By: "+$messageboardpostname$[@tempview]+".";
	mes "On: "+$messageboardpostdate$[@tempview]+".";
	mes $messageboardpost$[@tempview]+".";
	next;
	if(($mymessage[@tempview] == 5) && (getgmlevel()>0)) menu "Next Message",L_top2,"Delete My Message",L_delmy,"Edit my message",L_editmy,"Delete This message",L_Del;
	if((getgmlevel()>0))  menu "Next Message",L_top2,"Delete This message",L_Del;
	if(($mymessage[@tempview] == 5)) menu "Next Message",L_top2,"Delete My Message",L_delmy,"Edit my message",L_editmy;
	menu "Next message",L_top2;
	close;

L_editmy:
	mes "Are you sure?";
	next;
	menu "Yes",L_editmyy,"No",L_editmyn;

L_editmyy:
	mes "what do you want your new message to be?";
	next;
	mes "Current message!";
	mes $messageboardpost$[@tempview];
	set @tempeditmsg$,0;
	input @tempeditmsg$;
	next;
	mes "is this what you want?";
	mes @tempeditmsg$;
	next;
	menu "Yes!",L_editmyyy,"No.",L_editmyyn;

L_editmyyy:
	deletearray $messageboardpost$[@tempview],@tempview;
	set $messageboardpost$[@tempview],@tempeditmsg$;
	mes "Here is what your new message looks like.";
	next;
	mes "Posted By: "+$messageboardpostname$[@tempview]+".";
	mes "On: "+$messageboardpostdate$[@tempview]+".";
	mes $messageboardpost$[@tempview]+".";
	close2;
	set @tempview,0;
	end;

L_editmyn:
	Mes "So be it.";
	set @tempview,0;
	close;

L_editmyyn:
	mes "So be it!";
	set @tempeditmsg$,0;
	set @tempview,0;
	close;

L_delmy:
	mes "Are you sure...?";
	next;
	menu "Yes",L_delmyy,"No thanks.",L_delmyn;

L_delmyy:
	deletearray $messageboardpost$[@tempview],@tempview;
	deletearray $messageboardpostname$[@tempview],@tempview;
	deletearray $messageboardpostdate$[@tempview],@tempview;
	deletearray $mymessage[@tempview],@tempview;
	deletearray $messageboardeditdate$[@tempview],@tempview;
	set $messageboardpostnumber,$messageboardpostnumber-1;
	set @tempview,0;
	mes "It is done.";
	close;

L_delmyn:
	mes "Come back soon.";
	set @tempview,0;
	close;

L_top2:
	if(($messageboardpostnumber > @tempview)) goto L_top;
	close;

L_Del:
	mes "Are you sure?";
	next;
	menu "Yes",L_Dely,"No",L_Deln;

L_Dely:
	deletearray $messageboardpost$[@tempview],@tempview;
	deletearray $messageboardpostname$[@tempview],@tempview;
	deletearray $messageboardpostdate$[@tempview],@tempview;
	deletearray $mymessage[@tempview],@tempview;
	deletearray $messageboardeditdate$[@tempview],@tempview; 
	set $messageboardpostnumber,$messageboardpostnumber-1;
	mes "It is done.";
	set @tempview,0;
	close;

L_Deln:
	mes "Come back soon!";
	set @tempview,0;
	close;
}
