Author Topic: Game: Russian Roulette  (Read 5757 times)

0 Members and 1 Guest are viewing this topic.

Offline CarlHamilton

  • Major(1)
  • Posts: 29
Game: Russian Roulette
« 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!
« Last Edit: January 11, 2007, 01:36:43 pm by CarlHamilton »

Offline Cube

  • Camper
  • ***
  • Posts: 314
  • Go Cube go!
    • Cube&amp;#039;s Portal
Re: Game: Russian Roulette
« Reply #1 on: January 02, 2007, 03:29:51 pm »
what does it allow you to?
Hmm, any idea what to write here?

Offline cooz

  • Soldier
  • **
  • Posts: 187
  • BANNED
Re: Game: Russian Roulette
« Reply #2 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;
;)
Dead man! Dead man walking! We got a dead man walking here! Banned man crawling more like

Offline Cube

  • Camper
  • ***
  • Posts: 314
  • Go Cube go!
    • Cube&amp;#039;s Portal
Re: Game: Russian Roulette
« Reply #3 on: January 02, 2007, 04:00:07 pm »
still wonna know what it makes...
Hmm, any idea what to write here?

Offline Flippeh

  • Major
  • *
  • Posts: 58
  • Fish go moo :>
    • My Homepage
Re: Game: Russian Roulette
« Reply #4 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.

Offline Terrordog

  • Major(1)
  • Posts: 40
Re: Game: Russian Roulette
« Reply #5 on: January 02, 2007, 11:51:59 pm »
and where the hell do u add this ?

Offline jettlarue

  • Flagrunner
  • ****
  • Posts: 724
Re: Game: Russian Roulette
« Reply #6 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.

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5029
Re: Game: Russian Roulette
« Reply #7 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.
There are other worlds than these

Offline Eagles_Arrows

  • Veteran
  • *****
  • Posts: 1889
  • The Thread Killer
    • My Webcomic
Re: Game: Russian Roulette
« Reply #8 on: January 03, 2007, 06:58:10 pm »
Cube, you've never heard of Russian Roulette? :(

Nice script, I'd like to try this out on some server. ;D
« Last Edit: January 03, 2007, 06:59:50 pm by Eagles_Arrows »

"Sometimes it's a good day to die, sometimes it's a good day to have breakfast." - Smoke Signals

Offline cooz

  • Soldier
  • **
  • Posts: 187
  • BANNED
Re: Game: Russian Roulette
« Reply #9 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
Dead man! Dead man walking! We got a dead man walking here! Banned man crawling more like

Offline Sentroy

  • Major(1)
  • Posts: 6
Re: Game: Russian Roulette
« Reply #10 on: January 05, 2007, 07:47:22 pm »
Nice script, i feel like trying the script :D,
Your signature is too large, please read the forum rules.

Offline spidey

  • Major(1)
  • Posts: 5
Re: Game: Russian Roulette
« Reply #11 on: January 11, 2007, 06:07:42 am »
i tried it, but i got this error


 
  • (roulette.pas) [Hint] (56:1): Variable 'TEMP' never used
  • Exception raised on SetVariables(Access violation at address 0043AE09 in mo

dule 'soldatserver.exe'. Read of address 00000000)
 
  • Run-time error (ActivateServer "const"): No Error



both on windows and linux....first time using the server side scripting, am i doing something wrong? :/

Offline CarlHamilton

  • Major(1)
  • Posts: 29
Re: Game: Russian Roulette
« Reply #12 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.

Offline spidey

  • Major(1)
  • Posts: 5
Re: Game: Russian Roulette
« Reply #13 on: January 11, 2007, 03:09:15 pm »
ok, a new error.

  • Compiling Script roulette.pas...
  • [Error] (237:11): Duplicate identifier 'ONJOINTEAM'
  • Exception raised on SetVariables(Access violation at address 0043AE09 in mo

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

Offline CarlHamilton

  • Major(1)
  • Posts: 29
Re: Game: Russian Roulette
« Reply #14 on: January 11, 2007, 03:14:51 pm »
You replaced the OnJoinTeam and OnPlayerSpeak procedures in your NetworkCore with those in the script right?

Offline spidey

  • Major(1)
  • Posts: 5
Re: Game: Russian Roulette
« Reply #15 on: January 11, 2007, 03:24:20 pm »
ok..i replaced them with the ones in the script

 
  • (NetworkCore.pas) [Error] (12:1): Unknown identifier 'playernames'


sorry...still new to this :p took me forever to even get the hang on esa >.<

Offline CarlHamilton

  • Major(1)
  • Posts: 29
Re: Game: Russian Roulette
« Reply #16 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 and see if it works. If it doesn't I'm clueless. :-X

Offline spidey

  • Major(1)
  • Posts: 5
Re: Game: Russian Roulette
« Reply #17 on: January 11, 2007, 03:55:26 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 ''



Offline cooz

  • Soldier
  • **
  • Posts: 187
  • BANNED
Re: Game: Russian Roulette
« Reply #18 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
« Last Edit: January 17, 2007, 07:43:27 am by cooz »
Dead man! Dead man walking! We got a dead man walking here! Banned man crawling more like