Page 1 of 1
extend default class ?
Posted: Wed Jul 26, 2017 10:03 pm
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.
Re: extend default class ?
Posted: Thu Jul 27, 2017 3:13 am
by RusseL
I dont think its possible now.
Re: extend default class ?
Posted: Thu Jul 27, 2017 5:52 am
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
Re: extend default class ?
Posted: Thu Jul 27, 2017 9:32 am
by Turley
Mmmh
02-03-2010 Turley:
Added: MethodScript support for mobiles
NPC: npcdesc.cfg MethodScript entry
Character: uoclient.cfg section "General" MethodScript entry

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)
Re: extend default class ?
Posted: Thu Jul 27, 2017 12:54 pm
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

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
Re: extend default class ?
Posted: Thu Jul 27, 2017 8:06 pm
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.
Re: extend default class ?
Posted: Sat Jul 29, 2017 10:48 am
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.
Re: extend default class ?
Posted: Tue Aug 01, 2017 5:22 pm
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?
Re: extend default class ?
Posted: Tue Aug 01, 2017 6:25 pm
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?
Re: extend default class ?
Posted: Tue Aug 01, 2017 10:15 pm
by Nando
Does it happen every time? Which core binaries are you using? Did you compile it yourself or downloaded from the boards?
Re: extend default class ?
Posted: Wed Aug 02, 2017 10:31 am
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
Re: extend default class ?
Posted: Wed Aug 02, 2017 6:01 pm
by DevGIB
Does it only happen when calling one of the functions or is it crashing when you boot the server?
Re: extend default class ?
Posted: Wed Aug 02, 2017 10:09 pm
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.
Re: extend default class ?
Posted: Thu Aug 03, 2017 10:03 am
by Nando
Should be fixed now. Let me know if it still happens.

Re: extend default class ?
Posted: Fri Aug 04, 2017 8:33 am
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.