Official Soldat Forums

Server Talk => Scripting Releases => Topic started by: CarlHamilton on January 02, 2007, 03:26:35 pm

Title: Game: Russian Roulette
Post by: CarlHamilton on January 02, 2007, 03:26:35 pm
Script Name: Russian Roulette
Script Description: Shoot yourself in the head and die.
Original Author(s): CarlHamilton
Core Version: 2.5.2
Code:
Code: [Select]
const
scorefile= 'roulettescores.ini';
type
pnames= array[1..32] of string;
pscores= array[1..32] of integer;
gscores= array[1..4] of integer;
var
playernames: pnames;
playerscores: pscores;
globalscores: gscores;
recordholder: string;
latestdeath: string;
scores: string;
activated: boolean;
resetscores: boolean;
scoresarray: TStringArray;

function powerOf(a:integer;b:integer):integer;
var
t,i: integer;
begin
t:=1;
for i:=1 to b do begin
t:=t*a;
end;
result:= t;
end;

function rand(limit: integer):integer;
begin
result:= powerOf(strtoint(formatdate('zz')),3) mod limit;
end;

function loadscores():boolean;
var
count: integer;
begin
globalscores[1]:= strtoint(ReadINI(scorefile,'global','record','0'));
globalscores[2]:= strtoint(ReadINI(scorefile,'global','spins','0'));
globalscores[3]:= strtoint(ReadINI(scorefile,'global','deaths','0'));
globalscores[4]:= strtoint(ReadINI(scorefile,'global','percentage','0'));

recordholder:= ReadINI(scorefile,'global','recordholder','');
latestdeath:= ReadINI(scorefile,'global','latestdeath','');

for count:= 1 to NumPlayers do begin
playernames[count]:= IDToName(count);
playerscores[count]:= strtoint(ReadINI(scorefile,'players',IDToName(count),'0'));
end;

result:= true;
end;

function checkname(name: string):boolean;
var count: integer;
begin
for count:= 1 to ArrayHigh(playernames) do begin
if (ContainsString(playernames[count],name) and
(Length(playernames[count])=Length(name))) then begin
result:= true;
end;
end;
end;

function savescores():boolean;
var
count: integer;
nl,tempstring: string;
temparray: TStringArray;
begin
nl:= chr(13)+chr(10);

for count:= 0 to 7 do
case count of
0: scores:= '[global]' +nl;
1: scores:= scores +'record=' +inttostr(globalscores[count]) +nl;
2: scores:= scores +'spins=' +inttostr(globalscores[count]) +nl;
3: scores:= scores +'deaths=' +inttostr(globalscores[count]) +nl;
4: scores:= scores +'percentage=' +inttostr(globalscores[count]) +nl;
5: scores:= scores +'recordholder=' +recordholder +nl;
6: scores:= scores +'latestdeath=' +latestdeath +nl;
7: scores:= scores +'[players]' +nl;
end;

for count:= 1 to NumPlayers do
scores:= scores +playernames[count] +'=' +inttostr(playerscores[count]) +nl;

scoresarray:= split(ReadFile(scorefile),nl);

if (ArrayHigh(scoresarray)>7) then
for count:= 8 to ArrayHigh(scoresarray) do begin
tempstring:= scoresarray[count];
temparray:= split(tempstring,'=');
tempstring:= temparray[0];
if (not(checkname(tempstring))) then begin
scores:= scores +scoresarray[count];
end;
end;
WriteFile(scorefile,scores);
result:= true;
end;

function spin(name: string;bullets: byte):boolean;
var
randnum: integer;
begin
loadscores();
randnum:= (rand(6) +1);
globalscores[2]:= globalscores[2] +1;

if (bullets>=randnum) then
begin
Command('/say '+name+' picks up the gun, spins the chamber, and pulls the trigger...');

if (bullets=6) then
Command('/say Well aren''t you cute, hoping that''d work');

Command('/say BANG!!!!  SPLAT!! ('+inttostr(playerscores[NameToID(name)])+' points)');
Command('/kill '+inttostr(NameToID(name)));

playerscores[NameToID(name)]:= 0;
globalscores[3]:= globalscores[3] +1;
latestdeath:= name;
end;

