scripting..

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Damo307
Expert Poster
Posts: 79
Joined: Fri Jul 07, 2006 1:32 am

scripting..

Post by Damo307 »

dose anyone know any good tips or tricks nor guides on learning to 'Escript' ? i looked at some and i just done undertsand them =(, i keep getting lost so could someone please help?
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

If you have no previous experience with programming it will be harder for you than those of us who have done programming before. I recommend looking at the smaller <dot> commands found in \pol\scripts\textcmd

Read the guides on the POL homepage under documentation.

Unfortunately the docs assume some previous experience with programming. You should have a basic understanding of variables, program structure, program flow control and object oriented programming. But take heart that it is possible to learn without any previous knowledge. My son was able to learn and he had no experience before. You just need someone to go to with basic questions. Feel free to ask them here.
Damo307
Expert Poster
Posts: 79
Joined: Fri Jul 07, 2006 1:32 am

Post by Damo307 »

ok cool thanks

i started with a little easy script ^_^, world chat but i wonna know how can i change the color? i tested it in game and it works but it comes up grey :( i wont it to be like green or something

this is what I've done so far:



use uo;

program textcmd_wc( who, text )
var ppl := EnumerateOnlineCharacters();
foreach x in ppl
if (x.cmdlevel > 0)
SendSysMessage(x, "World Chat From " + who.name + ": " + text);
endif
endforeach
endprogram
qrak
Grandmaster Poster
Posts: 198
Joined: Sun Feb 05, 2006 4:35 pm

Post by qrak »

Change the:

Code: Select all

SendSysMessage(x, "World Chat From " + who.name + ": " + text); 
to:

Code: Select all

SendSysMessage(x, "World Chat From " + who.name + ": " + text, 3, 67); 
uo.em module is good place to look how to use most of functions.
Damo307
Expert Poster
Posts: 79
Joined: Fri Jul 07, 2006 1:32 am

Post by Damo307 »

:Dahh.. ok, thanks heaps man ^_^ :D im just a noobie scriprter trying to start off with some easy stuff, so yeah i might be posting alot lol. Also whats the code? everyone dose to put there script in that box thing:D

:( i tryed to make a .fkill script just like .lkill but a flamestrike insted of the lightingblot but i seem to have a error and being a noobie scripter and all i cant find it :(




use os;
use uo;
use boat;

include "include/client";
include "include/attributes";

program textcmd_kill( who )
var tgt := Target( who);

var mob := tgt.mobile;

PlayFlameStrikeEffect( tgt);
PlaySoundEffect( tgt, SFX_SPELL_FLAMESTRIKE );


RevokePrivilege( tgt, "invul" );
SetObjProperty(tgt, "guardkill", 1)
ApplyRawDamage( tgt, GetMaxHp(tgt) );


endprogram
User avatar
Tritan
Grandmaster Poster
Posts: 147
Joined: Sat Feb 04, 2006 8:17 am

Post by Tritan »

What version of POL are you using? I do not remember seeing the " PlayFlameStrikeEffect( tgt); " anyplace. Is this a function you created or is it part of the newer cores?

I have something close to this but I use the example below to generate the effects.

Code: Select all

PlayStationaryEffect(tgt.x, tgt.y, tgt.z, 0x3709, 0x0a, 0x1e);
PlaySoundEffect(tgt, SFX_SPELL_FLAME_STRIKE);
This plays the effects and sounds for the target. Then again I am using POL95 core.
Damo307
Expert Poster
Posts: 79
Joined: Fri Jul 07, 2006 1:32 am

Post by Damo307 »

im using pol 95,

how do i add new loot to the nlootgroup.cfg and so if its a rare item its randomly added to a crops of the monster but not every time you kill it?
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

Just a bit of advice on the SendSysMessage and other function calls that have default parameters. I usually specify the values by reference in the function call. Like this:

Code: Select all

SendSysMessage (who, "This message will be in green with a wide font.", font := 2, color := 66);
Using the references for the various options makes it more readable when trying to debug code but more importantly doing it that way you can change the colour or font without affecting the other default values used by that function.
Danielle
Grandmaster Poster
Posts: 104
Joined: Tue Feb 07, 2006 3:32 pm

Post by Danielle »

The former POL wiki... this is the development copy I maintained. I would work here before I would make changes to the official one.

Well the official one has been MIA for a long time, so figured I might aswell share the link to this one.

http://polwiki.winterboard.com/index.ph ... =Main_Page

And this is slightly related and may help you too... these are the coding standards I always adheared too:

http://www.winterboard.com/nightscape/c ... dards.html
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

YAY!!!
The Wiki is back!

*does a hoola dance*
*sings - 'unica oua wiki wiki'*
*laughs*
Damo307
Expert Poster
Posts: 79
Joined: Fri Jul 07, 2006 1:32 am

Post by Damo307 »

i made new ore and all, and it works, but when i just try to blacksmith out of it to test to make sure it all is working it just says in game

"You can't forge that.
You have no chance working successfully with that metal"

even if i change my blacksmith to 6000, i get the same message
Marilla

Post by Marilla »

Yukiko wrote:Just a bit of advice on the SendSysMessage and other function calls that have default parameters. I usually specify the values by reference in the function call. Like this:

Code: Select all

SendSysMessage (who, "This message will be in green with a wide font.", font := 2, color := 66);
Using the references for the various options makes it more readable when trying to debug code but more importantly doing it that way you can change the colour or font without affecting the other default values used by that function.
Just a note; What you have done there is called using Named Arguments/Parameters, by including the name before the value in the parameter list of the function call.

I say that, because the term 'reference' has a completely different meaning for function parameters; A parameter passed by reference is the opposite of passing it by value, and is similar to passing a pointer. It does not have anything to do with naming the parameter when calling the function.

When you pass a parameter by value, you are passing a copy of the value to the function. When you pass a parameter by reference, you pass instead a 'reference' to the memory location of the variable.

The main difference between the two is that when you pass a reference, any changes the function does to that reference affect the original variable. When you pass by value (the default), no changes carry through.

Consider the following simple code:

Code: Select all

use uo;

program test(who)
	var victim := target(who);
	SendSysMessage(who, victim.name);
	GetNewVictim(victim, who);
	SendSysMessage(who, victim.name);
endprogram

function GetNewVictim(what, who)
	what := target(who);	
endfunction
Run this, and target first yourself, and then another mobile. What do you think the results will be? Because GetNewVictim() declares both of its parameters as the default, "by value", no matter what you select with the second target, the second SendSysMessage will repeat the same victim.name as it said the first time.

However, do this one simple change:

Code: Select all

use uo;

program test(who)
	var victim := target(who);
	SendSysMessage(who, victim.name);
	GetNewVictim(victim, who);
	SendSysMessage(who, victim.name);
endprogram

function GetNewVictim(byref what, who)
	what := target(who);	
endfunction
Note the addition of the 'byref' keyword. That signifies that the 'what' parameter is being passed by reference. Instead of it making a separate, local copy of what for use within the function, it uses the same memory location.

When you run this code this time, and target two different things, you will get each of their separate names printed.

Another example:

Code: Select all

use uo;

program test(who)
	var one := "1";
	SendSysMessage(who, one);
	Testing(one);
	SendSysMessage(who, one);
endprogram

function Testing(what)
	what := "2";
endfunction
Run this, and you will get:
1
1

Do the same simple change as noted above:

Code: Select all

use uo;

program test(who)
	var one := "1";
	SendSysMessage(who, one);
	Testing(one);
	SendSysMessage(who, one);
endprogram

function Testing(byref what)
	what := "2";
endfunction
And this time, you get:
1
2

The default, by value, makes a 'copy' of the variable, which will not affect the original variable. Marking a parameter as 'byref' or by reference, means that the ADDRESS of the variable is passed, and so any assignments you do to the variable WILL carry through back in the original caller, if the original caller uses that variable again.


There's one place where this is very important: In Packet Hook scripts. You may have noticed packet hook functions are declared like so:

Code: Select all

function HandleB9(who, byref packet)
   ....
endfunction
The reason for this is simple; If you leave off the 'byref', then the 'caller' of the packet hook will not be given the changes you made to the packet, because 'byval' makes a separate copy.



Generally speaking, byref parameters aren't really needed all that often, particularly with parameters that are object references. Now, this might get confusing, but object references can themselves be passed by reference, or by value.

That is, you have to keep in mind that an 'object reference' or 'object variable' is itself a memory location that merely points to an instance of an object. That might sound confusing, but you actually already know this fact intuitively, because you know what this code does:

Code: Select all

program DotCommand(who)
    who := target(who);
endprogram
When you run this, and target something other than yourself, you know that this code does not 'morph' your character into whatever you just targetted; it merely changes the 'who' reference to point to that object, instead of to you. So really, you already know what a 'reference' is. On the other hand, you also know what a 'value' is:

Code: Select all

program DotCommand(who)
   who.color := 100;
endprogram
You know that who.color is a value - not a reference. (the fact that .color is a member of who is merely incidental to this discussion, and not actually central. I use it only because a simple variable would not cause an actual change in the world that you could see: your skin color changing). When you set who.color to a different number, you are actually changing the value of something - not just pointing a reference to a different object.

eScript variables are completely flexible - they can hold a reference one moment, and a value the next. Like so:

Code: Select all

program DotCommand(who)
    who := 1;
endprogram
Running that code won't delete your character and turn it into a number 1; It will simply replace the 'who' reference with a value of 1.



=========================


So, we have variables that can be values and references. We also have function parameters that can be passed by value or by reference. What's the relation here? Does one type of variable demand a certain type of function parameter? No, it doesn't. You can pass either type of variable in either way: You can pass a reference variable byref or byval, and you can pass a value variable byref or byval (I'm not sure if there is a literal 'byval' keyword, but it's not needed; remember: the default, if you don't specify, is byval.)


Though it may have been subtle, my first two examples showed passing references byval and byref. I alternated between how to pass 'what', but in both cases, 'who' (the reference to the dot-command-user) was always byval. However, we know that 'who' refers to an object - your PC. That's perfectly valid.

What this means is when I pass 'who' to that function, a local copy of the value of 'who' is created on the stack for the function. The 'value' of that variable happens to be a reference. Confused yet? Yes.. a reference is, itself, a value.

If you pass that reference BY reference, any changes you do to that reference also 'pass back' to the caller, just as you saw with the 'what' parameter when we had the 'byref'. But when you pass the reference by value, no changes you do to the reference will pass back to the caller - the caller's "who" reference will remain safely pointed at you.



Errr... anyway; I know we didn't need all of that just now... but I did think it was important not to confuse the issue of 'reference' parameters/arguments to functions, because there is a specific meaning to that. You were using named arguments and in fact, NOT using reference parameters (because the function you are calling does not define its parameters as references, but instead as values.)
User avatar
Tritan
Grandmaster Poster
Posts: 147
Joined: Sat Feb 04, 2006 8:17 am

Post by Tritan »

Thanks alot Marilla. That cleared up some things I was wondering about. I saw other scriptors use the byref before but never really did dig into why or understood why until now. Everyone can learn something on these forums. ;)
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

Yep. You're right. Thanks Marilla. I was in a hurry earlier and didn't check my verbage. BTW just so you know, I appreciate the teaching you do here. I usually save them in my POL Knowledge Base folder.
Damo307
Expert Poster
Posts: 79
Joined: Fri Jul 07, 2006 1:32 am

Post by Damo307 »

i've tryed to make a 'Flame Tile' but it wont work, so i dont know if or were there might be an error

----------------------------------------------
item 0xfa09
{
Name flametile
Desc Flame Tile
color 1176
Graphic 6173
WalkOnScript fstrike
Movable 0
}
----------------------------------------------
use os;
use uo;

include "include/client";

const EFFECT_FSTRIKE := 0x3709;
const SOUND_EFFECT_RES := 0x215;

program resfield(mobile)
set_critical(1);
if(mobile.dead)
return;
endif
endprogram
----------------------------------------------
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

Well, you have to actually do the flamestrike animation and play the sound effect as well as doing the damage to the mobile.

See PlayObjectCenteredEffect, PlaySoundEffect and ApplyDamage under UO.EM in the POL docs section of the website. I'd recommend looking at the flamestrike spell script as well to determine the amount of damage it applies and to determine how resisting spells skill affects damage, if you want to take spell resistance into effect on this tile that is.
Damo307
Expert Poster
Posts: 79
Joined: Fri Jul 07, 2006 1:32 am

Post by Damo307 »

ahhh ok thanks :D
Damo307
Expert Poster
Posts: 79
Joined: Fri Jul 07, 2006 1:32 am

Post by Damo307 »

how do i go when it comes adding a new loot group to 'nlootgroup.cfg' ?

i wont to add something like

Group VampireArmor
{
Item 1 vampiregloves
Item 1 vampireArms
Item 1 vampirelegs
Item 1 vampiretunic
Item 1 vampirehelm
}


but when i do add that there, add it to a monster as a loot, you can never pick any bit of it up
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

That last question is a different topic.
I assume from your description that they appear in the corpse. Is it marked as movable?
Damo307
Expert Poster
Posts: 79
Joined: Fri Jul 07, 2006 1:32 am

Post by Damo307 »

oh sorry i didnt know my last question is a different topic.
ahh.. there we go, but when it becomes loot, its not the set color i wont it to be, it looks just like bonearmor
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

Did you give the new armour a new colour in the itemdesc file where it is defined?
Damo307
Expert Poster
Posts: 79
Joined: Fri Jul 07, 2006 1:32 am

Post by Damo307 »

yeah i did, when i do .create vampiretunic , it comes in the color i wont it to, but when you kill a monster, and find it in the crops, its the same color as bone armor
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

Well, I can't answer this one. It's strange. Maybe someone else can help.
Sorry.
Damo307
Expert Poster
Posts: 79
Joined: Fri Jul 07, 2006 1:32 am

Post by Damo307 »

thats ok, you've been a great help to me :D

i fort ill just post a part of the vampire armor up here, mayb i could of put an error there


-------------------------------------------------------------------
Armor 0x1d93
{
Name vampiretunic
Desc Vampire Tunic
AR 40
Graphic 5199
Color 1996
Coverage Body
MaxHP 41
strrequired 40
medloss 2000
movable 1
equipscript equip
unequipscript unequip
controlscript itemControl
destroyscript destroy
}
-------------------------------------------------------------------
User avatar
CWO
POL Expert
Posts: 1160
Joined: Sat Feb 04, 2006 5:49 pm

Post by CWO »

If you're using the same type of loot system I am (kinda sounds like it), you have to put the color param after the item name in the loot.

Group VampireArmor
{
Item 1 vampiregloves 1996
Item 1 vampireArms 1996
Item 1 vampirelegs 1996
Item 1 vampiretunic 1996
Item 1 vampirehelm 1996
}
Post Reply