This thing shows in console:
Code: Select all
Exception in scripts/textcmd/test/qspawn.ecl, PC=82: some fool used operator[] on a struct, with an Integer indexCode: Select all
use uo;
use os;
use util;
use basic;
include "include/client";
include "include/time";
include "include/classes";
include "include/dotempmods";
include "include/constants/propids";
include "include/yesno";
use cfgfile;
include "include/client";
program quest( who )
var woo;
while (woo !=999)
woo := QuestGump(who);
endwhile
endprogram
function FindCoords(who)
var tileZ;
var zValid := 1; // assume z is correct for now.
SendSysmessage( who, "Target Upper Left" );
var coordStructOne := TargetCoordinates( who );
SendSysmessage( who, "Target Lower Right" );
var coordStructTwo := TargetCoordinates( who );
if ( ( ! coordStructOne ) OR ( ! coordStructTwo ) ) // check that we got two valid coordstructs.
SendSysmessage( who, "Missing coordinate. Aborting." );
return;
endif
if ( ! zValid ) // if we are to use the coord #1 Z, check it out.
if ( coordStructOne.z < -127 OR coordStructOne.z > 128 )
SendSysmessage( who, "Z is out of bounds. Aborting." );
return;
endif
endif
if ( ! zValid )
tileZ := coordStructOne.z;
endif
var x1 := coordStructOne.x;
var x2 := coordStructTwo.x;
var y1 := coordStructOne.y;
var y2 := coordStructTwo.y;
if (x1 > x2 or y1 > y2)
SendSysmessage( who, "Bad Coordinates. Aborting." );
return;
endif
SetGlobalProperty("quest1",coordStructOne);
SetGlobalProperty("quest2",coordStructTwo);
endfunction
function QuestGump(who)
var q1 := GetGlobalProperty("quest1");
var q2 := GetGlobalProperty("quest2");
var num := GetGlobalProperty("questnum");
var diff := GetGlobalProperty("questdiff");
if (!num)
num := 0;
endif
if (!diff)
diff := 0;
endif
var DiffLayout := {
"page 0",
"resizepic 30 30 83 290 200",
"button 50 70 2104 2103 1 0 2001",
"button 50 90 2104 2103 1 0 2002",
"button 50 110 2104 2103 1 0 2003",
"button 50 130 2104 2103 1 0 2004",
"",
"text 50 42 35 0",
"text 70 65 35 1",
"text 70 85 35 2",
"text 70 105 35 3",
"text 70 125 35 4",
"text 42 155 35 5",
"button 141 195 2128 2129 1 0 1"
};
var rtext := q1[1]+","+q1[2]+"-"+q2[1]+","+q2[2]+" Diff:"+diff+" #:"+num;
var DiffData := {
"",
"Select Area",
"Select Difficulty",
"Select # of NPCs",
"Spawn!",
rtext
};
var Difficulty;
var number;
var res := SendDialogGump( who, DiffLayout, DiffData );
var text;
var entered;
if (res[0]==0)
SendSysMessage(who, "Aborted.");
return 999;
endif
if (res[0]==1)
return 999;
endif
Difficulty := res[0] - 2000;
if (Difficulty == 1)
FindCoords(who);
elseif (Difficulty == 2)
text := "Enter Difficulty (1-5)";
entered := Cint(SendTextEntryGump( who, text, 1 ));
if (!entered or entered < 1 or entered > 5)
SendSysMessage(who,"Cancelled.");
entered := 0;
endif
SetGlobalProperty("questdiff",entered);
elseif (Difficulty == 3)
text := "Enter # of NPCs (1-999)";
entered := Cint(SendTextEntryGump( who, text, 1 ));
if (!entered or entered < 1 or entered > 999)
entered := 0;
SendSysMessage(who,"Cancelled.");
endif
SetGlobalProperty("questnum",entered);
elseif (Difficulty == 4)
Spawn(who);
else
Difficulty := 999;
endif
return Difficulty;
endfunction
function Spawn(who);
var num := GetGlobalProperty("questnum");
var diff := GetGlobalProperty("questdiff");
var coord1 := GetGlobalProperty("quest1");
var coord2 := GetGlobalProperty("quest2");
var x;
var y;
var z;
if (!num or !diff or !coord1 or !coord2)
SendSysMessage(who,"Cancelled. Data Missing.");
return;
endif
var rangex := coord2[1] - coord1[1];
var rangey := coord2[2] - coord1[2];
var loop := 0;
var snum := 10;
var monner;
var actual := 0;
while (loop < num)
loop := loop + 1;
x := Random(rangex) + 1 + coord1[1];
y := Random(rangey) + 1 + coord1[2];
z := coord2[3];
monner := SpawnNpc(x,y,z,diff,who);
if (monner)
actual := actual + 1;
if (loop == snum)
SendSysMessage(who, snum+" NPCs spawned.");
snum := snum + 10;
endif
endif
sleepms(100);
endwhile
SendSysMessage(who, "Finished Spawning. Total: "+actual);
endfunction
function SpawnNpc(x, y, z, diff,who )
var group;
var g2 := Random(3)+1;
case(diff)
1: case(g2)
1: group := 2;
2: group := 1;
3: group := 8;
endcase
2: case(g2)
1: group := 9;
2: group := 17;
3: group := 23;
endcase
3: case(g2)
1: group := 69;
2: group := 70;
3: group := 71;
endcase
4: case(g2)
1: group := 75;
2: group := 61;
3: group := 62;
endcase
5: case(g2)
1: group := 63;
2: group := 76;
3: group := 77;
endcase
endcase
var cfg := ReadConfigFile( ":spawnpoint:groups" );
if( !cfg )
return 0;
endif
var elem := cfg[group];
var possibles := GetConfigStringArray( elem, "spawn" );
if( !possibles.size() )
return 0;
endif
var template := possibles[RandomInt(possibles.size())+1];
if( !template )
return 0;
endif
var critter := CreateNpcFromTemplate( template, x, y, z );
SetObjProperty(critter,"LFucker",who.name);
SetObjProperty(critter,"tmonster",1);
return critter;
endfunction