Using "ConsoleCommand" in script. Any alternative?

Discussions about Coding and Scripting
Post Reply
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!

Using "ConsoleCommand" in script. Any alternative?

Post by MrLoathsome »

Scenario:

Mutator is reading values from an ini, that need to be set as default values for a pawn class, that
is also being read from the ini. These values must be set BEFORE the pawn is spawned.
An example would be the bHasBaby default for the UnrealShare.Cow class.

Of course the mutator has to preserve the original default value for the class, to maintain
compatibility with everything else. (And itself.... :omfg: )

Note, this mutator also sets values after the pawn has spawned. No problems with those.
The mutator reads in the Name, Value to be set, and a boolean that tells it if the value
needs to be applied before or after the pawn has spawned.

This question is ONLY about the settings that need applied to the class BEFORE the pawn is actually
spawned by the mutator. (Just to be clear. I hope.....)

I have banged together a solution that seems to work with the things I have tested it with, but it is just ugly I think.... :what:

This bit of code is out of the function that spawns the pawns.

The string values for the SetCnt array and the SetName/DefName arrays used in the ConsoleCommand() calls have been
created & preloaded with the values in the PostBeginPlay() function.

i.e. SetName0[0] = "Set UnrealShare.Cow bHasBaby True" & DefName0[0] = "Set UnrealShare.Cow bHasBaby False"

Here is the code in question:

Code: Select all

   for (i = 0; i<SetCnt[SwarmNum]; i++)
   {
   	switch(SwarmNum) {
		case 3: if ((SetName3[i] != "") && (SwarmSettings3[j].bPreSpawn)) { log(SetName3[i]); ConsoleCommand(SetName3[i]); } break;
		case 2: if ((SetName2[i] != "") && (SwarmSettings2[j].bPreSpawn)) { log(SetName2[i]); ConsoleCommand(SetName2[i]); } break;
		case 1: if ((SetName1[i] != "") && (SwarmSettings1[j].bPreSpawn)) { log(SetName1[i]); ConsoleCommand(SetName1[i]); } break;
		case 0: if ((SetName0[i] != "") && (SwarmSettings0[j].bPreSpawn)) { log(SetName0[i]); ConsoleCommand(SetName0[i]); } break;
	}
   }
   NewPawn = Spawn(aC,,,Location);
   if ( NewPawn == None )
   {
      return false;
   }
   for (i = 0; i<SetCnt[SwarmNum]; i++)
   {
   	switch(SwarmNum) {
		case 3: if ((DefName3[i] != "") && (SwarmSettings3[j].bPreSpawn)) { log(DefName3[i]); ConsoleCommand(DefName3[i]); } break;
		case 2: if ((DefName2[i] != "") && (SwarmSettings2[j].bPreSpawn)) { log(DefName2[i]); ConsoleCommand(DefName2[i]); } break;
		case 1: if ((DefName1[i] != "") && (SwarmSettings1[j].bPreSpawn)) { log(DefName1[i]); ConsoleCommand(DefName1[i]); } break;
		case 0: if ((DefName0[i] != "") && (SwarmSettings0[j].bPreSpawn)) { log(DefName0[i]); ConsoleCommand(DefName0[i]); } break;
	}
   }
Here is the question:

Shirley there must be a better way?

*Bonus point to any reply's that have the correct admonishment as the last line.
blarg
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: Using "ConsoleCommand" in script. Any alternative?

Post by Higor »

ObjectClass.default.bHasBaby = true;
Spawn( ObjectClass);
ObjectClass.default.bHasBaby = false;

Note, this won't replicate the variable change on clients, so only do this on things that are purely processed serverside.
Also, using ConsoleCommand "set" will not only change the class default, but every single actor that has already been spawned.
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Using "ConsoleCommand" in script. Any alternative?

Post by JackGriffin »

MrLoathsome wrote: *Bonus point to any reply's that have the correct admonishment as the last line.
I gotta know now Loathe, what's this mean? BTW if you want to open the console via server mod and do stuff on clients I'll send you the code for that. Don't really want to post that publicly.
So long, and thanks for all the fish
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: Using "ConsoleCommand" in script. Any alternative?

Post by MrLoathsome »

Higor wrote:ObjectClass.default.bHasBaby = true;
Spawn( ObjectClass);
ObjectClass.default.bHasBaby = false;
That was the 1st thought I had, however it becomes problematic to implement in this case since all 3 values used
there, (ObjectClass, bHasBaby and true), are all being read from the ini file, and are in string variables.

Let me rephrase the question. I need functions that do the same thing as Get/SetPropertyText(), but that will function
on ObjectClasses rather than on spawned objects.
Also, using ConsoleCommand "set" will not only change the class default, but every single actor that has already been spawned.
Exactly correct. This is why I will only be using this method on a few settings, such as bHasbaby in the above example, or a
setting such as BirdColor in my NewBirds pawns.

