Difference between revisions of "Code Snippet: PlaceBot"
(Created page with "===Code Snippet by Avarax=== <source lang="pascal">function PlaceBot(botname: string; team: byte; X,Y: single): byte; var i,n,tempType: byte; spawn: array of byte; tem...") |
m (Category fix) |
||
Line 49: | Line 49: | ||
[http://home.arcor.de/avarax3/fubar.png Example of usage] | [http://home.arcor.de/avarax3/fubar.png Example of usage] | ||
− | [[Category: | + | [[Category:Scripting_Templates]] |
Latest revision as of 11:50, 26 August 2013
Code Snippet by Avarax
function PlaceBot(botname: string; team: byte; X,Y: single): byte;
var i,n,tempType: byte;
spawn: array of byte;
tempX,tempY: single;
begin
//DEACTIVATE ALL SPAWNS OF CHOSEN TEAM
SetArrayLength(spawn,0);
n:=0;
for i:=1 to 254 do
If GetSpawnStat(i,'Active') = true then
If GetSpawnStat(i,'Style') = team then begin
n:=n + 1;
SetArrayLength(spawn,n);
spawn[n-1]:=i;
SetSpawnStat(i,'Active',false);
end;
//FIND AN UNUSED SPAWN AND SET IT TO SPECIFIED X/Y AND TEAM
for i:=1 to 254 do
If GetSpawnStat(i,'Active') = false then begin
SetSpawnStat(i,'Active',true);
tempType:=GetSpawnStat(i,'Style');
tempX:=GetSpawnStat(i,'X');
tempY:=GetSpawnStat(i,'Y');
SetSpawnStat(i,'Style',team);
SetSpawnStat(i,'X',X);
SetSpawnStat(i,'Y',Y);
break;
end;
//ADD THE BOT
result:=Command('/addbot' + inttostr(team) + ' ' + botname);
//RESET THE USED SPAWN TO ITS PREVIOUS STATE
SetSpawnStat(i,'Active',false);
SetSpawnStat(i,'Style',tempType);
SetSpawnStat(i,'X',tempX);
SetSpawnStat(i,'Y',tempY);
//ENABLE ALL PREVIOUSLY DISABLED SPAWNS
If n > 0 then
for i:=0 to n-1 do
SetSpawnStat(spawn[i],'Active',true);
end;
You can spawn bots at any position with this. Very useful, since you can not use MovePlayer on bots. Example of usage