Page 1 of 1
Translocating item.
Posted: Sun Apr 23, 2006 7:49 am
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.
Posted: Sun Apr 23, 2006 8:27 pm
by CWO
Just do something like this (Just dont kill me if this isnt efficient enough for you guys

)...
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.
Posted: Tue May 02, 2006 1:34 am
by Duskman
Am..and..stupid question

Where to put this code?

Posted: Tue May 02, 2006 2:40 am
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).
Posted: Tue May 02, 2006 6:08 am
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
Posted: Tue May 02, 2006 9:18 pm
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.