Spawnpoint - spawn creature on server starts

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.

Moderator: POL Developer

Post Reply
User avatar
Ciechu
New User
Posts: 29
Joined: Mon Oct 15, 2018 5:36 am
Location: Poland

Spawnpoint - spawn creature on server starts

Post by Ciechu » Sat Oct 20, 2018 5:37 am

Hi! I'm using standard spawnpoint scripts (linked below). I want to make that, when Pol shard starts all creatures spawns right now and also when I create new, or edit a spawnpoint. Normally when a server starts players must wait 2 hours for boss spawn, and it's not all right.

Thank you, and sorry for bad English.

spawnPoint (item)

Code: Select all

use vitals;
use math;
use basic;
use uo;
include "include/attributes";

var spawneditlayout :=
{
	"page 0                           ",
	"gumppic    30   0  101           ",
	"button    118  90 2130 2129  1 0 100",
	"text       80 120  33           0",
	"text       85 140   0           1",
	"text       85 156   0           2",
	"text       85 180  33           3",
	"text      100 196   0           4",
	"text      100 212   0           5",
	"text       95 250  33           6",
	"text       95 235  33          12",
    "group 1                          ",
    "radio     180 235 210 211    0 99",
	"textentry 160 140  40  15 50 1  7",
	"textentry 160 156  40  15 50 2  8",
	"textentry 155 196  30  15 50 3  9",
	"textentry 155 212  30  15 50 4 10",
	"textentry  65 268 160  15 50 5 11"
};

var spawneditdata :=
{
	"Spawn Point Data",
	"Amount: ",
	"Range: ",
	"Delay (Minutes)",
	"Min: ",
	"Max: ",
	"Monster Type",
	"0",
	"0",
	"0",
	"0",
	"NONE",
    "Ignore LOS"
};

program use_spawnpoint(who, spawnpoint)
  EraseObjProperty(spawnpoint, "IgnoreLOS");
  if(who.cmdlevel < 2)
	return;
  endif
  var spawn := GetObjProperty(spawnpoint, "Spawn");
  var amount := GetObjProperty(spawnpoint, "Amount");
  var mindelay := GetObjProperty(spawnpoint, "MinDelay");
  var maxdelay := GetObjProperty(spawnpoint, "MaxDelay");
  var range := GetObjProperty(spawnpoint, "Range");
  var i, x;
  if(spawn == "NONE")
	SendSysMessage(who, "Initializing new spawnpoint...");
  else
	spawneditdata[8] := CStr(amount);
	spawneditdata[9] := CStr(range);
	spawneditdata[10] := CStr(mindelay);
	spawneditdata[11] := CStr(maxdelay);
	spawneditdata[12] := CStr(spawn);
  endif
  var res := SendDialogGump(who, spawneditlayout, spawneditdata);
  if(res[0] != 100)
	SendSysMessage(who, "Aborted.");
	return;
  endif
  for(i:=1; i<=5; i:=i+1);
	if(!res[i])
	  SendSysMessage(who, "Error: spawn data incomplete.  Aborting.");
	  return;
	endif
  endfor
	x := len(res[1]);
	i := res[1];
	i := i[4, (x-3)];
	amount := CInt(i);
	x := len(res[2]);
	i := res[2];
	i := i[4, (x-3)];
	range := CInt(i);
	x := len(res[3]);
	i := res[3];
	i := i[4, (x-3)];
	mindelay := CInt(i);
	x := len(res[4]);
	i := res[4];
	i := i[4, (x-3)];
	maxdelay := CInt(i);
  if((amount < 1))
	SendSysMessage(who, "Amount must be between 1 and 32.  Setting to 1.");
	amount := 1;
  endif
  if((range < 0))
	SendSysMessage(who, "Range must be between 0 and 32.  Setting to 1.");
	range := 0;
  endif
  if((mindelay < 40) || (mindelay > 1440))
	SendSysMessage(who, "MinDelay must be between 40 and 1440.  Setting to 1.");
	mindelay := 40;
  endif
  if((maxdelay < 40) || (maxdelay > 1440))
	SendSysMessage(who, "MaxDelay must be between 40 and 1440.  Setting to 1.");
	maxdelay := 40;
  endif
  if(maxdelay < mindelay)
	SendSysMessage(who, "MaxDelay cannot be less than MinDelay.   Setting equal.");
	maxdelay := mindelay;
  endif
  x := len(res[5]);
  i := res[5];
  i := i[4, (x-3)];
  spawn := i;
  foreach thing in (res.keys)
    if(thing == 99)
      SetObjProperty(spawnpoint, "IgnoreLOS", 1);
      break;
    endif
  endforeach
  SendSysMessage(who, i);
  var critterarray := {"ettins", "orchorde", "trolls", "lesserundead", "undead", "vermin", "orcs", "dracos", "lizardmen", "ratmen", "elfs", "mountedelfs"};
  if(!i in critterarray)
    var thecritter := CreateNpcFromTemplate(i, spawnpoint.x, spawnpoint.y, spawnpoint.z);
    if(!thecritter)
	  SendSysMessage(who, "Invalid creature type.");
	  spawn := "NONE";
    else
            RevokePrivilege( thecritter, "invul" );
            SetObjProperty( thecritter, "guardkill", 1);
            ApplyRawDamage( thecritter, GetHp( thecritter ) + 100 );
    endif
  else
    var thecritter := CreateNpcFromTemplate(GetCritter(i), spawnpoint.x, spawnpoint.y, spawnpoint.z);
    if(!thecritter)
	  SendSysMessage(who, "Invalid creature type.");
	  spawn := "NONE";
    else
            RevokePrivilege( thecritter, "invul" );
            SetObjProperty( thecritter, "guardkill", 1);
            ApplyRawDamage( thecritter, GetHp( thecritter ) + 100 );
    endif
  endif
  SetObjProperty(spawnpoint, "Amount",   amount);
  SetObjProperty(spawnpoint, "Range",    range);
  SetObjProperty(spawnpoint, "MinDelay", mindelay);
  SetObjProperty(spawnpoint, "MaxDelay", maxdelay);
  SetObjProperty(spawnpoint, "Spawn",    spawn);
  SetObjProperty(spawnpoint, "ResetMe",  1);
  SendSysMessage(who, "Spawnpoint initialized. Resetting spawn. This may take a minute...");
  spawnpoint.invisible := 1;
