Help with structs

Discussions about Coding and Scripting

Help with structs

Postby JackGriffin » Fri Mar 29, 2019 3:34 pm

I've been messing with something for the last few days but it's pissing me off that I can't work it out. It's got to be something simple I'm just overlooking. The issue: I have a bunch of maps in my coop server that I need to dynamically replace certain weapon classes. They were imported/converted MH maps but ridiculous weapons were imported along with the maps (think AppleBlossom here) and they do nothing but spam log errors. I could use any of the weapon replace mods out there but I'd like to do my own so I understand how it works.

Bleeder is one of my go-to guys and he replied with these code snippets:
Code: Select all
struct sReplaceList
{
    var() string ReplaceMe;
    var() string ReplaceWith;
};
var() array<sReplaceList> ReplaceList;


Code: Select all
local class<Actor> CheckClass;
local int I;


For(I=0; I<Array_Size(ReplaceList); I++)
{
    CheckClass = class<Actor>(DynamicLoadObject(ReplaceList[I].ReplaceMe,class'Actor',True));
    if(bool(CheckClass) && Other.Class==CheckClass)
    {
        ReplaceWith(Other,ReplaceList[I].ReplaceWith);
        return false;
    }
}

I'm very much a brute force coder and I've been slamming my sledgehammer on this for several days. No matter how I try to implement this into CheckReplacement it won't see my checks. This is my replacement line
Code: Select all
ReplaceList=(ReplaceMe=class'StupidWeapon.StupidGun',ReplaceWith[0]=class'BetterWeapon.BetterGun')

I try logging like this:
Code: Select all
log("Check class = "@CheckClass)

but it always returns
Code: Select all
ScriptLog: goHD Mutator active
ScriptLog: Check class =  None
ScriptLog: Check class =  None

I have tried every combination I can think of to get a return on the check class but it never does. WTF am I doing wrong here?
So long, and thanks for all the fish
JackGriffin
Godlike
 
Posts: 3763
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Help with structs

Postby Higor » Fri Mar 29, 2019 5:45 pm

DynamicLoadObject( ... , ... ,True)

True

True

Start there.
Higor
Godlike
 
Posts: 1743
Joined: Sun Mar 04, 2012 6:47 pm

Re: Help with structs

Postby TheDane » Fri Mar 29, 2019 9:37 pm

I once used StuffSwapper back in the days, won't that do the trick for you?

Judging by the ini file it uses structs the way you wish to use them, so have a look there 8)
Attachments
StuffSwapper3.2.zip
(88.71 KiB) Downloaded 11 times
Retired.
User avatar
TheDane
Masterful
 
Posts: 615
Joined: Tue Feb 12, 2008 2:47 pm
Personal rank: Anti EPIC Games fan

Re: Help with structs

Postby sektor2111 » Fri Mar 29, 2019 10:54 pm

Higor did a simple strategy in his MH prototype which was sharing around. I used his idea in XC_MonsterHunt for preventing hard-coded replacements in old style. Advantages:
- if a weapon presumed a good replacement is not really OK you can use another one;
- if something is forgotten can be added later - INI is open for usage;
- if players are asking pure play leaving original weaponry - once again, ini can be edited.
Solution was handy without structs and too much RocketScience.

@TheDane
In 2019 StuffSwapper still does raw replacements:
- missing rotation-rate copied;
- missing respawntime Vs killed pawn DropWhenKilled deal;
- missing instigator checks - Skaarj here;
- missing any deal with stupid setup like bStatic;
- and can write a book about "ReplaceWith" poorly coded things...
Forget ReplaceWith and configure your own - especially when replacements uses the same meshes they should clone properly replaced thing letting original design in Level
Last edited by sektor2111 on Sat Mar 30, 2019 9:42 am, edited 1 time in total.
User avatar
sektor2111
Godlike
 
Posts: 4003
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Help with structs

Postby JackGriffin » Sat Mar 30, 2019 4:50 am

Thank you Higor. This is what happens when I don't research a function all the way to the end and just assume it to be correct as it is given. I appreciate your pointing it out. And the second time....Oh, and the third too :lol2: You remind me of my dad (in a very good way).

Dane, I could use Stuff but I really wanted my own solution built into my HD mod. It's already doing checks and replacing things all over the place so this is a natural fit. I looked at the code for Stuff but it's very involved since it has random swapping. I just need a stone simple way to code dynamic checks as it runs through pickups. Think of it as needing 'StuffSwapperLite'.

Nels, could I look at your class that does the replacing?

Thank you guys for the replies. I get very little free time lately to do much but I enjoy banging around in the coop server when I can.
So long, and thanks for all the fish
JackGriffin
Godlike
 
Posts: 3763
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Help with structs

Postby Chris » Sat Mar 30, 2019 4:57 am

