Translocating item.

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
Duskman
New User
Posts: 20
Joined: Mon Apr 03, 2006 1:59 pm

Translocating item.

Post by Duskman »

Could some one help me with script, wich will be moving an item in that direction, in wich player is directed when he double click it? But, important, it will be great, when item could be locked down and it will spawn new item, with the same graphic to avoid last object macro :)

D.
User avatar
CWO
POL Expert
Posts: 1160
Joined: Sat Feb 04, 2006 5:49 pm

Post by CWO »

Just do something like this (Just dont kill me if this isnt efficient enough for you guys :P )...

Code: Select all

function moveobject(who, item)
	var locx := item.x;
	var locy := item.y;	
  if ((who.facing < 2) || (who.facing == 7))  // 7 (Northwest), 0 (North), 1 (Northeast)
   	locy := locy - 1; // Move item 1 tile North
  endif
  if ((who.facing > 2) && (who.facing < 6)) // 3 (Southeast), 4 (South), 5 (Southwest)
   	locy := locy + 1; // Move item 1 tile South
  endif
  if ((who.facing > 0) && (who.facing < 4)) // 1 (Northeast), 2 (East), 3 (Southeast)
   	locx := locx + 1; // Move item 1 tile East
  endif
  if (who.facing > 4) // 5 (Southwest), 6 (West), 7 (Northwest)
   	locx := locx - 1;  //Move item 1 tile West
  endif
  CreateItemCopyAtLocation(locx, locy, GetWorldHeight(locx, locy), item);
  //Use the next line in place of the previous if you have POL096. Supports different maps.
  //CreateItemCopyAtLocation(locx, locy, GetWorldHeight(locx, locy), item, item.realm);
  DestroyItem(item);
endfunction
If your goal is to prevent macroing of this, this wont work against third party programs. You can easily scan the ground of an object of a certain type and set it to LastObject then use it. The only way around that is to make a completely different item but then that will get offset because if the type is changing, players will just have it scan the ground for anything and use it. Obstacles and extra items... they can have it just use everything almost all at once.
Duskman
New User
Posts: 20
Joined: Mon Apr 03, 2006 1:59 pm

Post by Duskman »

Am..and..stupid question :P Where to put this code? :roll:
Last edited by Duskman on Tue May 02, 2006 6:05 am, edited 1 time in total.
User avatar
CWO
POL Expert
Posts: 1160
Joined: Sat Feb 04, 2006 5:49 pm

Post by CWO »

Just stick this in the usescript for the item. As soon as you want to move the item, just do the command moveobject(who, item).
Duskman
New User
Posts: 20
Joined: Mon Apr 03, 2006 1:59 pm

Post by Duskman »

But it's function. And documentation says about usescript:
"Where Does It Live?
The 'program' in a .src file, in a package or /scripts/items"
example

Code: Select all

use uo;
use util;
program my_example_usescript(character, item)
    PrintTextAbove(item, character.name + " used me!");
    item.color := RandomInt(50);
endprogram
User avatar
CWO
POL Expert
Posts: 1160
Joined: Sat Feb 04, 2006 5:49 pm

Post by CWO »

Right, you can copy and paste that function inside an include or just in the script itself then call it like

Code: Select all

use uo;

program my_example_usescript(character, item)
    var newitem := moveobject(character, item);
    newitem.movable := 0;
    (put any other modifications or stuff you want to do here)
endprogram

function moveobject(who, item)
   var locx := item.x;
   var locy := item.y;   
  if ((who.facing < 2) || (who.facing == 7))  // 7 (Northwest), 0 (North), 1 (Northeast)
      locy := locy - 1; // Move item 1 tile North
  endif
  if ((who.facing > 2) && (who.facing < 6)) // 3 (Southeast), 4 (South), 5 (Southwest)
      locy := locy + 1; // Move item 1 tile South
  endif
  if ((who.facing > 0) && (who.facing < 4)) // 1 (Northeast), 2 (East), 3 (Southeast)
      locx := locx + 1; // Move item 1 tile East
  endif
  if (who.facing > 4) // 5 (Southwest), 6 (West), 7 (Northwest)
      locx := locx - 1;  //Move item 1 tile West
  endif
  var newitem := CreateItemCopyAtLocation(locx, locy, GetWorldHeight(locx, locy), item);
  //Use the next line in place of the previous if you have POL096. Supports different maps.
  //var newitem := CreateItemCopyAtLocation(locx, locy, GetWorldHeight(locx, locy), item, item.realm);
  DestroyItem(item);
  return newitem;
endfunction
Theres your program and the function all in 1 file. You can call any function you want using your program as long as its either in the script or in one of its includes.
Post Reply