endprogram

function GetCritter(type)
  if(type == "vermin")
    return "grat";
  elseif(type == "orcs")
     return "orc1";
  elseif(type == "orchorde")
    return "orclord";
  elseif(type == "ratmen")
    return "ratman1";
  elseif(type == "lizardmen")
    return "lizardman1";
  elseif(type == "dracos")
    return "dragon1";
  elseif(type == "trolls")
    return "troll1";
  elseif(type == "undead")
    return "shade";
  elseif(type == "lesserundead")
    return "zombie";
  elseif(type == "ettins")
    return "ettin";
  else
    return type;
  endif
endfunction

spawnPointController

Code: Select all

Use uo;
Use os;
Use util;
use math;
use vitals;
use basic;
use util;
use os;
use uo;

Include "include/attributes";

Program spawnpointcontrol( spawnpoint )

  var spawn := GetObjProperty(spawnpoint, "Spawn");
  var amount := GetObjProperty(spawnpoint, "Amount");
  var i, x;
  var spawnqueue := {};
  var children := {};
  var mindelay := GetObjProperty(spawnpoint, "MinDelay");
  var maxdelay := GetObjProperty(spawnpoint, "MaxDelay");
  spawn := GetObjProperty(spawnpoint, "Spawn");
  while(spawn == "NONE")
    sleep(10);
    spawn := GetObjProperty(spawnpoint, "Spawn");
  endwhile
  i := RandomInt(20);
  sleep(i);
  while(spawnpoint)
    var resetme := GetObjProperty(spawnpoint, "ResetMe");
    if(resetme)
      amount := GetObjProperty(spawnpoint, "Amount");
      KillChildren(spawnpoint);
      ResetSpawnQueue(spawnpoint);
      EraseObjProperty(spawnpoint, "ResetMe");
    endif
    spawn := GetObjProperty(spawnpoint, "Spawn");
    while(spawn == "NONE")
      sleep(10);
      spawn := GetObjProperty(spawnpoint, "Spawn");
    endwhile
    children := GetObjProperty(spawnpoint, "Children");
    spawnqueue := GetObjProperty(spawnpoint, "SpawnQueue");
    for(i:=1; i<=amount; i:=i+1);
      if(children[i] != "Empty")
        x := SystemFindObjectBySerial(children[i]);
        if((!x) || (x.dead == 1) || (x.script=="tamed"))
          spawnqueue[i] := "Empty";
          children[i] := "Empty";
        endif
      endif
    endfor
    SetObjProperty(spawnpoint, "Children", children);
    SetObjProperty(spawnpoint, "SpawnQueue", spawnqueue);
    ResetSpawnQueue(spawnpoint);
    spawnqueue := GetObjProperty(spawnpoint, "SpawnQueue");
    for(i:=1; i<=amount; i:=i+1)
      x := spawnqueue[i];
      if((x != "Empty") && (x != "Active"))
        if(x == 0)
          children[i] := CreateSpawn(spawnpoint);
          spawnqueue[i] := "Active";
        else
          spawnqueue[i] := x - 1;
        endif
      endif
    endfor
    SetObjProperty(spawnpoint, "SpawnQueue", spawnqueue);
    SetObjProperty(spawnpoint, "Children", children);
    If( !spawnpoint.invisible )
    spawnpoint.invisible := 1;
    endif
    
    if((mindelay < 1))
	mindelay := 40;
        syslog("SpawnPoint o serialu: " + spawnpoint.serial + " mial za niski mindelay. Zwiekszylem do 40.");
        SetObjProperty(spawnpoint, "MinDelay", 40);        
    endif
   
    if((maxdelay < 1))
	maxdelay := 40;
        syslog("SpawnPoint o serialu: " + spawnpoint.serial + " mial za niski maxdelay. Zwiekszylem do 40.");
        SetObjProperty(spawnpoint, "MaxDelay", 40);
    endif
  
    sleep(60);
  endwhile
