Page 1 of 1

Still in practice

Posted: Tue Jul 01, 2008 8:20 am
by Lunne
Yeah hey it's me again. I've been continuing my self-learning in Escript, but it seems I have gotten myself stuck at trying to create a cloak that when equipped will hide you and let you stealth 2d6+13 steps.

The method I thought I'd use is this:


I'll have an item that when is equipped calls the script "invis_cloak.src", and when unequipped calls the script "invis_cloak_off.src".

The equipscript looks like this:

Code: Select all

use uo;
use util;


program InvisibilityCloakOn(player, cloak)

var Time := ReadGameClock();
var WaitTime := GetObjProperty(player, "InvisCloakTime");
if (Time < WaitTime)
var TimeLeft := (WaitTime - Time);
PrintTextAbovePrivate(player, ("The cloak needs to recharge. You feel it will take " + TimeLeft + " seconds before you can use it.), player); 
return;
endif

var orcolor := GetObjProperty(cloak, "color");
SetObjProperty(cloak, "originalcolor", orcolor); 
SetObjProperty(cloak, "color", 1);
SetObjProperty(player, "hidden", 1);
SetObjProperty(player, "stealthsteps", (2d6+13));
SetObjProperty(player, "InvisCloakTime", (ReadGameClock() + 60));


endprogram
And the unequip code looks like this:

Code: Select all

use uo;
use util;

program InvisibilityCloakOff(player, cloak)

var orcolor := GetObjProperty(cloak, "originalcolor");
cloak.color := orcolor;

endprogram

The itemdesc.cfg file in the config folder has this code:

Code: Select all

Item 0x5002
{
	Name		inviscloak
	Desc		Invisibility Cloak
	Graphic		0x1515
	maxhp		20
	AR		4
	Script		
	controlscript	:combat:itemControl
	destroyscript	:combat:destroy
	equipscript	invis_cloak
	unequipscript	invis_cloak_off
}


Both the .src files are located in ...\scripts\custom


Help would be greatly appreciated.
Thank you / Lunne

Re: Still in practice

Posted: Tue Jul 01, 2008 8:33 am
by qrak
invis_cloak.src :

Code: Select all

use uo;
use util;


program InvisibilityCloakOn(player, cloak)

var WaitTime := GetObjProperty(player, "InvisCloakTime") 
if(!WaitTime)
  SetObjProperty(player, "InvisCloakTime", ReadGameClock());
endif
if (ReadGameClock() < WaitTime)
var TimeLeft := WaitTime - ReadGameClock();
PrintTextAbovePrivate(player, "The cloak needs to recharge. You feel it will take " + TimeLeft + " seconds before you can use it.", player); 
return 0;
endif

var orcolor := GetObjProperty(cloak, "color");
SetObjProperty(cloak, "originalcolor", orcolor); 
SetObjProperty(cloak, "color", 1);
player.stealthsteps := RandomDiceRoll(2d6)+13;
SetObjProperty(player, "InvisCloakTime", ReadGameClock() + 60);


endprogram

Where do you set properties originalcolor and color ? what do you want them to do? And just one tip: don't type all operations in brackets

Posted: Tue Jul 01, 2008 8:35 am
by ncrsn
You have misunderstood the concept of (custom) properties.

See, each object has its own properties: character, in example, has "hidden", "stealthsteps", which you'll want to alter. Scriptwise you reach them like this: object.property. Simple as that.

Code: Select all

// Hide player and give him some stealthsteps.
who.hidden := 1;
who.stealthsteps := 5 + RandomInt(10);

// Print how many steps he got:
print(who.name + " has " + who.stealthsteps + " stealthsteps");
Object's properties are currently handled by core, and are thus hardcoded. See the possible objects' properties and values from here: http://docs.polserver.com/pol097/objref.php.

Custom properties (CProps), on the other hand, allow scripter to create own properties in addition to the normal properties each object of the same type has. You can use those with either GetObjProperty(object, property), SetObjProperty(object, property, value) or EraseObjProperty(object, property), or using methods: object.GetProp(property), object.SetProp(property, value), object.EraseProp(property). GetObjPropertyNames(object) and object.PropNames() allow you to list existing custom properties.

It looked like you already knew how to play with those.

In the end, you just need to be careful when to use custom property and when object's property.


(Edit: fix: added object parameter to functions)

Posted: Wed Jul 02, 2008 4:42 am
by Lunne
qrak:
I wanted the cloak to be able to spawn with different colors, but always go black when equipped and activated.


ncrsn:
I think I understand what you mean. I will alter all the properties to the object.property form. Results coming soon.
Thank you very much.

Posted: Wed Jul 02, 2008 5:02 am
by Lunne
The script seems to be functioning now, at least I can compile it.
There's a problem though:

When I create the inviscloak ingame, and try to equip it, it just drops into my backpack. The server window says:

Warning! scripts/control/invis_cloak.ecl does not exist!
Exception caught while loading script scripts/control/invis_cloak.ecl: Unable to open scripts/control/invis_cloak.ecl for reading.
Unable to read script 'scripts/control/invis_cloak.ecl'
Error reading script scripts/control/invis_cloak.ecl


I do understand that the cloak needs a control script, but I can't figure out:
1. What a control script is.
2. Why the normal cloak located in the tailoring skill package can use the script :combat:itemControl, and not my cloak. I've tried not setting a controlscript, and tried setting it to the :combat:itemControl one, but neither works.





I also have another question, on another item I tried to make.
I asked a friend for ideas on what to try to make, and he said:
A football!

So I tried. I made an item that when stepped upon moves one tile in your direction, but there are two problems:

1. I want to use the small bagball graphic, but when I do, my character cannot walk on that tile. Until I can solve that, I used the bone graphic for it, and it worked just fine. What should I do about this?
2. I need the ball to make sure there is noone on the tile it's about to jump to. Is there a simple way to check if there is a playermobile standing on a tile?

Posted: Thu Jul 03, 2008 3:36 am
by ncrsn
Your compiled script is not in the place where it should be, according the itemdesc config file. To help you out, I have to ask you to tell where did you put the file invis_cloak.ecl? Is it in [pol]/scripts/control? Or packaged somewhere?

About the football: if the height of the graphic of ball is too much, either on client or server side, the character is refused to step onto it. You can check the server side value using .getprop height and targetting the item. Values are read by POL from [pol]/config/tiles.cfg file, so you may be able to change it in there (into something like 2) and get it to work. If client refuses to walk onto it you'd have to update every players client files to get it to work, which is not an easy thing.

To check mobiles on tile, you can use function ListMobilesNearLocation (link to docs: http://docs.polserver.com/pol097/single ... e=uoem.xml). There are also other usable functions in the UO module, I suggest you to check them out.

Posted: Thu Jul 03, 2008 4:40 am
by Lunne
The script used to be in scripts/items, but I moved it to scripts/control. Now, when I equip it it doesn't give an error message in the server window, and I get hidden and stealthy, but it still wont equip. It goes to my backpack as soon as I try to equip it.


You were right about the football, it must be clientwise, because I changed the small bagball information to Blocking 0 and Height 1, and I still can't walk through it. I'll have to search for a better graphic. Ideas?

I tried using the ListMobilesNearLocation command, but I couldn't figure out HOW exactly to use it.

Thank you very much for your help, you're the best.

Posted: Thu Jul 03, 2008 5:06 am
by ncrsn
In the case of (un)equipscript, if the return value is 0, the (un)equip fails. So while you get the benefits of equipping the item, in the end the script tells core to not allow it. So add this as the last line (before the very last line of "endprogram", that is):

Code: Select all

return 1;
Do the same to the unequip script, if necessary.

This information can also be found in the documentations, should you ever forget how it went: http://docs.polserver.com/pol097/scripttypes.php. Scroll down to equipscript and unequipscript. I suggest reading all the other things in there, too.

I cannot think of any ball-like graphic, but that doesn't mean there isn't any. Just keep searching. And use your imagination if search goes in vain.

Usage example of ListMobilesNearLocation coming through;

Code: Select all

// We want to know all the players on the same tile as the ball.
// Remember, x, y, z and realm are properties every UObject has.
// range is 0 so no other tiles around the item are checked.
var playerlist := ListMobilesNearLocation(ball.x, ball.y, ball.z, 0, ball.realm);

foreach player in playerlist
    Print(player.name + " in on the same tile as the ball!");
endforeach
As is, ListMobilesNearLocation only lists visible and alive mobiles (both players and npcs) near the x, y, z location. Documentations mention this, too, just think carefully what you really need when you are about to use this. If you want to include also hidden or dead or concealed people you have to use ListMobilesNearLocationEX-function instead. -- Yeah, not going too deep into that, now.

Posted: Thu Jul 03, 2008 11:46 am
by Lunne
Okey! Thanks a lot for all your help, both items' scripts are finished and functioning.

Now, I have yet ANOTHER question for you, because I just know you love helping me out.

As I said, I wanted the inviscloak to be able to spawn in different colors, and always return to the original color when unequipped. The change-color system works, but what I want to know is:

How do I make an item spawn in a random color?

Posted: Thu Jul 03, 2008 6:18 pm
by ncrsn
You can use the item' createscript to set a randomized color to the cprop. Thus, every time the item is created, it will get a all random color which never changes again.

Createscript documentation: http://docs.polserver.com/pol097/script ... eateScript.

Posted: Fri Jul 04, 2008 1:32 am
by Lunne
Okey the random color script was easy to make, but another problem has occured.


The cloak seems to get bugged, or something. When I equip it, and then unequip it, the next time it is moved or equipped it "disappears", as if it was picked up, but not visible at the cursor. When this happens you can't do anything else that you can't do when carrying something.

Ideas?

Posted: Sat Jul 05, 2008 5:22 am
by ncrsn
I can't really help you with that one.

I know things like that has happen before, even to me, but what I cannot recall is the reasons behind that.

If you cannot solve it out yourself, I suggest that you tell more of the scripts and settings so possible volunteers could try and hopefully tell what's the reason behind that.

And if you do, it would be nice to know what was the problem.