if (bullets<randnum) then
begin
Command('/say '+name+' picks up the gun, spins the chamber, and pulls the trigger...');
Command('/say CLICK');
playerscores[NameToID(name)]:= playerscores[NameToID(name)] +(bullets*bullets);
end;

globalscores[4]:= (100* globalscores[3]/ globalscores[2]);

if (globalscores[1]< playerscores[NameToID(name)]) then
begin
globalscores[1]:= playerscores[NameToID(name)];
recordholder:= playernames[NameToID(name)];
Command('/say New record by '+playernames[NameToID(name)]+': '+inttostr(globalscores[1])+' spins in a row!');
end;
savescores();
result:= true;
end;

function showscores(name: string):boolean;
begin
Command('/say Record holder: '+recordholder+' with '+inttostr(globalscores[1])+' points');
Command('/say Total spins: '+inttostr(globalscores[2])+' Total deaths: '+inttostr(globalscores[3]));
Command('/say Death percentage: '+inttostr(globalscores[4])+'%  Latest death: '+latestdeath);
result:= true;
end;

procedure OnJoinTeam(IP, Nickname: string;Team: byte);
begin
playernames[NameToID(Nickname)]:= Nickname;
playerscores[NameToID(Nickname)]:= 0;
end;

procedure OnPlayerSpeak(Name,Text: string);
var
count: integer;
remote: string;
remotearray: TStringArray;
begin
if (activated=true) then begin
if ((Text='!spin') or (Text='!spin 1')) then
spin(Name,1)
else if (Text='!spin 2') then
spin(Name,2)
else if (Text='!spin 3') then
spin(Name,3)
else if (Text='!spin 4') then
spin(Name,4)
else if (Text='!spin 5') then
spin(Name,5)
else if (Text='!spin 6') then
spin(Name,6);

if (Text='!scores') then
showscores(Name);
end
else
if (Text='!spin') then
Command('/say The roulette game is deactivated, an admin can activate it with "!spin on"');

if (Text='!spin on') then begin
remote:= ReadFile('remote.txt');
remotearray:= split(remote,chr(13)+chr(10));
for count:= 0 to ArrayHigh(remotearray) do
if ((IPToID(remotearray[count])=NameToID(Name)) and (NameToID(Name)<>32)) then begin
Command('/say '+Name+' activated the russian roulette game')
activated:= true;
end;
end;
if (Text='!spin off') then begin
remote:= ReadFile('remote.txt');
remotearray:= split(remote,chr(13)+chr(10));
for count:= 0 to ArrayHigh(remotearray) do
if ((IPToID(remotearray[count])=NameToID(Name)) and (NameToID(Name)<>32)) then begin
Command('/say '+Name+' deactivated the russian roulette game')
activated:= false;
end;
end;

if (Text='!spin reset') then begin
remote:= ReadFile('remote.txt');
remotearray:= split(remote,chr(13)+chr(10));
for count:= 0 to ArrayHigh(remotearray) do begin
if ((IPToID(remotearray[count])=NameToID(Name)) and (NameToID(Name)<>32)) then begin
if (resetscores=false) then begin
Command('/say '+Name+', are you sure you want to reset the russian roulette scores?');
Command('/say Type "!spin reset" again to reset them');
resetscores:= true;
end
else if (resetscores=true) then begin
WriteFile(scorefile,'[global]'+chr(13)+chr(10)+'[players]'+chr(13)+chr(10));
Command('/say Scores reset by '+Name);
resetscores:= false;
end;
end;
end;
end;
end;
Edit:

Commands:
!spin = The default spin, 1/6 chance to die
!spin [N] = Custom number of bullets where [N] is a number from 1-6 *
!scores = Shows the current scores: Record holder and the record, total spins, total deaths and death percentage
!spin on = Turn on the script **
!spin off = Turn off the script **
!spin reset = Resets the scores **

* Note: More bullets = more points
1 bullet 1 point
2 bullets 4 points
3 bullets 9 points
And so on...
** Admins only (the IPs in remote.txt)

Important: The scores are saved in 'roulettescores.ini', you should make a file called that in the server folder, with two lines of text in it:
Code: [Select]
[global]
[players]

Known problems:
Changing teams resets your score

