Author Topic: [beta] cResponse |updated:12.12.2006|  (Read 2856 times)

0 Members and 1 Guest are viewing this topic.

Offline cooz

  • Soldier
  • **
  • Posts: 187
  • BANNED
[beta] cResponse |updated:12.12.2006|
« on: December 12, 2006, 02:59:53 am »
Script Name: cResponse
Script Description: script allowing to automatic responses to our server (eg. "!site" could trigger "hxxp://www.mypage.com" answer)
Original Author: cooz
Core Version: 2.6

Code: [Select]
var
  tab,response,temp,res: tstringarray;
  i: integer;

function getMode(m: integer): string;
begin
  case m of
  0: result:= 'Death Match';
  1: result:= 'Point Match';
  2: result:= 'Team Match';
  3: result:= 'Capture The Flag';
  4: result:= 'Rambo Match';
  5: result:= 'Infiltration';
  6: result:= 'Hold The Flag';
  end;
end;

function getRate(pID: integer): string;
var k,d: integer;
begin
  //k:= GetPlayerStat(nametoid(Name),'Kills');
  //d:= GetPlayerStat(nametoid(Name),'Deaths');
  if d=0 then result:='0.0'
    else result:= inttostr(k/d);
end;

procedure ActivateServer();
begin
  tab:=split(ReadFile('cResponse.txt'),chr(13)+chr(10));
end;

procedure OnCommand(ID: integer;Text: string);
begin
  if Text='/reload_cresponse' then begin
    tab:=split(ReadFile('cResponse.txt'),chr(13)+chr(10));
    saytoplayer(ID,'cResponse.txt file was reloaded');
  end;
end;