endprogram

function KillChildren(spawnpoint)
  var i, x;
  var children := GetObjProperty(spawnpoint, "Children");
  if(children)
    foreach x in children
      if(x != "Empty")
        x := CInt(x);
        i := SystemFindObjectBySerial(x);
            RevokePrivilege( i, "invul" );
            SetObjProperty( i, "guardkill", 1);
            ApplyRawDamage( i, GetHp( i ) + 100 );
      endif
    endforeach
  endif
  var amount := GetObjProperty(spawnpoint, "Amount");
  var spawnqueue := {};
  children := {};
  for(i:=1; i<=amount; i:=i+1);
    spawnqueue[i] := "Empty";
    children[i] := "Empty";
  endfor
  SetObjProperty(spawnpoint, "Children", children);
  SetObjProperty(spawnpoint, "SpawnQueue", spawnqueue);
endfunction

function ResetSpawnQueue(spawnpoint)
  var i;
  var amount := GetObjProperty(spawnpoint, "Amount");
  var mindelay := GetObjProperty(spawnpoint, "MinDelay");
  var maxdelay := GetObjProperty(spawnpoint, "MaxDelay");
  var spawnqueue := GetObjProperty(spawnpoint, "SpawnQueue");
  for(i:=1; i<=amount; i:=i+1)
    if(spawnqueue[i] == "Empty")
      if(mindelay == maxdelay)
        spawnqueue[i] := mindelay;
      else
        spawnqueue[i] := RandomInt(maxdelay - mindelay) + mindelay + 1;
      endif
    endif
  endfor
  SetObjProperty(spawnpoint, "SpawnQueue", spawnqueue);
endfunction

function CreateSpawn(spawnpoint)
  var loscheck := GetObjProperty(spawnpoint, "IgnoreLOS");
  var spawn := GetObjProperty(spawnpoint, "Spawn");
  var range := GetObjProperty(spawnpoint, "Range");
  var x, y, z, success := 0;
  var i := 1;
  while(success == 0)
    if(range == 0)
      x := spawnpoint.x;
      y := spawnpoint.y;
      z := spawnpoint.z;
    else
      x := spawnpoint.x + RandomInt(2 * range) - range;
      y := spawnpoint.y + RandomInt(2 * range) - range;
      z := GetWorldHeight(x, y);
    endif
    if(!loscheck)
      if(CheckLosAt(spawnpoint, x, y, z))
        var i := CreateNpcFromTemplate(spawn, x, y, z);

        success := 1;
        return i.serial;
      endif
    else
      var i := CreateNpcFromTemplate(spawn, x, y, z);

      success := 1;
      return i.serial;
    endif
    i := i + 1;
    if(i > 10)
      var i := CreateNpcFromTemplate(spawn, spawnpoint.x, spawnpoint.y, spawnpoint.z);

      success := 1;
      return i.serial;
    endif
  endwhile
endfunction


Function Legal_NPC( NPC )

     Var xScript := NPC.script;

     Case( xScript )
     "townguard":     Return 1;
     "merchant":      Return 1;
     "banker":        Return 1;
     "animaltrainer": Return 1;
     Default:         Return 0;
     Endcase

