extend default class ?

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.

Moderator: POL Developer

Post Reply
Duttones
Novice Poster
Posts: 49
Joined: Tue Mar 27, 2012 8:56 pm

extend default class ?

Post by Duttones » Wed Jul 26, 2017 10:03 pm

It is possible to add a extended function (methods) to default POL obj classes ?
For example, add a method "getLevel" for characters, and use it like: who.getLevel() ?

I know it is possible for items through method scripts.

RusseL
Forum Regular
Posts: 341
Joined: Fri Feb 20, 2009 8:30 pm

Re: extend default class ?

Post by RusseL » Thu Jul 27, 2017 3:13 am

I dont think its possible now.

DevGIB
Grandmaster Poster
Posts: 182
Joined: Mon Feb 06, 2006 6:12 am

Re: extend default class ?

Post by DevGIB » Thu Jul 27, 2017 5:52 am

As far as i know currently method scripts only apply to items.
There was a discussion previously between core developers which suggested they might look into enabling methods for more class types, but at this stage i'd guess we're not likely to see anything until POL1.00

Turley
POL Developer
Posts: 644
Joined: Sun Feb 05, 2006 4:45 am

Re: extend default class ?

Post by Turley » Thu Jul 27, 2017 9:32 am

Mmmh
02-03-2010 Turley:
Added: MethodScript support for mobiles
NPC: npcdesc.cfg MethodScript entry
Character: uoclient.cfg section "General" MethodScript entry
:P
items/multis in itemdesc.cfg per objtype
NPC in npcdesc.cfg per template
Character generally in uoclient.cfg

What is/was under discussion is to have a place to define at one specific spot all "default" methods independent of the objtype/template. Currently you have to add the right MethodScript to each item definition/npctemplate. It's a bit of work but with a few includes you can easily define default behaviour with specific overrides. (I personally used this for the tooltip pkthook to create in a fast way without dozen of objtype checks default and specific texts)

Duttones
Novice Poster
Posts: 49
Joined: Tue Mar 27, 2012 8:56 pm

Re: extend default class ?

Post by Duttones » Thu Jul 27, 2017 12:54 pm

Turley wrote:
Thu Jul 27, 2017 9:32 am
Mmmh
02-03-2010 Turley:
Added: MethodScript support for mobiles
NPC: npcdesc.cfg MethodScript entry
Character: uoclient.cfg section "General" MethodScript entry
:P
items/multis in itemdesc.cfg per objtype
NPC in npcdesc.cfg per template
Character generally in uoclient.cfg

What is/was under discussion is to have a place to define at one specific spot all "default" methods independent of the objtype/template. Currently you have to add the right MethodScript to each item definition/npctemplate. It's a bit of work but with a few includes you can easily define default behaviour with specific overrides. (I personally used this for the tooltip pkthook to create in a fast way without dozen of objtype checks default and specific texts)
Wow!
Thanks!
It will make the code much more easy and beauty

User avatar
Austin
Former Developer
Posts: 612
Joined: Wed Jan 25, 2006 2:30 am
Contact:

Re: extend default class ?

Post by Austin » Thu Jul 27, 2017 8:06 pm

I think I remember a discussion from 2011.. heh!
I just remembered about this idea the other day and felt i should document it in case someone feels a coder itch.

We have a tree for how objects in POL are abstractions of other things

Code: Select all

            UObject             Account         PolCore()    DataFileElement
               |
               |                Guild           Script       Datastore
     +---------+--------+
     |                  |       Array           Dictionary   Datafile
   Character           Item
     |                  |       AuxConnection   Error        String
    NPC                 |
                        |                                    Struct
     +------------------+--------------+-----------+
     |                  |              |           |         Package
 Equipment           Lockable         Map        Multi
     |                  |                          |         Packet
 +---+----+        +----+--------+            +----+----+
 |        |        |             |            |         |    Party
Armor  Weapon     Door        Container      Boat     House
                                 |                           BinaryFile
                            +----+----+
                            |         |
                         Spellbook   Corpse
So what if we had a Methods.cfg file.

Code: Select all

Elem Corpse
{
   MethodScript :pkg:xyz
}
Elem Container
{
   MethodScript :pkg:abc
}
Then if you have a corpse object in the script - you can call a method like corpse.MoveToJail();
Corpse's method script doesn't have this... so then the core goes to the next up, Container, its not there, so it goes up until the method is found. Lets pretend Item has it.

If the itemdesc.cfg methodscript has a matching function name - itll use that instead.. or could have an override like _method() for using core methods.


This would let scripts extend other things like Datafiles, Arrays, Dictionaries, etc.
-Austin

Duttones
Novice Poster
Posts: 49
Joined: Tue Mar 27, 2012 8:56 pm

Re: extend default class ?

Post by Duttones » Sat Jul 29, 2017 10:48 am

Would be great if it works this way. I really would use method functions for all npcs and characters. One thing I miss from ServUO on POL is the override function from C#.

Methods is a simple way to act like overrides.

Duttones
Novice Poster
Posts: 49
Joined: Tue Mar 27, 2012 8:56 pm

