Starting some scripting, looking for some commands

Discussions about Coding and Scripting
Marscaleb
Average
Posts: 48
Joined: Tue Jun 07, 2016 6:50 am

Re: Starting some scripting, looking for some commands

Post by Marscaleb »

Okay, I am almost done with all the changes I wanted to make, but I have two questions left.

One, how do I check if a player is dead? (And with that, also know if they respawn.)

Two, is there a way to not have the crosshair rendered on the screen? Hopefully a simple way that doesn't stop localized messages from being drawn on the screen...
ShaiHulud
Adept
Posts: 459
Joined: Sat Dec 22, 2012 6:37 am

Re: Starting some scripting, looking for some commands

Post by ShaiHulud »

If you want to check statically whether a player is alive or not (I mean, rather than responding to an event), then I suppose checking the Health property (<= 0) should do the trick.

ModifyPlayer is called on respawn as well as initial spawn, so you should be able to catch that in the same way.

Removing the crosshair might be more challenging. It's not there as a spectator, or when a game is in the pre-start state. DrawCrosshair is a function in the ChallengeHUD class. It looks like it's not called when a weapon isn't present in the player inventory (that might be a strategy?). I had a quick go at triggering the first condition:

Code: Select all

if (Crosshair>=CrosshairCount) Return;
...by surreptitiously increasing the Crosshair count, but it didn't exit the function, so I'm doing something wrong. You can get a reference to the player HUD in PostRender. Here's a snippet from Rextended, but it doesn't necessarily get you any further until you have a plan for interrupting the call to DrawCrossHair (note the simulated keyword - required because it's manipulating screen drawing on the client end):

Code: Select all

// Makes sure we get registered (Thanks to the UnrealWiki)
simulated Function Tick(float delta)
{
  // Client side
  if (Level.NetMode != NM_DedicatedServer)
  {
    if (!bHUDMutator)
      RegisterHUDMutator();
  }
}

// Display the countdowns when needed
simulated function PostRender(canvas C)
{
  local PlayerPawn PP;
  local ChallengeHUD cHUD;
...
  PP = C.Viewport.Actor;
  cHUD = ChallengeHUD(C.Viewport.Actor.myHUD);
}
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Starting some scripting, looking for some commands

Post by sektor2111 »

Player is mainly dead in some condition of TakeDamage - "ActualDamage > Victim.Health" but might be better a ScoreKill - these are default functions called by themselves - even "PreventDeath" can be used at something...

For crosshair - let's say that dead player can see Scoreboard - I don't really recall crosshairs in state dead - Probably by only typing F1 for removing ScoreBoard in that state. These are mainly HUD specific things which are not my goals as long as it might be conflicting with other HUD mutators...

You want to set a message when player stay dead more time... it's probably nasty because dead player stays with Scoreboard On Screen and that's why even master-blaster "CTFAnnouncer" with message announcing a victory won't be seen because of... ScoreBoard so is pretty much useless. HUD has to be rewritten at this point. Usually I quickly press F1 for seeing what Announcer does else NONE message can be seen in that moment. I think is way easy usage of a sound rather than a masked useless message: "Warning, dead camper will be punished...". Sometimes player is not reading a message but a sound cannot be avoid to get into ears. As a matter of fact I'm not curious about a combination of ScoreBoard Data and a message dropped into Screen messing up all readable things from there - I don't think this is a good idea to screw scoreboard visibility.
User avatar
Barbie
Godlike
Posts: 2792
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Starting some scripting, looking for some commands

Post by Barbie »

Marscaleb wrote:how do I check if a player is dead?
Pawn's state 'Dying' has come to my mind here: Dead == Player.IsInState('Dying') should be worth to test if it is always true.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
Marscaleb
Average
Posts: 48
Joined: Tue Jun 07, 2016 6:50 am

Re: Starting some scripting, looking for some commands

Post by Marscaleb »

A dying state, huh? Isn't there a dead state, too? I remember there was one in UDK. (...why would you even need two such states?)
But unless I can catch some sort of call when the player dies, I'm still just checking a variable every tick, and I don't see any difference between checking player health and a dead state.
I guess its better than nothing though.
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Starting some scripting, looking for some commands

Post by sektor2111 »

Barbie wrote:Pawn's state 'Dying' has come to my mind here: Dead == Player.IsInState('Dying') should be worth to test if it is always true.
Excuse me but this is not that FAST and probably pretty much expensive than testing a BOOL - read well. In CountHunters which I'm using in some last MH done, I simply did an instant check for bHidden. For sure player dead is not visible (TournamentPlayer), LOL. A Bool check is faster than lightning. Else "PlayerPawn.Health < 1" for sure = DEAD like dead baboon. A string check is not a fast code and neither a huge array, you should avoid these if are not needed by following lazy's man way: shortest route. I will not mention that Waiting type states which are not Dying - dying is very short.
We have: state PlayerWaiting, state PlayerSpectating which are not in account here when player just does nothing.

And now a cheap observation sold:
When I did some tests in a Level having 6000+ creatures, I could deducted that even an ISA check and all sort of foreach might develop a nice crash reaching at iterations limit - heavy functions are contributors at this harmful load because of multiple tests/processing. From now on I will not iterate not needed things in Prebegins PostBegins because this is first way in a game crash in a heavy load case. Probably fixing movers is doable even if they were already initialized by sending them into the right state after a few time without the charge happening at Level load.
ShaiHulud
Adept
Posts: 459
Joined: Sat Dec 22, 2012 6:37 am

Re: Starting some scripting, looking for some commands

Post by ShaiHulud »

Perhaps the ScoreKill(, PreventDeath, or MutatorTakeDamage functions would be useful to investigate in that case.
Marscaleb wrote:But unless I can catch some sort of call when the player dies, I'm still just checking a variable every tick
Marscaleb
Average
Posts: 48
Joined: Tue Jun 07, 2016 6:50 am

Re: Starting some scripting, looking for some commands

Post by Marscaleb »

Ahhh, crap...

Well I got the mutator "finished" but when I went to test in on multiple computers connected together I found a problem. None of the messages display on any screens except for the host.

I set the system up to use "ReceiveLocalizedMessage" which displays text on the player's screen. I just keep sending the messages at a regular rate and it has the same effect as a message just displayed on the screen, but without all the work of trying to re-write the HUD.
But as I said, these messages are NOT being displayed on the screens of anyone except the host.

I don't see why this is happening. Looking at other mods that use this function, its use is pretty clear.
(Pawn).ReceiveLocalizedMessage(class 'MyMessageClass'); It's pretty simple, so that part isn't getting screwed up.
So the next thing I would check is that the "pawn" in question is actually the player on that system.
But this seems to be a given. The players actually turn into spectators, so all the code in each instance of the SSCheck actor is clearly directing to the correct pawn.

So... I don't get why this is happening.

EDIT: Attached the current source code, in case someone wants to take a look.
Attachments
Classes.zip
Source
(8.07 KiB) Downloaded 57 times
User avatar
Barbie
Godlike
Posts: 2792
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Starting some scripting, looking for some commands

Post by Barbie »

Marscaleb wrote:these messages are NOT being displayed on the screens of anyone except the host.
Sounds like the clients does not have the mutator. Did you add the mutator to ServerPackages?
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Starting some scripting, looking for some commands

Post by sektor2111 »

Class SScheck doesn't have RemoteRole and I'm not sure if this do helps.
Marscaleb
Average
Posts: 48
Joined: Tue Jun 07, 2016 6:50 am

Re: Starting some scripting, looking for some commands

Post by Marscaleb »

Barbie wrote:
Marscaleb wrote:these messages are NOT being displayed on the screens of anyone except the host.
Sounds like the clients does not have the mutator. Did you add the mutator to ServerPackages?
I wasn't even aware that was a thing, so no, no I didn't.

That being said, the original code Mr. Loathsome made works fine on the other machines. If I have to set up something special to work on servers, wouldn't the code be an all-or-nothing deal?
Also I copied the mutator to most of the machines in this network anyway.
sektor2111 wrote:Class SScheck doesn't have RemoteRole and I'm not sure if this do helps.
I don't know what that is.

Okay, well at least I have some stuff to start researching. Maybe I can figure this out when I get home tonight.
User avatar
Barbie
Godlike
Posts: 2792
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Starting some scripting, looking for some commands

Post by Barbie »

If a job has only to be done on the server, the clients don't need that code. But you said you used 'MyMessageClass' - from where should the clients know what this is and how to display that?
Also I copied the mutator to most of the machines in this network anyway.
It is not enough if the file lies around somewhere in the file system - it has to be loaded. All files that are given in server's ServerPackages are loaded by the clients. So add this line in server's UnrealTournament.ini file in section [Engine.GameEngine]:

Code: Select all

ServerPackages=MyMutator.u
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
Marscaleb
Average
Posts: 48
Joined: Tue Jun 07, 2016 6:50 am

Re: Starting some scripting, looking for some commands

Post by Marscaleb »

Oh! Well hey, now its working -- almost.

So now the messages that are being displayed are the ones that are saved in the original defaults, which strictly speaking, should never be seen.
I made the properties of the messages be obtained from the mod's ini file so other folks can customize the messages to their liking.

The relevant code:

Code: Select all

class SpecStart extends Mutator config(SpecStart);

...
var() config string HeaderText, BannerText, NotReadyText, ReadyText, inGameText;

function PostBeginPlay()
{
    local bool bWasText;
    
	Super.PostBeginPlay();
	...
    if (HeaderText != "")
    {
        class'MessageHeader'.default.daString = HeaderText;
        class'SSCheck'.default.bHeaderMess = true;
        bWasText = true;
    }
    else
    {
        class'SSCheck'.default.bHeaderMess = false;
    }
    ...
}
(The bools are used to bypass the message functions entirely if they are blank.)

And the message itself:

Code: Select all

class MessageHeader expands LocalMessagePlus;

var(Messages)	localized string	daString, BlankString;

static function float GetOffset(int Switch, float YL, float ClipY )
{
	return (Default.YPos/768.0) * ClipY - 2*YL;
}


static function string GetString(
	optional int Switch,
	optional PlayerReplicationInfo RelatedPRI_1, 
	optional PlayerReplicationInfo RelatedPRI_2,
	optional Object OptionalObject 
	)
{
    if (switch == -1)
        return Default.BlankString;
	return Default.daString;

}



defaultproperties
{
    daString="Feed me a cat!"
    BlankString=""
    Lifetime=2
    FontSize=1
    bIsSpecial=True
    bIsUnique=True
    bFadeMessage=False
    DrawColor=(R=20,G=155,B=255,A=200),
    YPos=190.00
    bCenter=True
}
(The blank string is used to clear the message instantly when the player spawns.)
The clients are displaying the messages in this code, not the messages specified in the ini files.

And the ini file has the desired strings in it, and they are even on the client's computers as well, and I even tried adding the ini file to the ServerPackages, but to no avail.

...I can at the very least compile a version just for me to use personally, but this makes it challenging to have a "public version" that anyone can use.

(BTW, is there some more straight-forward way to add the package to the ServerPackages without manually editing the ini file? It feels rather... unprofessional. If I were to distribute this mod, I would expect it to not require instructions telling people to modify their ini files to make it work.)
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Starting some scripting, looking for some commands

Post by sektor2111 »

I don't know if exist a problem at editing files because SOMETHING has to load mutator ANYWAY if it needs to work in that server, because mutators dropped in system aren't starting alone by only reading admin's mind :loool: .
So whatever you do, declaring mutator somewhere (run-line, mapvote) is a NEED not an option else it will never work. Aside, ini can be screwed VIA preferences menu if mutator has a proper INT file directly from game or a menu section accordingly, however rented servers are based the mostly on editing INI files - it's a common rule so I don't get what's wrong with this "unprofessional" term. NGZ servers which are pretty much professionally configured are using this way all time. A good work on Linux by example is based on a lot of commands which pro programmers are using - Editing files is part of I.T. I don't get the issue at this point. Only a 0 skill admin has problems at editing INI files.
Marscaleb
Average
Posts: 48
Joined: Tue Jun 07, 2016 6:50 am

Re: Starting some scripting, looking for some commands

Post by Marscaleb »

The best thought I have so far is that I could have SSCheck actually set the default values for the messages, but I would need a way to send those strings to the SSCheck class.

How can I obtain a reference to an instance of a class that I have spawned?
I keep thinking of how I do this in Unity, but it isn't working here.
Post Reply