When demolishing a house

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
Poi
Grandmaster Poster
Posts: 298
Joined: Fri Apr 14, 2006 9:36 am

When demolishing a house

Post by Poi »

I made a little code so that when someone has a certain item in their house, and they demolish their house, it *should* destroy the item and create the deed used to make the item where that item was. but it doesn't.

Any ideas what is wrong?

I added this code

Code: Select all

if(GetObjProperty(thing, "objtype") == 0x10)
DestroyItem(thing);
var watt :=  CreateItemAtLocation(thing.x, thing.y, thing.z, 0x5abc, 1);
endif
in this section

Code: Select all

function demolish(house)

  var lists := GetObjProperty(house, "footage");
  var itemlist := {};
  foreach entry in lists
    foreach thing in ListObjectsInBox(entry[1], entry[2], entry[3], entry[4], entry[5],entry[6])
      itemlist.append(thing);
    endforeach
  endforeach
  var chk;
  var builtdeed := GetObjProperty(house, "builtdeed");
  if(builtdeed)
    if(!DestroyItem(SystemFindObjectBySerial(builtdeed)))
      DestroyItem(SystemFindObjectBySerial(builtdeed, 1));
    endif
  endif
  foreach thing in itemlist
if(GetObjProperty(thing, "objtype") == 0x10)
DestroyItem(thing);
var watt :=  CreateItemAtLocation(thing.x, thing.y, thing.z, 0x5abc, 1);
endif
    if(GetObjProperty(thing, "houseserial") == house.serial)
      if ((GetObjProperty(thing, "secure") == 1) && (thing.movable == 0))
        EraseObjProperty(thing, "secure");
        if(GetObjProperty(thing, "houseserial" ) == house.serial)
          var oldscript := GetObjProperty(thing, "oldscript");
          if (oldscript == error)
            oldscript := "";
          endif
          thing.usescript := oldscript;
          thing.movable := 1;
          EraseObjProperty(thing, "houseserial" );
          EraseObjProperty(thing, "oldscript" );
        endif
      elseif ((GetObjProperty(thing, "lockeddown" ) == 1) && (thing.movable == 0))
        thing.movable := 1;
        EraseObjProperty(thing, "houseserial");
        EraseObjProperty(thing, "lockeddown");
      elseif (thing.movable == 0)
        if(thing.objtype == 0xa390)
           MoveItemToLocation(thing, thing.x, thing.y, (thing.z - 7), MOVEITEM_FORCELOCATION);
        else
          DestroyItem(thing);
        endif
      endif
    endif
  endforeach
  DestroyMulti(house );
  return;
endfunction
User avatar
ncrsn
Grandmaster Poster
Posts: 255
Joined: Fri Feb 10, 2006 12:15 am

Post by ncrsn »

Well, after you destroy the thing there's no longer going to be usable x, y and z members.

Try creating the new item before and destroying the thing after.
Poi
Grandmaster Poster
Posts: 298
Joined: Fri Apr 14, 2006 9:36 am

Post by Poi »

Hmm, that doesn't seem to be the problem as ingame when tested, either way(destroy before or after) they both leave the original item in a non-locked down form(movable) and no deed =/
User avatar
CWO
POL Expert
Posts: 1160
Joined: Sat Feb 04, 2006 5:49 pm

Post by CWO »

is it possible that its because you're doing GetObjProperty(thing, "objtype") == 0x10 instead of thing.objtype == 0x10 ?
Poi
Grandmaster Poster
Posts: 298
Joined: Fri Apr 14, 2006 9:36 am

Post by Poi »

Ill try at our next shard restart, thanks.
Poi
Grandmaster Poster
Posts: 298
Joined: Fri Apr 14, 2006 9:36 am

Post by Poi »

Still didn't work =/
Pierce
Forum Regular
Posts: 420
Joined: Thu Feb 02, 2006 8:33 am

Post by Pierce »

A very simple way to find self made errors in your own script is to put in some kind of output of especially the variables. I do this normally on my test server with the simple broadcast command. Sure there are other ways :D

I just make a suggestion what i would do with your script, because we all don't know what e.g. the cprop "footage" look like.
Perhaps you find the error that way or could at least give us the results:

Code: Select all

function demolish(house) 

  var lists := GetObjProperty(house, "footage"); 
broadcast("footage: " + lists);
  var itemlist := {}; 
  foreach entry in lists 
    foreach thing in ListObjectsInBox(entry[1], entry[2], entry[3], entry[4], entry[5],entry[6]) 
      itemlist.append(thing); 
    endforeach 
  endforeach 
broadcast("itemlist size: " + itemlist.size());
  var chk; 
  var builtdeed := GetObjProperty(house, "builtdeed"); 
  if(builtdeed) 
    if(!DestroyItem(SystemFindObjectBySerial(builtdeed))) 
      DestroyItem(SystemFindObjectBySerial(builtdeed, 1)); 
    endif 
  endif 
  foreach thing in itemlist 
broadcast("Test 1");
if(GetObjProperty(thing, "objtype") == 0x10) 
broadcast("Test 2");
DestroyItem(thing); 
var watt :=  CreateItemAtLocation(thing.x, thing.y, thing.z, 0x5abc, 1); 
endif 
    if(GetObjProperty(thing, "houseserial") == house.serial) 
      if ((GetObjProperty(thing, "secure") == 1) && (thing.movable == 0)) 
        EraseObjProperty(thing, "secure"); 
        if(GetObjProperty(thing, "houseserial" ) == house.serial) 
          var oldscript := GetObjProperty(thing, "oldscript"); 
          if (oldscript == error) 
            oldscript := ""; 
          endif 
          thing.usescript := oldscript; 
          thing.movable := 1; 
          EraseObjProperty(thing, "houseserial" ); 
          EraseObjProperty(thing, "oldscript" ); 
        endif 
      elseif ((GetObjProperty(thing, "lockeddown" ) == 1) && (thing.movable == 0)) 
        thing.movable := 1; 
        EraseObjProperty(thing, "houseserial"); 
        EraseObjProperty(thing, "lockeddown"); 
      elseif (thing.movable == 0) 
        if(thing.objtype == 0xa390) 
           MoveItemToLocation(thing, thing.x, thing.y, (thing.z - 7), MOVEITEM_FORCELOCATION); 
        else 
          DestroyItem(thing); 
        endif 
      endif 
    endif 
  endforeach 
  DestroyMulti(house ); 
  return; 
endfunction
Post Reply