I'm really not a proficient scripter but i try.
On too the problem. compiler out put shows a few local variables not used warnings such as these aren't being used. var x1; var y1; var x2; var y2; these represent the coords used in the regions.cfg file.
log output example for the error is when the region spawner is running follows.
Script Error in 'pkg/world/spawners/regionspawner/dospawn.ecl' PC=448:
Call to function MoveObjectToLocation:
Parameter 4: Expected datatype String, got datatype Integer
and the actual script code is:
Code: Select all
use uo;
use os;
use cfgfile;
use util;
use vitals;
include "include/myutil";
var regspawn;
var totalnumspawned := 0;
program SpawnThatStuff( me )
set_critical(0);
if (GetGlobalProperty("#regionalspawnerwipe"))
gmreport("regional spawner is disabled");
return;
endif
if (GetGlobalProperty("#spawnerisrunning"))
gmreport("regional spawner is still running from last invocation");
return;
endif
SetGlobalProperty("#spawnerisrunning",1 );
gmreport("regional spawner is running");
UnloadConfigFile( "regionspawn" );
regspawn := ReadConfigFile( "regionspawn" );
var numregions := GetConfigMaxIntKey( regspawn );
var coords;
var x1;
var y1;
var x2;
var y2;
var i;
for( i := 1; i <= numregions; i := i + 1 )
var spawnregion := regspawn[ i ];
var spawngroups := GetConfigStringArray( spawnregion, "group" );
foreach spawngroup in spawngroups
var groupstring := splitwords(spawngroup);
var groupname := groupstring[1];
var groupdensity := cint(groupstring[2]);
if (GetGlobalProperty("regionalspawnerwipe"))
gmreport("regional spawner is disabled");
EraseGlobalProperty("#spawnerisrunning");
return;
endif
SpawnThisGroup(i, spawnregion, groupname, groupdensity);
sleep(30);
endforeach
endfor
UnloadConfigFile( "regionspawn" );
EraseGlobalProperty("#spawnerisrunning");
gmreport("Total mobs respawned: "+ totalnumspawned);
endprogram
function SpawnThisGroup(regionnum, spawnregion, groupname, groupdensity)
var coords := splitwords(spawnregion.rect);
var x1 := cint(coords[1]);
var y1 := cint(coords[2]);
var x2 := cint(coords[3]);
var y2 := cint(coords[4]);
var spawngroup := FindConfigElem( regspawn, groupname );
if (!spawngroup)
gmreport("Could not find: "+groupname);
endif
var critterlist := GetConfigStringArray( spawngroup, "npc" );
var sizeofregion := (x2 - x1) * (y2 - y1);
var numtospawn := cint((sizeofregion * groupdensity)/10000);
if (!numtospawn)
numtospawn := 1;
endif
var SpawnName := "r"+regionnum+"g"+groupname;
if (groupdensity == 0)
gmreport("Erasing: "+SpawnName);
EraseGlobalProperty(SpawnName);
return;
endif
if ( (RandomInt(1000) == 1) )
NukeThisGroup(regionnum,spawnregion,groupname);
endif
set_critical(1);
var currentspawn := 0;
if (GetGlobalProperty(SpawnName))
currentspawn := Cint(GetGlobalProperty(SpawnName));
else
SetGlobalProperty(SpawnName,0);
endif
if ( (currentspawn < 1) or (!currentspawn) )
currentspawn := 0;
SetGlobalProperty(SpawnName,0);
endif
set_critical(0);
if ( currentspawn <= numtospawn )
numtospawn := numtospawn - currentspawn;
else
NukeThisGroup(regionnum,spawnregion,groupname);
currentspawn := 0;
endif
if (numtospawn < 1)
return;
endif
var critnum;
var thecritter;
var x;
var y;
var z;
var i;
var tries;
var sh;
var info;
for( i := 1; i <= numtospawn; i := i + 1 )
critnum := RandomInt(len(critterlist))+1;
thecritter := 0;
tries := 0;
repeat
x := RandomInt (x2-x1)+x1;
y := RandomInt (y2-y1)+y1;
z := GetMapInfo(x,y).z;
tries := tries +1;
sh := GetStandingHeight( x, y, z );
if (sh.multi or sh.multi.serial)
thecritter := 0;
else
info := hex(GetMapInfo( x , y ).landtile);
if ((info < 0x406) or (info > 0x455))
thecritter := createnpcfromtemplate(critterlist[critnum],x,y,z);
if (thecritter)
if (!MoveObjectToLocation(thecritter, thecritter.x,
thecritter.y, z,0) )
KillIt(thecritter);
else
set_critical(1);
SetObjProperty(thecritter,"regspawn",SpawnName);
currentspawn := Cint(GetGlobalProperty(SpawnName))+1;
SetGlobalProperty(SpawnName,currentspawn);
totalnumspawned := totalnumspawned +1;
set_critical(0);
sleep(1);
endif
endif
endif
endif
until (thecritter) or (tries > 50);
if (tries > 50)
gmreport ("Error - could not spawn "+ critterlist[critnum] + " in " + SpawnName);
endif
endfor
endfunction
function gmreport(text)
syslog(text);
ALertGM( "Regionspawner: " + text);
endfunction
function KillIt(me)
var hostiles := ListHostiles(me, 9 );
if (hostiles.size() or me.warmode)
EraseObjProperty( me, "regspawn" );
return;
endif
foreach item in ListRootItemsInContainer( me.backpack );
MoveObjectToLocation(item, me.x, me.y, me.z, 0 );
endforeach
MoveObjectToLocation(me, 4550, 3687 , 0,flags := MOVEOBJECT_NORMAL );
SetObjProperty(me,"guardkill",1);
ApplyRawDamage (me, GetVital (me, "Life") + 3 );
endfunction
function NukeThisGroup(regionnum, spawnregion, groupname)
var coords := splitwords(spawnregion.rect);
var x1 := cint(coords[1]);
var y1 := cint(coords[2]);
var x2 := cint(coords[3]);
var y2 := cint(coords[4]);
var kills := 0;
var SpawnName := "r"+regionnum+"g"+groupname;
gmreport("Resetting : "+SpawnName);
set_critical(0);
var x, y, z;
for( x := x2 ; x > x1 ; x := x - 16)
for( y := y1; y < y2; y := y + 16 )
for( z := -60; z <= 60; z := z + 16 )
foreach npc in ListMobilesNearLocationEx( x, y, z, 16,0x02+0x01)
if ( GetObjProperty( npc, "regspawn" ) == SpawnName )
set_critical(1);
EraseObjProperty(npc,"regspawn");
KillIt(npc);
kills := kills + 1;
set_critical(0);
endif
endforeach
endfor
sleepms(250);
endfor
endfor
set_critical(0);
gmreport("kills: "+kills);
SetGlobalProperty(SpawnName,0);
endfunction