The setting is only used by the pawn when it spawns, so it doesn't matter to other pawns of the same class that are already on the map.
i.e. if you do console command "Set unrealshare.cow bHasbaby true" nothing really happens to cows that have been spawned previously.
Perhaps they get sad because they suddenly think they have a baby they can't find, but they do not all suddenly spawn babies....
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: Using "ConsoleCommand" in script. Any alternative?

Post by MrLoathsome »

JackGriffin wrote:
MrLoathsome wrote: *Bonus point to any reply's that have the correct admonishment as the last line.
I gotta know now Loathe, what's this mean?
I will give you 1 more chance to guess... :lol2:
BTW if you want to open the console via server mod and do stuff on clients I'll send you the code for that. Don't really want to post that publicly.
Thanks for the offer, but I have no need to do that for this mutator. It runs serverside only.

Shirley it is for the best if you keep that code to yourself. :loool:
blarg
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Using "ConsoleCommand" in script. Any alternative?

Post by JackGriffin »

I will, and don't call me Shirley.
So long, and thanks for all the fish
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: Using "ConsoleCommand" in script. Any alternative?

Post by MrLoathsome »

We have a winner.

But the question remains.....
blarg
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Using "ConsoleCommand" in script. Any alternative?

Post by JackGriffin »

I'm glad you got the reference. What can you make of it? Well, I can make a hat or a boat or a...

Best movie ever.

Anyway I'm truly at a loss. Hint?
So long, and thanks for all the fish
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: Using "ConsoleCommand" in script. Any alternative?

Post by MrLoathsome »

Well, that was the extent of my bad joke. I was just waiting for somebody to tell me not to call them Shirley. :gj:

The question that remains, is the one that actually pertains to Coding/Scripting.

I still haven't tracked down a way to do the same thing as Get/SetPropertyText() on ObjectClasses rather than on spawned objects.

Been optimizing the code in the spawning function I have now that uses the ConsoleCommand() function, and it is working the way I want.
Just can't help thinking another way, if there is one, would be faster.
And I could be wrong about that also. Not even sure if the ConsoleCommand function is terribly slow or not. Haven't tried any tests to check its exact execution speed
or anything like that...

Going to attempt a change in the code tonight, that if it works will reduce those operation from 1 per pawn, to 1 per swarm, which should help the minor "spawn lag"
I am still getting with larger swarms.

Current version of this thing supports 16 separate swarms. You can set the swarmclass and drawscale independently for each swarm. Each swarm can have 1 or more
pawns in it. (Haven't even put a check in for max amount. As many as your hardware can handle will be the limit I expect.)
You can optionally set values for up to 8 different default values for each swarm. All read from the ini file, so this should support pawns and defaults that
don't even exist yet.

As you can see, this has huge potential to be very laggy, so I am trying to tweak the piss out of every single line involved.
blarg
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Using "ConsoleCommand" in script. Any alternative?

Post by JackGriffin »

Nelsona and I have been working the last couple of days to get the flies to work with carcass, probably some of the same type of issues you are having. For the record he wants the flies and I don't but it's been very interesting to work through the actual spawning of them in an online game and making them work.

You can't end-around this with a spawnnotify?
So long, and thanks for all the fish
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: Using "ConsoleCommand" in script. Any alternative?

Post by MrLoathsome »

JackGriffin wrote:Nelsona and I have been working the last couple of days to get the flies to work with carcass, probably some of the same type of issues you are having. For the record he wants the flies and I don't but it's been very interesting to work through the actual spawning of them in an online game and making them work.
I know there is a way to do that. You can set my Dropper mutator to spawn swarms of flies on player/monster deaths. Works fine online or off.
Don't even bother messing with SpawnRatsandFlies or any of the default functions/variables unreal has regarding them at all.

Just force a spawn of the swarm at the carcass location. (maybe add 10 or 20 to the location.Z)

However, you want to keep the numbers of those you spawn pretty low for online use. (For both DeadBodySwarm and HorseFlySwarm)
Don't have any exact numbers, but if you get too many of those swarms spawning on a server at the same time, it just hogs the bandwidth.

I still have them spawning on my DM & AS servers, but with very, very low odds of appearing.

After glancing at the very minimal code there in the HorseFlySwarm, about the only other thing I could suggest to improve the performance
online would be to scale back the swarmsize variable. (Next thing I release, should enable you to test that out just by editing an ini file....)
You can't end-around this with a spawnnotify?
Unknown. Somebody else will need to answer that one. Don't recall having to use spawnnotify much in any of the junk I have done so far.
blarg
Post Reply