Official Soldat Forums
Server Talk => Scripting Releases => Topic started 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:
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:
[global]
[players]
Known problems:
Changing teams resets your score
More improvement suggestions and bug reports welcome.
Thanks to cooz for his random script!
-
what does it allow you to?
-
good script, hehe
oh end tell me what's for this part in loadscores()
for count:= 1 to NumPlayers do begin
end;
;)
-
still wonna know what it makes...
-
You type !spin, and if a randum number is X, you die, and if its not, you're alive and get points.
-
and where the hell do u add this ?
-
It's for if you run a server Terrordog, you run the file through the parser in the server.
-
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.
-
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
-
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
-
Nice script, i feel like trying the script :D,
-
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? :/
-
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.
-
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)
-
You replaced the OnJoinTeam and OnPlayerSpeak procedures in your NetworkCore with those in the script right?
-
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 >.<
-
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
-
ahhh...ok that fixed networkcore.pas, but now there's a error in roulette.pas
- Compiling Script roulette.pas...
- [Error] (302:1): Duplicate identifier ''
-
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