Re: extend default class ?

Post by Duttones » Tue Aug 01, 2017 5:22 pm

After I added the methodScript for characters on uoclient.cfg, every time I close POL it crashes and create a minidump.

Does anyone know of fix for that?
Attachments
20170801222138-0.dmp
(49.56 KiB) Downloaded 8 times
D__Ultima Online_forgottenlore_pol.exe 2017-08-01 22.22.03.png

DevGIB
Grandmaster Poster
Posts: 182
Joined: Mon Feb 06, 2006 6:12 am

Re: extend default class ?

Post by DevGIB » Tue Aug 01, 2017 6:25 pm

Firstly are you running the most recent core?
The most recent patch fixed some major crash errors when it came to method scripts.

Secondly the method script crashes were related to core function scripts in method scripts which require user input e.g. target() or RequestInput() or SendInputGump().

What is your method trying to do?

Nando
POL Developer
Posts: 260
Joined: Wed Sep 17, 2008 6:53 pm
Contact:

Re: extend default class ?

Post by Nando » Tue Aug 01, 2017 10:15 pm

Does it happen every time? Which core binaries are you using? Did you compile it yourself or downloaded from the boards?

Duttones
Novice Poster
Posts: 49
Joined: Tue Mar 27, 2012 8:56 pm

Re: extend default class ?

Post by Duttones » Wed Aug 02, 2017 10:31 am

Yes, it happens every time.

I'm using the latest POL version from github, compiled myself. I always try to be up to date with the last versions.
If I remove the methods for characters, it doesn't crash when the server shutdown.

The methods just have some exported functions to check PropEdits, I not even use the listed methods you said in my server, except for Target of course, but I'm not using it on the character methods script.

Except if I need to do something special for the character methods, it is not soo much different from any method script I have in my shard.

Code: Select all

use os;
use uo;

include "include/arrays";

program Install()
    return 1;
endprogram

exported function GetLevel( who )
	var chardata := GetObjProperty(who, "chardata");
	var charlevel := chardata["level"];

	if (charlevel == error || !charlevel)
		SetLevel(who, 0);
		charlevel := 0;
	endif

	return charlevel;
endfunction

exported function setLevel(who, level)
	var chardata := GetObjProperty(who, "chardata");
	chardata.level := level;
	SetObjProperty(who, "chardata", chardata);
	return 1;
endfunction

exported function isClass(who, class)
	var chardata := GetObjProperty(who, "chardata");

	if (Lower(chardata.classe) == Lower(class))
		return 1;
	endif

	return 0;
endfunction

exported function SkillList(who)
	var chardata   := GetObjProperty(who, "chardata");
	var skill_list := chardata.Skills;

	if (!skill_list)
		skill_list := array{};
	endif
	
	return skill_list;
endfunction


exported function GetExp(who)
	var chardata := GetObjProperty(who, "chardata");
	var exppoints := chardata["exppoints"];
	if (exppoints == error || !exppoints)
		SetExp(who, 0);
		exppoints := 0;
	endif

	return exppoints;
endfunction

exported function SetExp(who, points)
	var chardata := GetObjProperty(who, "chardata");
	chardata["exppoints"] := points;
	SetObjProperty(who, "chardata", chardata);
	return 1;
endfunction


exported function GetPoints(who)
	var chardata := GetObjProperty(who, "chardata");
	var attpoints := chardata["attpoints"];
	if (attpoints == error || !attpoints)
		SetPoints(who, 0);
		attpoints := 0;
	endif
	return attpoints;
endfunction

exported function SetPoints(who, points)
	var chardata := GetObjProperty(who, "chardata");
	chardata["attpoints"] := points;
	SetObjProperty(who, "chardata", chardata);
	return 1;
endfunction

DevGIB
Grandmaster Poster
Posts: 182
Joined: Mon Feb 06, 2006 6:12 am

Re: extend default class ?

Post by DevGIB » Wed Aug 02, 2017 6:01 pm

Does it only happen when calling one of the functions or is it crashing when you boot the server?

Yukiko
Distro Developer
Posts: 2411
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: extend default class ?

Post by Yukiko » Wed Aug 02, 2017 10:09 pm

He said it happens on shutdown of POL. According to his screen shot it looks like it save the world data then crashes.
Sincerely,
Yukiko

I would tell you a UDP joke but you might not get it.

Titus 2:13

Nando
POL Developer
Posts: 260
Joined: Wed Sep 17, 2008 6:53 pm
Contact:

Re: extend default class ?

Post by Nando » Thu Aug 03, 2017 10:03 am

Should be fixed now. Let me know if it still happens. :)

Duttones
Novice Poster
Posts: 49
Joined: Tue Mar 27, 2012 8:56 pm

Re: extend default class ?

Post by Duttones » Fri Aug 04, 2017 8:33 am

Nando wrote:
Thu Aug 03, 2017 10:03 am
Should be fixed now. Let me know if it still happens. :)
Thanks. I'll try it tonight and let you know of any problems.

Post Reply