Retrieving the package name of an Actor

Discussions about Coding and Scripting
User avatar
Barbie
Godlike
Posts: 2802
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Retrieving the package name of an Actor

Post by Barbie »

How to get the package name an Actor is defined in?
Examples:
Actor 'Botpack.UT_Eightball' -> 'Botpack' is needed
Actor 'UnrealShare.DispersionPistol' -> 'UnrealShare' is needed
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
MrLoathsome
Inhuman
Posts: 958
Joined: Wed Mar 31, 2010 9:02 pm
Personal rank: I am quite rank.
Location: MrLoathsome fell out of the world!

Re: Retrieving the package name of an Actor

Post by MrLoathsome »

I think all you have to do is parse Actor.Self

*Or maybe Actor.Self.Class
** Or maybe Actor.Self.Class.Outer
Last edited by MrLoathsome on Sun Jun 12, 2016 9:32 am, edited 2 times in total.
blarg
User avatar
Barbie
Godlike
Posts: 2802
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Retrieving the package name of an Actor

Post by Barbie »

ucc.exe wrote:Error, Unrecognized member 'self' in class 'Actor'
:lol:
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: Retrieving the package name of an Actor

Post by Higor »

Do not bother for he who does not bother.
MrLoathsome
Inhuman
Posts: 958
Joined: Wed Mar 31, 2010 9:02 pm
Personal rank: I am quite rank.
Location: MrLoathsome fell out of the world!

Re: Retrieving the package name of an Actor

Post by MrLoathsome »

Whoops. I left off a bit, (.Class), as I was going by memory when I posted that. And was sort of posting pseudo-code.
(I thought you guys would figure that out.... :roll: )

Here is a tested example.

This line of code in a mutator actor class named SwarmSpawn.SS:

Code: Select all

	log(Self.Class);
Will result in this log line:

Code: Select all

ScriptLog: SwarmSpawn.SS

Code: Select all

Self.Class
You should be able to parse that somehow....

Unless I am not understanding your question completely.
In which case, ignore all of the above.
Last edited by MrLoathsome on Sun Jun 12, 2016 7:02 am, edited 4 times in total.
blarg
MrLoathsome
Inhuman
Posts: 958
Joined: Wed Mar 31, 2010 9:02 pm
Personal rank: I am quite rank.
Location: MrLoathsome fell out of the world!

Re: Retrieving the package name of an Actor

Post by MrLoathsome »

Higor wrote:Do not bother for he who does not bother.
W.T.F. does that mean?
blarg
User avatar
sektor2111
Godlike
Posts: 6410
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Retrieving the package name of an Actor

Post by sektor2111 »

I have something but I'm not sure how well does it work from inside of an iterator (any) because simply STRINGS operations are like a doggy slow. Something in engine rejects such a "lag" crap. Look at GetItemName and do some modifications. Mutator calling that thing a single time return good results. If gets called from PawnList or Foreach looks garbled...
Look at a log operated by a small mutator + trying to retrieve package for a few monsters - looks nasty:

Code: Select all

ScriptLog: GetPackageOrigin::  for Behemoth3
ScriptLog: Behemoth3 belongs to package 
ScriptLog: GetPackageOrigin::  for Behemoth2
ScriptLog: Behemoth2 belongs to package 
ScriptLog: GetPackageOrigin::  for Behemoth1
ScriptLog: Behemoth1 belongs to package 
ScriptLog: GetPackageOrigin::  for Behemoth0
ScriptLog: Behemoth0 belongs to package 
ScriptLog: GetPackageOrigin:: UNREAL for Gasbag0
ScriptLog: Gasbag0 belongs to package UNREAL
ScriptLog: GetPackageOrigin:: LOGGER_A for Informer0
ScriptLog: Informer0 belongs to package LOGGER_A
The only good thing was Mutator itself, the rest is trash.
Aside, I was wonder why do you need that, I did not see many coders using craps slowing down servers. Like I said you have a "string" problem which is not a charm in UnrealEngine.
Gotta do more research... I'll be back.
Edit: See this - simply is garbled or I don't have a clue how to speed it up. Mutator responds well but not really the rest
Spoiler
class Informer expands mutator;

var DeathMatchPlus MyGame;
var bool Initialized;

function PostBeginPlay()
{

if (Initialized)
return;
Initialized = True;
Level.game.registerdamagemutator(Self);
Level.game.registermessagemutator(Self);
log ("A test mutator has been initiated...");
MyGame = DeathMatchPlus(Level.Game);
SetTimer(5,True);
}

function CallManure()
{
Local ScriptedPawn S;
Local Pawn P;
Local String Strg;
for ( P=Level.PawnList; P!=None; P=P.nextPawn )
{
if ( ScriptedPawn(P) != None && P.Health > 0 )
{
S=ScriptedPawn(P);
strg=GetPackageOrigin(S);
log(S.Name@"belongs to package"@strg);
}
}
strg=GetPackageOrigin(Self);
log (Self.Name@"belongs to package"@strg);
}

event Timer()
{
CallManure();
}

function String GetPackageOrigin(Actor AnActor)
{
Local string FullName, Temp;
Local int pos;

Temp="None";
if (AnActor == None) return Temp;
FullName="";
pos=0;
FullName=CAPS(AnActor.Class);
pos = InStr(FullName, ".");
StillMove:
if ( pos != -1 )
{
FullName = Left(FullName, Len(FullName) - pos - 1);
pos = InStr(FullName, ".");
Goto StillMove;
}
log ("GetPackageOrigin::"@FullName@"for"@AnActor.Name);
return FullName;
}
ENJOY :ironic:
User avatar
Wormbo
Adept
Posts: 258
Joined: Sat Aug 24, 2013 6:04 pm
Contact:

