Official Soldat Forums
Server Talk => Scripting Discussions and Help => Topic started by: y0uRd34th on December 03, 2009, 11:13:49 am
-
Well, i hope you can understand what i wrote.. :D
all you need to know goes here:
It will be executed whenever a human joins a team or leaves the game.
So the basics:
first of all there are at least 4 ghouls (min_ghouls) and for every player on the server would be
2 more ghouls. When there are 2 people and one quits, 2 ghouls would be kicked.
The species[]: need: number of players requiered to spawn at least one of this ghoul type.
So as you can read out of the imploding ghoul there would be requiered 3 players, when so, one ghoul will be kicked and the imploding ghoul added. And again, when a guy leaves, the imploding ghoul will be kicked and the normal ghoul joins again.
5 minutes ago i tested if any bots would join, but nothing happened, the server console just told me (OnJoinGame) Division by zero, same for OnLeaveGame.
As far as i can think, the basics here should work so far (I hope so ::))
Thanks alot for helping!
If you dont use notepad++ some lines are longer or shorter than normal because it adds TABs from itself and their longer in normal notepad or others..
const
// zombie related stuff
min_ghouls = 4;
GhoulsPerPlayer = 2;
BotSpecies = 2;
// teams
GhoulTeam = 1;
HumanTeam = 2;
type
TBot = Record
species, armor, chest: integer; // Species; 1: Ghoul; 2: Imploding Ghoul;
kick: boolean;
end;
TSpecies = Record
armor, chest, need: integer;
name: string;
end;
var
Bot: Array [1..30] of TBot;
species: array [1..BotSpecies] of TSpecies;
function HighestID(): byte;
var i: byte;
begin
for i := 1 to 30 do
if GetPlayerStat(i,'Active') = true then
Result := i;
end;
procedure SetSpecies();
begin
species[1].name := 'Ghoul';
species[1].armor := 8000;
species[1].chest := 10;
species[1].need := 1;
species[2].name := 'Imploding Ghoul';
species[2].armor := 12000;
species[2].chest := 30
species[2].need := 3;
end;
function GetBotSpecies(ID: byte): integer;
var i: byte;
begin
for i := 1 to BotSpecies do begin
if IDToName(ID) = species[i].name then
Result := i;
end;
end;
function GetBotCount(Specie: integer): byte;
var i: byte;
begin
Result := 0;
for i := 1 to HighestID do begin
if GetPlayerStat(i,'Active') = true then
if GetPlayerStat(i,'Human') = false then
if IDToName(i) = species[Specie].name then
Result := Result + 1;
end;
end;
function GetBot(Specie: integer): integer;
var i: byte;
begin
for i := 1 to HighestID do begin
if GetPlayerStat(i,'Active') = true then
if GetPlayerStat(i,'Human') = false then
if IDToName(i) = species[specie].name then begin
Result := i;
break;
end;
end;
end;
procedure CalculateGhouls();
var botcount, num: array [1..BotSpecies] of integer; humans, i, j, present, ghouls : integer;
begin
humans := 0;
present := 0;
for i := 1 to BotSpecies do
botcount[i] := GetBotCount(i);
for i := 1 to HighestID do begin
if GetPlayerStat(i,'Active') = true then
if GetPlayerStat(i,'Human') = true then
humans := humans + 1;
end;
ghouls := GhoulsPerPlayer * humans + min_Ghouls;
for i := 1 to BotSpecies do
present := present + botcount[i];
// less bots then minimal number of them? set it to the minimum number
if present < min_ghouls then
present := min_ghouls;
// not enough bots on server for humans? add them
if present < ghouls then
for i := 1 to ghouls - present do begin
Command('/addbot' + IntToStr(GhoulTeam) + ' ' + species[1].name);
botcount[1] := botcount[1] + 1;
// too much bots per player there? kick them to balance
if present > ghouls then
for i := 1 to present - ghouls do begin
j := GetBot(1);
KickPlayer(j);
botcount[1] := botcount[1] - 1;
end;
end;
if humans > 0 then begin
// setting up the number of bots required to add
for i := 1 to BotSpecies do begin
if humans > species[i].need then
num[i] := humans div species[i].need;
end;
// now add or kick them
for i := 1 to BotSpecies do begin
// not enough bots there? add them
if botcount[i] < num[i] then
while botcount[i] < num[i] do begin
Command('/addbot' + IntToStr(GhoulTeam) + ' ' + species[i].name);
j := GetBot(1);
KickPlayer(j);
botcount[i] := botcount[i] + 1;
botcount[1] := botcount[1] - 1;
end;
// too much on the server? kick them
if botcount[i] > num[i] then
while botcount[i] > num[i] do begin
j := GetBot(i);
KickPlayer(j);
botcount[i] := botcount[i] - 1;
if i > 1 then begin
Command('/addbot' + IntToStr(GhoulTeam) + ' ' + species[1].name);
botcount[1] := botcount[1] + 1;
end;
end;
end;
end;
end;
procedure ActivateServer();
begin
SetSpecies;
end;
procedure OnJoinTeam(ID, team: byte);
begin
calculateghouls;
end;
procedure OnLeaveGame(ID, team: byte; kicked: boolean);
begin
calculateghouls;
end;
-
A quick glance makes me suggest
num[i] := humans div species[i].need;
check if species[ i ].need is 0.
-
It cant be 0 because i goes from 1 to GhoulSpecies (2) and species[1,2].need are 1,3 :/ but im testing it with WriteLn() fast
okey, forgot to add SetSpecies; into ActivateServer;
Well, now it works, but adds infinite ghouls to the server
this is kinda complicated; please post any ideas you got how you would think to make this.
-
Maybe OnJoinGame and OnLeaveGame check if its a bot joining or leaving, but I would guess calculategouls() should work properly without that.
-
Solved with help, was alot easier than i made it up there...