Endfunction

function GetCritter(type)
  if(type == "vermin")
    case(RandomInt(11) + 1)
      1: return "grat";
      2: return "grat";
      3: return "grat";
      4: return "jwilson";
      5: return "slime";
      6: return "slime";
      7: return "slime";
      8: return "giant_serpent";
      9: return "giant_serpent";
     10: return "giantscorp";
     11: return "giantscorp";
    endcase
  elseif(type == "orcs")
     case(RandomInt(10) + 1)
      1: return "orcmage";
      2: return "orclord";
      3: return "orc1";
      4: return "orc1";
      5: return "orc1";
      6: return "orc2";
      7: return "orc2";
      8: return "orc2";
      9: return "ettin";
     10: return "ettin2";
    endcase
  elseif(type == "orchorde")
    case(RandomInt(8) + 1)
      1: return "orc1";
      2: return "orc1";
      3: return "orc1";
      4: return "orcmage";
      5: return "orclord";
      6: return "orc2";
      7: return "orc2";
      8: return "orc2";
    endcase
  elseif(type == "ratmen")
    case(RandomInt(3) + 1)
      1: return "ratman3";
      2: return "ratman2";
      3: return "ratman1";
    endcase
  elseif(type == "lizardmen")
    case(RandomInt(3) + 1)
      1: return "lizardman3";
      2: return "lizardman2";
      3: return "lizardman1";
    endcase
  elseif(type == "dracos")
    case(RandomInt(4) + 1)
      1: return "dragon1";
      2: return "dragon2";
      3: return "drake1";
      4: return "drake2";
    endcase
  elseif(type == "trolls")
    case(RandomInt(3) + 1)
      1: return "troll1";
      2: return "troll2";
      3: return "troll3";
    endcase
  elseif(type == "undead")
    case(RandomInt(7) + 1)
      1: return "zombie";
      2: return "zombie";
      3: return "skeleton";
      4: return "skeleton";
      5: return "shade";
      6: return "shade";
      7: return "liche";
    endcase
  elseif(type == "lesserundead")
    case(RandomInt(4) + 1)
      1: return "zombie";
      2: return "zombie";
      3: return "skeleton";
      4: return "skeleton";
    endcase
  elseif(type == "ettins")
    case(RandomInt(2) + 1)
      1: return "ettin";
      2: return "ettin2";
    endcase
  elseif(type == "elfs")
    case(RandomInt(3) + 1)
      1: return "darkelfwarrior";
      2: return "darkelfarcher";
      3: return "darkelfmage";
    endcase
  elseif(type == "mountedelfs")
    case(RandomInt(2) + 1)
      1: return "mountedelfwarrior";
      2: return "mountedelfarcher";
    endcase
  endif
endfunction


Yukiko
Distro Developer
Posts: 2781
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: Spawnpoint - spawn creature on server starts

Post by Yukiko » Sun Oct 21, 2018 8:28 pm

It looks as if the delay in spawning is the CProps MinDelay and MaxDelay for each spawnpoint. I would check those values. At first I thought the delay might be in the spawnPointControl script at startup. I suspected that script might pick a random delay to start spawning the NPCs so as to avoid excess server load during server start but the longest delay (Sleep() ), other than that imposed by MinDelay and MaxDelay, is 60 seconds not 2 hours.

Line 126 in spawnPointControl.src is where the actual delay to spawn is calculated:

Code: Select all

spawnqueue[i] := RandomInt(maxdelay - mindelay) + mindelay + 1;
Those values, mindelay and maxdelay, are taken from the CProps MinDelay and MaxDelay. Those CProps are set on the spawnpoint by spawnPoint.src. You give it those values in the spawnpoint gump. Those delays are in seconds I believe. So check your MinDelay and MaxDelay settings on your "Boss" spawnpoints. Those might be set too long.

User avatar
Ciechu
New User
Posts: 29
Joined: Mon Oct 15, 2018 5:36 am
Location: Poland

Re: Spawnpoint - spawn creature on server starts

Post by Ciechu » Mon Oct 22, 2018 6:17 am

Ok, thank you for your reply.

I setup this correctly, and works perfect.

Yukiko
Distro Developer
Posts: 2781
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: Spawnpoint - spawn creature on server starts

Post by Yukiko » Mon Oct 22, 2018 8:42 am

You are welcome. I am glad I could help.

Post Reply