Re: Retrieving the package name of an Actor

Post by Wormbo »

Not None-safe: (logs two warnings for None input, but returns correct value)

Code: Select all

function String GetPackageOrigin(Actor AnActor)
{
    return string(anActor.Class.Outer);
}
None-safe version:

Code: Select all

function String GetPackageOrigin(Actor anActor)
{
    if (anActor == None)
        return string(None);
    return string(anActor.Class.Outer);
}
This works because all objects have a class and classes are always directly located in a top-level package.
User avatar
sektor2111
Godlike
Posts: 6410
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Retrieving the package name of an Actor

Post by sektor2111 »

Small errata

Code: Select all

function String GetPackageOrigin(Actor AnActor)
{
	Local string FullName, Temp;
	Local int pos;

	Temp="None";
	if (AnActor == None) return Temp;
	FullName="";
	pos=-1;
	FullName=CAPS(AnActor.Class);
	log (FullName);
	pos = InStr(FullName, ".");
	log (pos);
	if ( InStr(FullName, ".") > 0 )
	{
		FullName=Left(FullName, InStr(FullName, "."));
	}
	log ("GetPackageOrigin::"@FullName@"for"@AnActor.Name);
	return FullName;
}
But I have to try other options of course.
But related to Wormbo's suggestion I think I got an idea for my MHReplacer...
Chris
Experienced
Posts: 134
Joined: Mon Nov 24, 2014 9:27 am

Re: Retrieving the package name of an Actor

Post by Chris »

MrLoathsome wrote:
Higor wrote:Do not bother for he who does not bother.
W.T.F. does that mean?
Let me translate:
Don't bother helping someone who does not bother to understand. In this case barbie was joking, Higor knows that, therefore Higor is joking too.
MrLoathsome
Inhuman
Posts: 958
Joined: Wed Mar 31, 2010 9:02 pm
Personal rank: I am quite rank.
Location: MrLoathsome fell out of the world!

Re: Retrieving the package name of an Actor

Post by MrLoathsome »

Chris wrote:
MrLoathsome wrote:
Higor wrote:Do not bother for he who does not bother.
W.T.F. does that mean?
Let me translate:
Don't bother helping someone who does not bother to understand. In this case barbie was joking, Higor knows that, therefore Higor is joking too.
I hope so. Otherwise my next reply to Higor was gonna get me kicked off the forum. :satan: :tongue:

I like Wormbo's response better. :tu:

It extends my 2nd, more detailed post.

@Sektor. Nice job on re-inventing the ".Outer" wheel.
Exactly what I had in mind when I was suggesting parsing Actor.Class

In matters such as this, we should ALL just wait a bit to see what Wormbo has to say about it.
blarg
User avatar
Barbie
Godlike
Posts: 2802
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Retrieving the package name of an Actor

Post by Barbie »

Wormbo and MrLoathsome wrote:anActor.Class.Outer
That was it, thanks. :tu: I was already on the track with "Outer" but "anActor.Outer" returns the map name only.
sektor2111 wrote:Aside, I was wonder why do you need that
I want to replace some non stock items. Detecting if an item belongs to a class can usually be done by »ThisActor.IsA('WhatEver')« or »WhatEver(ThisActor) != None«, but then the server and the clients have to include the foreign package for all maps just to get rid of some items in a single map. So I decided to identify these items by their class name with »if (ThisActor.Class.Name == 'WhatEver')«. But what happens, if items of another package has the same class name? Then this method may detect wrong items and so I want to make sure that the item of interest belongs to the package XYZ:

Code: Select all

if (ThisActor.Class.Name == 'WhatEver' && String(ThisActor.Class.Outer) == "xyz")
(For example »MH-RiseOfDead[NoDaytime]« includes both »DC-Pawns2.u« and »DC-Pawns3.u« which have a lot of same-named classes.)
sektor2111 wrote:Like I said you have a "string" problem
Yep, the theory of everything isn't fully developed yet:
Image
But seriously, I have no idea what you mean by this. :noidea

<EDIT>
added string typecasting to "ThisActor.Class.Outer"
</EDIT>
Last edited by Barbie on Sun Jun 12, 2016 5:47 pm, edited 1 time in total.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
sektor2111
Godlike
Posts: 6410
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Retrieving the package name of an Actor

Post by sektor2111 »

Because you can spy "Other.Class" if "left" from "string class" whatever letters match some evil creature just put it down... that is easy. Btw formula above I guess can save AttitudeToPlayer right ? :lol:

Now The Credit Section
Because you set me on a research I could figure some things today... that's another story off topic here... I have to rewrite a few things at my MH2 then...
MrLoathsome wrote: @Sektor. Nice job on re-inventing the ".Outer" wheel.
If you check well the last one shown by me is able to get package-name even from current class ( mutator itself or whatever ) - credit goes at LoathSome (or Core ?) - stuff already done...
User avatar
Barbie
Godlike
Posts: 2802
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Retrieving the package name of an Actor

Post by Barbie »

sektor2111 wrote:Because you can spy "Other.Class"
Whoo, its even simpler then:

Code: Select all

if (String(A.class) == "PackageName.Classname")
:gj:
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
Wormbo
Adept
Posts: 258
Joined: Sat Aug 24, 2013 6:04 pm
Contact:

Re: Retrieving the package name of an Actor

Post by Wormbo »

See, that's why you state your root intent, not the problem you ran into while pursuing one particular approach of which you don't even know whether it will actually solve your problem.
Post Reply