0 Members and 1 Guest are viewing this topic.
varwarns: array[1..32] of byte;warningfile: TStringArray;warning_number: integer;//This is the new fancy function we're gonna use; xsplit - made by KeYDoN.function xsplit(const source: string; const delimiter: string):TStringArray;vari,x,d:integer;s:string;begind:=length(delimiter);x:=0;i:=1;SetArrayLength(Result,1);while(i<=length(source)) do begin s:=Copy(source,i,d); if(s=delimiter) then begin inc(i,d); inc(x,1); SetArrayLength(result,x+1); end else begin result[x]:= result[x]+Copy(s,1,1); inc(i,1); end;end;end;procedure ActivateServer();begin//Load the contents of warns.txt and split it into an arraywarningfile:=xsplit(ReadFile('scripts/warns.txt'),#13+#10);//Store the number of lines for later use.warning_number:=GetArrayLength(warningfile)-1;end;function OnCommand(ID: Byte; Text: string):boolean;varw,i,warnkicks: byte;found: boolean;writestring: string;beginResult:=false;if GetPiece(LowerCase(Text),' ',0) = '/warn' then begin try w:=strtoint(GetPiece((Text), ' ', 1)); except exit; end; warns[w]:=warns[w]+1; SayToPlayer(w,'You have been warned by admin, warnings: '+inttostr(warns[w])); SayToPlayer(w,'Warns until warn kick: '+inttostr(5-warns[w])); if warns[w]=5 then begin found:=false; //Loop through all the lines in the file. for i:=0 to warning_number do //In the file we're going to store data structured as <player IP><ascii char 1 = #1><number of warnings><#13><#10>. //So get the first piece containing the player IP. if GetPiece(warningfile[i],#1,0)=GetPlayerStat(w,'ip') then begin //Yep, we found it. found:=true; //Update the existing entry. warnkicks:=strtoint(GetPiece(warningfile[i],#1,1))+1; warningfile[i]:=GetPiece(warningfile[i],#1,0)+#1+inttostr(warnkicks); break; end; if found=false then begin //Right, we didn't find it. Increase the size of the array... warning_number:=warning_number+1; SetArrayLength(warningfile,warning_number+1); //... and add the new warning data to it. warnkicks:=1; warningfile[warning_number]:=GetPlayerStat(w,'ip')+#1+'1'; end; //Kick/ban the player, and giggle afterwards. if warnkicks=5 then begin SayToPlayer(w,'You have been banned for 4320 minutes (3 days)'); SayToPlayer(w,'Try not to get warned so much, please'); BanPlayer(w,4320); warnkicks:=strtoint(GetPiece(warningfile[i],#1,1))-5; warningfile[i]:=GetPiece(warningfile[i],#1,0)+#1+inttostr(warnkicks); end else begin SayToPlayer(w,'You have been warn kicked, Warn kicks: '+inttostr(warnkicks)); SayToPlayer(w,'Warn kicks left until 3-day ban: '+inttostr(5-warnkicks)); KickPlayer(w); end; //And write everything back to the file. Smooth! writestring:=''; for i:=0 to warning_number do writestring:=writestring+warningfile[i]+#13+#10; WriteFile('scripts/warns.txt',writestring); end; end;end;procedure OnLeaveGame(ID, Team: byte; Kicked: boolean);beginwarns[ID]:=0; Command('/say Warn script by Kavukamari, Script fixed/debuged by Toumaz');end;procedure OnJoinGame(ID, Team: byte);begin Command('/say Warn script by Kavukamari, Script fixed/debuged by Toumaz');end;
INI:=strtoint(INI)+1
INI:=ReadINI('Scripts/Warn/Warns.ini','Warn Kicked',IDToIP(w),'0');
if (ContainsString(INI,IDToIP(w)) = true) then begin
if (ContainsString(INI,IDToIP(w)) <> true) then begin
KickPlayer(w);SayToPlayer(w,'You have been warn kicked, Warn kicks: '+INI);SayToPlayer(w,'Warn kicks left until 3-day ban: '+inttostr(5-strtoint(INI)));
if (strtoint(INI) = 5) then begin BanPlayer(w,4320); SayToPlayer(w,'You have been banned for 4320 minutes (3 days)'); SayToPlayer(w,'Try not to get warned so much, please');end;
varwarns: array[1..32] of byte;warnkicks: byte;function OnCommand(ID: Byte; Text: string):boolean;varw: Byte;beginResult:=false;if GetPiece(LowerCase(Text),' ',0) = '/warn' then begin try w:=strtoint(GetPiece((Text), ' ', 1)); except exit; end; warns[w]:=warns[w]+1; SayToPlayer(w,'You have been warned by admin, warnings: '+inttostr(warns[w])); SayToPlayer(w,'Warns until warn kick: '+inttostr(5-warns[w])); if warns[w]=5 then begin warnkicks:=strtoint(ReadINI('Scripts/Warn/Warns.ini','Warn Kicked',GetPlayerStat(w,'ip'),'0'))+1; //Stuff will break in so many ways with storing data in the .ini files. Hell, it won't work at all. Use Xsplit and manual loops to store the data instead. WriteLnFile('scripts/warns.ini',IDToIP(w)+'='+inttostr(warnkicks)); if warnkicks=5 then begin SayToPlayer(w,'You have been banned for 4320 minutes (3 days)'); SayToPlayer(w,'Try not to get warned so much, please'); BanPlayer(w,4320); end else begin SayToPlayer(w,'You have been warn kicked, Warn kicks: '+inttostr(warnkicks)); SayToPlayer(w,'Warn kicks left until 3-day ban: '+inttostr(5-warnkicks)); KickPlayer(w); end; end; end;end;procedure OnLeaveGame(ID, Team: byte; Kicked: boolean);beginwarns[ID]:=0;end;
and why doesn't INI's work?
how? (how do I use XSplit)
varwarns: array[1..32] of byte;warningfile: TStringArray;warning_number: integer;//This is the new fancy function we're gonna use; xsplit - made by KeYDoN.function xsplit(const source: string; const delimiter: string):TStringArray;vari,x,d:integer;s:string;begind:=length(delimiter);x:=0;i:=1;SetArrayLength(Result,1);while(i<=length(source)) do begin s:=Copy(source,i,d); if(s=delimiter) then begin inc(i,d); inc(x,1); SetArrayLength(result,x+1); end else begin result[x]:= result[x]+Copy(s,1,1); inc(i,1); end;end;end;procedure ActivateServer();begin//Load the contents of warns.txt and split it into an arraywarningfile:=xsplit(ReadFile('scripts/warns.txt'),#13+#10);//Store the number of lines for later use.warning_number:=GetArrayLength(warningfile)-1;end;function OnCommand(ID: Byte; Text: string):boolean;varw,i,warnkicks: byte;found: boolean;writestring: string;beginResult:=false;if GetPiece(LowerCase(Text),' ',0) = '/warn' then begin try w:=strtoint(GetPiece((Text), ' ', 1)); except exit; end; warns[w]:=warns[w]+1; SayToPlayer(w,'You have been warned by admin, warnings: '+inttostr(warns[w])); SayToPlayer(w,'Warns until warn kick: '+inttostr(5-warns[w])); if warns[w]=5 then begin found:=false; //Loop through all the lines in the file. for i:=0 to warning_number do //In the file we're going to store data structured as <player IP><ascii char 1 = #1><number of warnings><#13><#10>. //So get the first piece containing the player IP. if GetPiece(warningfile[i],#1,0)=GetPlayerStat(w,'ip') then begin //Yep, we found it. found:=true; //Update the existing entry. warnkicks:=strtoint(GetPiece(warningfile[i],#1,1))+1; warningfile[i]:=GetPiece(warningfile[i],#1,0)+#1+inttostr(warnkicks); break; end; if found=false then begin //Right, we didn't find it. Increase the size of the array... warning_number:=warning_number+1; SetArrayLength(warningfile,warning_number+1); //... and add the new warning data to it. warnkicks:=1; warningfile[warning_number]:=GetPlayerStat(w,'ip')+#1+'1'; end; //Kick/ban the player, and giggle afterwards. if warnkicks=5 then begin SayToPlayer(w,'You have been banned for 4320 minutes (3 days)'); SayToPlayer(w,'Try not to get warned so much, please'); BanPlayer(w,4320); end else begin SayToPlayer(w,'You have been warn kicked, Warn kicks: '+inttostr(warnkicks)); SayToPlayer(w,'Warn kicks left until 3-day ban: '+inttostr(5-warnkicks)); KickPlayer(w); end; //And write everything back to the file. Smooth! writestring:=''; for i:=0 to warning_number do writestring:=writestring+warningfile[i]+#13+#10; WriteFile('scripts/warns.txt',writestring); end; end;end;procedure OnLeaveGame(ID, Team: byte; Kicked: boolean);beginwarns[ID]:=0;end;