extend default class ?

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

Moderator: POL Developer

Post Reply
Duttones
Apprentice Poster
Posts: 54
Joined: Tue Mar 27, 2012 8:56 pm

extend default class ?

Post by Duttones »

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: 375
Joined: Fri Feb 20, 2009 8:30 pm

Re: extend default class ?

Post by RusseL »

I dont think its possible now.
DevGIB
Grandmaster Poster
Posts: 248
Joined: Mon Feb 06, 2006 6:12 am

Re: extend default class ?

Post by DevGIB »

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: 670
Joined: Sun Feb 05, 2006 4:45 am

Re: extend default class ?

Post by Turley »

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
Apprentice Poster
Posts: 54
Joined: Tue Mar 27, 2012 8:56 pm

Re: extend default class ?

Post by Duttones »

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: 621
Joined: Wed Jan 25, 2006 2:30 am

Re: extend default class ?

Post by Austin »

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.
Duttones
Apprentice Poster
Posts: 54
Joined: Tue Mar 27, 2012 8:56 pm

Re: extend default class ?

Post by Duttones »

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
Apprentice Poster
Posts: 54
Joined: Tue Mar 27, 2012 8:56 pm

Re: extend default class ?

Post by Duttones »

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 269 times
D__Ultima Online_forgottenlore_pol.exe 2017-08-01 22.22.03.png
DevGIB
Grandmaster Poster
Posts: 248
Joined: Mon Feb 06, 2006 6:12 am

Re: extend default class ?

Post by DevGIB »

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: 282
Joined: Wed Sep 17, 2008 6:53 pm
Contact:

Re: extend default class ?

Post by Nando »

Does it happen every time? Which core binaries are you using? Did you compile it yourself or downloaded from the boards?
Duttones
Apprentice Poster
Posts: 54
Joined: Tue Mar 27, 2012 8:56 pm

Re: extend default class ?

Post by Duttones »

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: 248
Joined: Mon Feb 06, 2006 6:12 am

Re: extend default class ?

Post by DevGIB »

Does it only happen when calling one of the functions or is it crashing when you boot the server?
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: extend default class ?

Post by Yukiko »

He said it happens on shutdown of POL. According to his screen shot it looks like it save the world data then crashes.
Nando
POL Developer
Posts: 282
Joined: Wed Sep 17, 2008 6:53 pm
Contact:

Re: extend default class ?

Post by Nando »

Should be fixed now. Let me know if it still happens. :)
Duttones
Apprentice Poster
Posts: 54
Joined: Tue Mar 27, 2012 8:56 pm

Re: extend default class ?

Post by Duttones »

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