Page 1 of 1

Anyone can help with .qspawn? [POL095]

Posted: Wed Aug 20, 2008 2:57 pm
by lokaum
When I use .qspawn and select the area (upper left and down right):

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 index
qspawn.srt:

Code: 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
Can anyone help me to find what the problem?

Re: Anyone can help with .qspawn? [POL095]

Posted: Thu Aug 21, 2008 12:29 am
by CWO
Its giving a PC=82 number so you should post the .lst file between the numbers 70: and 90: so we can have a better look on exactly where in the code POL is.

The error is being triggered because somewhere in this code a struct is being used like an array. I believe in the past you were able to do that but nowadays, you can't (and its horrible form anyway). The .lst file is easier to look at because the problem is just as likely inside an include file and not the .src file.

Re: Anyone can help with .qspawn? [POL095]

Posted: Fri Aug 22, 2008 7:40 am
by lokaum
how i can get or create the .lst file??

i not found it..

Re: Anyone can help with .qspawn? [POL095]

Posted: Fri Aug 22, 2008 10:32 am
by Turley
Messed a bit in your code. I hope you can understand this:

// These two vars are structs
var coordStructOne := TargetCoordinates( who );
var coordStructTwo := TargetCoordinates( who );

// correct usage
var x1 := coordStructOne.x;
var x2 := coordStructTwo.x;
var y1 := coordStructOne.y;
var y2 := coordStructTwo.y;

....
//ok here are our two structs

var q1 := GetGlobalProperty("quest1");
var q2 := GetGlobalProperty("quest2");

// i guess here is PC 82
// using of array operator on a struct

var rtext := q1[1]+","+q1[2]+"-"+q2[1]+","+q2[2]+" Diff:"+diff+" #:"+num;

...
// next

var coord1 := GetGlobalProperty("quest1");
var coord2 := GetGlobalProperty("quest2");

// ... next wrong usage
var rangex := coord2[1] - coord1[1];
var rangey := coord2[2] - coord1[2];

// ...


You should use .x and .y not [1] and [2]

Re: Anyone can help with .qspawn? [POL095]

Posted: Fri Aug 22, 2008 11:13 am
by lokaum
Thank you alot man!

It's now working!

Re: Anyone can help with .qspawn? [POL095]

Posted: Sat Aug 23, 2008 4:12 am
by CWO
Just for future reference, make sure ecompile.cfg has the line

GenerateListing=1

after setting that, ecompile will generate a .lst when you compile a script. This is very useful in pointing out problems because if POL is going to complain about something in a script, it will usually point to information only contained in this .lst file.

Re: Anyone can help with .qspawn? [POL095]

Posted: Sat Aug 23, 2008 4:58 am
by lokaum
Hmmm thanks man... I'll do it..