Your replacelist is defined as a structure of strings, yet you assign class types to it. Change the strings to class types too, and remove the DynamicLoadObject completely, it's overkill.
As such:

Code: Select all
struct sReplaceList
{
    var() class<Actor> ReplaceMe;
    var() class<Actor> ReplaceWith;
};
var() array<sReplaceList> ReplaceList;


....
....
....


local class<Actor> CheckClass;
local int I;


For(I=0; I<Array_Size(ReplaceList); I++)
{
    CheckClass = ReplaceList[I].ReplaceMe;
    if(CheckClass != none && Other.Class==CheckClass)
    {
        ReplaceWith(Other,ReplaceList[I].ReplaceWith);
        return false;
    }
}


DynamicLoadObject is only needed when you want to load an object (class) from a package that is unknown at compile time.
Your use of DynamicLoadObject is wrong too, the second parameter is not a UScript class type, it's the object type. In UE, a class is an object, so you want to use class'class', not class'Actor'.
Chris
Experienced
 
Posts: 116
Joined: Mon Nov 24, 2014 9:27 am

Re: Help with structs

Postby Higor » Sat Mar 30, 2019 5:53 am

Let him change the third parameter to FALSE and see the logs :loool:
No better way to learn than failing and understanding why.

PD: If you want to use DynamicLoadObject for making the mutator's replacement INI/INT changeable, use it to precache all replacements in one of the 3 BeginPlay events.
Higor
Godlike
 
Posts: 1743
Joined: Sun Mar 04, 2012 6:47 pm

Re: Help with structs

Postby sektor2111 » Sat Mar 30, 2019 9:35 am

JackGriffin wrote:Nels, could I look at your class that does the replacing?
See Higor's Split MH packages or XC_MonsterHunt through forum, you'll figure "BaseMutator" what does. I have expanded replacements at 64 options - aiming bad weaponry generally...
Chris wrote:Change the strings to class types too, and remove the DynamicLoadObject completely, it's overkill.
Yes, I don't really like it, for such reasons I was trying harder to gain more precaching as possible.
User avatar
sektor2111
Godlike
 
Posts: 4003
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Help with structs

Postby JackGriffin » Sat Mar 30, 2019 2:47 pm

Higor wrote:No better way to learn than failing and understanding why.

This, 100 times over. It's the thing that keeps me coming back. Thank you for doing it this way.
Higor wrote:PD: If you want to use DynamicLoadObject for making the mutator's replacement INI/INT changeable, use it to precache all replacements in one of the 3 BeginPlay events.

Using an ini was the way I'd ideally like to do this and it's why the code had dynamic loading. As I find things in maps that need to be removed it would make everything much easier. I understand the need to precache but is there an example of this that springs to your mind so I can see how to lay it out?

So in general is it better to do away with dynamic loading and make it string checks instead?

Added Edit:
Code: Select all
ScriptLog: goHD Mutator active
Warning: Failed to load 'class'StupidWeapon': Can't find file for package 'class'StupidWeapon'
Warning: Failed to load 'Class StupidGun',ReplaceWith[0]=class'BetterWeapon.BetterGun')': Can't find file for package 'class'StupidWeapon'

Now I understand the need for precaching.
So long, and thanks for all the fish
JackGriffin
Godlike
 
Posts: 3763
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Help with structs

Postby sn260591 » Sun Mar 31, 2019 9:37 am

Need to replace
Code: Select all
ReplaceList=(ReplaceMe=class'StupidWeapon.StupidGun',ReplaceWith[0]=class'BetterWeapon.BetterGun')
with
Code: Select all
ReplaceList=(ReplaceMe="StupidWeapon.StupidGun",ReplaceWith="BetterWeapon.BetterGun")
Sorry for my bad English
User avatar
sn260591
Average
 
Posts: 53
Joined: Sat Jun 01, 2013 10:38 am
Location: Russia

Re: Help with structs

Postby JackGriffin » Sun Mar 31, 2019 4:02 pm

Just to follow up and close this thread...

As per the usual I was overthinking things and that's why I stayed so confused. The checks were a mixture because I didn't think that you could check for a class name (like 'AssaultInfinity' for example) dynamically in an if(Other.IsA(CheckedWeaponName[i])) where the check is handled via a "var() config name CheckedWeaponName[10];" environment without loading the package. Yeah, I know...I try to tell you guys I'm not that smart.

Once that clicked for me and I looked at what Nels had referenced I imported the methodology Higor used in his MH base and it worked immediately. Even better I understand now why it didn't work before. Thank you guys for your time and replies on this. I'm super glad to have it working now.

This is the best of Unreal community in action.
So long, and thanks for all the fish
JackGriffin
Godlike
 
Posts: 3763
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-


Return to Coding, Scripting

Who is online

Users browsing this forum: No registered users and 0 guests