More improvement suggestions and bug reports welcome.
Thanks to cooz for his random script!
Title: Re: Game: Russian Roulette
Post by: Cube on January 02, 2007, 03:29:51 pm
what does it allow you to?
Title: Re: Game: Russian Roulette
Post by: cooz on January 02, 2007, 03:54:58 pm
good script, hehe

oh end tell me what's for this part in loadscores()
Code: [Select]
for count:= 1 to NumPlayers do begin
end;
;)
Title: Re: Game: Russian Roulette
Post by: Cube on January 02, 2007, 04:00:07 pm
still wonna know what it makes...
Title: Re: Game: Russian Roulette
Post by: Flippeh on January 02, 2007, 08:50:25 pm
You type !spin, and if a randum number is X, you die, and if its not, you're alive and get points.
Title: Re: Game: Russian Roulette
Post by: Terrordog on January 02, 2007, 11:51:59 pm
and where the hell do u add this ?
Title: Re: Game: Russian Roulette
Post by: jettlarue on January 03, 2007, 12:07:00 am
It's for if you run a server Terrordog, you run the file through the parser in the server.
Title: Re: Game: Russian Roulette
Post by: jrgp on January 03, 2007, 12:47:19 am
You type !spin, and if a randum number is X, you die, and if its not, you're alive and get points.

Ha, if that's what it does then I really like it.

I might implement it on mine, when I get the time.
Title: Re: Game: Russian Roulette
Post by: Eagles_Arrows on January 03, 2007, 06:58:10 pm
Cube, you've never heard of Russian Roulette (http://en.wikipedia.org/wiki/Russian_Roulette)? :(

Nice script, I'd like to try this out on some server. ;D
Title: Re: Game: Russian Roulette
Post by: cooz on January 03, 2007, 07:52:14 pm
Thanks to cooz for his excellent random script which made this possible! I'd applaud you but I haven't posted enough.  ;)

you know i love you anyway mate ; *
oh and and my random() function is rather noobish one hehe
Title: Re: Game: Russian Roulette
Post by: Sentroy on January 05, 2007, 07:47:22 pm
Nice script, i feel like trying the script :D,
Title: Re: Game: Russian Roulette
Post by: spidey on January 11, 2007, 06:07:42 am
i tried it, but i got this error


 
dule 'soldatserver.exe'. Read of address 00000000)
 


both on windows and linux....first time using the server side scripting, am i doing something wrong? :/
Title: Re: Game: Russian Roulette
Post by: CarlHamilton on January 11, 2007, 01:39:45 pm
Nope, that was a variable I forgot to take out when it wasn't needed any more.
Thanks for letting me know though, I'm sure there are a deal of weird stuff in this code, it's good if you let me know so that I can fix them.
It should now be working again.
Title: Re: Game: Russian Roulette
Post by: spidey on January 11, 2007, 03:09:15 pm
ok, a new error.


ule 'soldatserver.exe'. Read of address 00000000)
Title: Re: Game: Russian Roulette
Post by: CarlHamilton on January 11, 2007, 03:14:51 pm
You replaced the OnJoinTeam and OnPlayerSpeak procedures in your NetworkCore with those in the script right?
Title: Re: Game: Russian Roulette
Post by: spidey on January 11, 2007, 03:24:20 pm
ok..i replaced them with the ones in the script

 

sorry...still new to this :p took me forever to even get the hang on esa >.<
Title: Re: Game: Russian Roulette
Post by: CarlHamilton on January 11, 2007, 03:50:31 pm
You know what, I have no idea what is wrong since everything is working fine for me. Try replacing your NetworkCore.pas with this one (http://m00.laughingllamas.com/data/Pikkalaka/NetworkCore.pas) and see if it works. If it doesn't I'm clueless. :-X
Title: Re: Game: Russian Roulette
Post by: spidey on January 11, 2007, 03:55:26 pm
ahhh...ok that fixed networkcore.pas, but now there's a error in roulette.pas



Title: Re: Game: Russian Roulette
Post by: cooz on January 11, 2007, 04:25:38 pm
ahhh...ok that fixed networkcore.pas, but now there's a error in roulette.pas

  • Compiling Script roulette.pas...
  • [Error] (302:1): Duplicate identifier ''
oh yes, now you must have 2 same (procedures) variables ...somewhere