procedure OnPlayerSpeak(Name,Text: string);
begin
   
  if Text='!commands' then begin
    saytoplayer(nametoid(Name),'available commands are:');
    for i:=0 to arrayhigh(tab)-1 do begin
      temp:= split(tab[i],'^a^');
      saytoplayer(nametoid(Name),temp[0]);
    end;
  end;

  if Text[1]='!' then begin
    for i:=0 to arrayhigh(tab)-1 do begin
      response := split(tab[i],'^a^');
      if Text=response[0] then begin
        //if(ContainsString(response[1],'$kills')=true)then
        //  response[1]:= StrReplace(response[1],'$kills',inttostr(GetPlayerStat(nametoid(Name),'Kills')));
        //if(ContainsString(response[1],'$deaths')=true)then
        //  response[1]:= StrReplace(response[1],'$deaths',inttostr(GetPlayerStat(nametoid(Name),'Deaths')));
        //if(ContainsString(response[1],'$rate')=true)then
        // response[1]:= StrReplace(response[1],'$rate',getRate(nametoid(Name))); 
        //if(ContainsString(response[1],'$ping')=true)then
        //  response[1]:= StrReplace(response[1],'$ping',inttostr(GetPlayerStat(nametoid(Name),'Ping')));
        //if(ContainsString(response[1],'$health')=true)then
        //  response[1]:= StrReplace(response[1],'$health',inttostr(GetPlayerStat(nametoid(Name),'Health')));
        //if(ContainsString(response[1],'$ip')=true)then
        //  response[1]:= StrReplace(response[1],'$ip',inttostr(GetPlayerStat(nametoid(Name),'IP')));
       
        if(ContainsString(response[1],'$name$')=true)then
          response[1]:= StrReplace(response[1],'$name$',Name);
        if(ContainsString(response[1],'$pid$')=true)then
          response[1]:= StrReplace(response[1],'$pid$',inttostr(nametoid(Name)));
 
        if(ContainsString(response[1],'$map$')=true)then
          response[1]:= StrReplace(response[1],'$map$',CurrentMap);
        if(ContainsString(response[1],'$nextmap$')=true)then
          response[1]:= StrReplace(response[1],'$nextmap$',NextMap);
       
        if(ContainsString(response[1],'$maxplayers$')=true)then
          response[1]:= StrReplace(response[1],'$maxplayers$',inttostr(MaxPlayers));
        if(ContainsString(response[1],'$numplayers$')=true)then
          response[1]:= StrReplace(response[1],'$numplayers$',inttostr(NumPlayers));
 
        if(ContainsString(response[1],'$timelimit$')=true)then
          response[1]:= StrReplace(response[1],'$timelimit$',inttostr(TimeLimit)); 
        if(ContainsString(response[1],'$timeleft$')=true)then
          response[1]:= StrReplace(response[1],'$timeleft$',inttostr(TimeLeft));
 
        if(ContainsString(response[1],'$scorelimit$')=true)then
          response[1]:= StrReplace(response[1],'$scorelimit$',inttostr(ScoreLimit));
        if(ContainsString(response[1],'$gamemode$')=true)then
          response[1]:= StrReplace(response[1],'$gamemode$',getMode(GameStyle));     
       
        if(ContainsString(response[1],'$serverver$')=true)then
          response[1]:= StrReplace(response[1],'$serverver$',ServerVersion);       
        if(ContainsString(response[1],'$servername$')=true)then
          response[1]:= StrReplace(response[1],'$servername$',ServerName);       
        if(ContainsString(response[1],'$serverport$')=true)then
          response[1]:= StrReplace(response[1],'$serverport$',inttostr(ServerPort));
        if(ContainsString(response[1],'$servertime$')=true)then
          response[1]:= StrReplace(response[1],'$servertime$',FormatDate('hh:nn:ss'));
 
        if(ContainsString(response[1],'$ascore$')=true)then
          response[1]:= StrReplace(response[1],'$ascore$',inttostr(AlphaScore));
        if(ContainsString(response[1],'$bscore$')=true)then
          response[1]:= StrReplace(response[1],'$bscore$',inttostr(BravoScore)); 
        if(ContainsString(response[1],'$cscore$')=true)then
          response[1]:= StrReplace(response[1],'$cscore$',inttostr(CharlieScore));
        if(ContainsString(response[1],'$dscore$')=true)then
          response[1]:= StrReplace(response[1],'$dscore$',inttostr(DeltaScore));
       
        if(ContainsString(response[1],'$aplayers$')=true)then
          response[1]:= StrReplace(response[1],'$aplayers$',inttostr(AlphaPlayers));
        if(ContainsString(response[1],'$bplayers$')=true)then
          response[1]:= StrReplace(response[1],'$bplayers$',inttostr(BravoPlayers));
        if(ContainsString(response[1],'$cplayers$')=true)then
          response[1]:= StrReplace(response[1],'$cplayers$',inttostr(CharliePlayers));
        if(ContainsString(response[1],'$dplayers$')=true)then
          response[1]:= StrReplace(response[1],'$dplayers$',inttostr(DeltaPlayers));
         
        if(ContainsString(response[1],'$ffire$')=true)then
          response[1]:= StrReplace(response[1],'$ffire$',ReadINI('soldat.ini','GAME','Friendly_Fire','error'));
        if(ContainsString(response[1],'$respawntime$')=true)then
          response[1]:= StrReplace(response[1],'$respawntime$',inttostr(strtoint(ReadINI('soldat.ini','GAME','Respawn_Time','error'))/60) ); 
        if(ContainsString(response[1],'$waverespawntime$')=true)then
          response[1]:= StrReplace(response[1],'$waverespawntime$',inttostr(strtoint(ReadINI('soldat.ini','GAME','WaveRespawn_Time','error'))/60) );
        if(ContainsString(response[1],'$bonusfreq$')=true)then
          response[1]:= StrReplace(response[1],'$bonusfreq$',ReadINI('soldat.ini','GAME','Bonus_Frequency','error'));
        if(ContainsString(response[1],'$votepercent$')=true)then
          response[1]:= StrReplace(response[1],'$votepercent$',ReadINI('soldat.ini','NETWORK','Vote_Percent','error'));
       
        res:= split(response[1],'^n^');
        for i:=0 to getarraylength(res) do begin
          if copy(res[i],1,4)='cmd:' then command(copy(res[i],5,length(res[i])))
            else saytoplayer(nametoid(Name),res[i]);
        end;
 
      end;
    end;
  end;
end;
notes:
this script is written for dedicated server v2.6 but i commented some lines and it should work also on v2.5.2 ;)
(only on windows servers cause of split())

server is holding his questions and answers in cResponse.txt file - so you should create it in server main dir

cResponse.txt syntax, commands has to begin with ! symbol, question and answer are divided with ^a^ symbol:
!question^a^answer
eg.
!site^a^http://yourpage.com

there's possible to give answers in multiple lines using ^n^ symbol eg.
!info^a^this is my server^n^good luck and have fun

also you can answer with in-game command (find them here: soldat manual) by putting on begin of answer cmd: letters, eg:
!map_Rok^a^cmd:/map Rok

and at last but not least place you can use server variables eg.
!info^a^You're on $servername$ Server

current list of supported variables:
$name$ - player nick
$pid$ - player id
$map$ - current map
$nextmap$ - next map
$maxplayers$ - maximum number of players
$numplayers$ - number of players
$timelimit$ - time limit in minutes
$timeleft$ - time left in seconds
$scorelimit$ - limit of scores
$gamemode$ - current game mode

$ffire$ - friendly fire on/off (0/1)
$respawntime$ - respown time in seconds
$waverespawntime$ - wave respown time in seconds
$bonusfreq$ - bonuses frequency
$%votepercent$ - percent for vote to accept it

$serverver$ - server version
$servername$ - server name
$serverport$ - server port
$servertime$ - current time on server

$ascore$ - number of alfa scores
$bscore$ - number of bravo scores
$cscore$ - number of charlie scores
$dscore$ - number of delta scores
$aplayers$ - number of players in alfa
$bplayers$ - number of players in bravo
$cplayers$ - number of players in charlie
$dplayers$ - number of players in delta

v2.6: (commented, and not working in current script version)
$kills$ - number of player kills
$deaths$ - number of player deaths
$rate$ - kills/deaths player rate
$ping$ - player ping
$health$ - player health
$ip$' - player ip

written on Leo request :)

this script still has beta status,
i would be gratefull for any suggestions or bug reports,
maybe you want some other variable added - no problem, post it here

edit:
12.12.2006
- added /reload_cresponse commands to reload cResponse.txt file
- modified script so every commands has to start with "!" symbol now, but script won't run some loop every time players say something
« Last Edit: December 12, 2006, 09:07:18 am by cooz »
Dead man! Dead man walking! We got a dead man walking here! Banned man crawling more like

Offline Leo

  • Soldat Beta Team
  • Veteran
  • ******
  • Posts: 1011
Re: [beta] cResponse
« Reply #1 on: December 12, 2006, 03:50:28 am »
Thx cooz, too bad we can't even beta test it until new server version is out :(

Offline cooz

  • Soldier
  • **
  • Posts: 187
  • BANNED
Re: [beta] cResponse
« Reply #2 on: December 12, 2006, 04:29:16 am »
on your windows server you still can test it,
as i wrote: i commented v2.6 code parts,
go ahead and try it :)

edit:
and let's hope this one won't have memory leaks,
but i doubt it :/ memory allocated too many times...
« Last Edit: December 12, 2006, 04:33:20 am by cooz »
Dead man! Dead man walking! We got a dead man walking here! Banned man crawling more like

Offline Frenchie

  • Camper
  • ***
  • Posts: 358
  • SoldatHQ
Re: [beta] cResponse
« Reply #3 on: December 12, 2006, 04:58:30 am »
Wow top stuff cooz  :),
This has to got be the best possible response script ever.
This is gonna make alot of people happy and will keep them busy customising it for their servers.

Good Job
Soldat Lobby Avec Players -New Release! - Updated AGAIN!


Offline cooz

  • Soldier
  • **
  • Posts: 187
  • BANNED
Re: [beta] cResponse
« Reply #4 on: December 12, 2006, 05:18:54 am »
thanks man :)

i hope this script will bite off some users of ARRSE to server scripts side ::)

it's probably not best response script cause i still can think up some imrovments,
and if enough people will request it, i can try to add some math operations
Dead man! Dead man walking! We got a dead man walking here! Banned man crawling more like

Offline Zero Ziat

  • Major(1)
  • Posts: 12
  • Why you bring that dog? It's gonna crap all over!
    • Zero Ziat's Crib
Re: [beta] cResponse |updated:12.12.2006|
« Reply #5 on: December 14, 2006, 10:07:51 pm »
Cool! Now I wish I had a better connection and that I wasn't THAT foreign...

I am Zero. I am uber.