MH: Monsters should not move before map starts

Discussions about Coding and Scripting

MH: Monsters should not move before map starts

Postby Aldebaran » Tue Mar 21, 2017 4:56 am

You all know perhaps, if a player spectates the monster hunt map in monster hunt 2 (gold) before the game starts the monsters in it begin to fight against the spectating player and they also move. So players can manipulate the map start in a unflattering way, also spectating isn't that easy (with spectator here I mean a player who is looking how the maps look like before game starts, not the "spectator").
I want to change this as some others have done this already in their mod version: monsters should stay still and should not fight before the game was started.

Can somebody help me how I can implement that or can provide some code for me, I will try then to adapt this from other MH version to MH2...
Aldebaran
Masterful
 
Posts: 657
Joined: Thu Jan 28, 2016 7:30 pm

Re: MH: Monsters should not move before map starts

Postby sektor2111 » Tue Mar 21, 2017 6:48 am

Is a little logic around. Currently all my Mods have monsters at map load... "sleeping". Nobody moves until game is being started - not even Skaarj will not spawn weaponry until Engine is being properly initialized. THIS was one of reasons triggering me to study UScript. Such a code exist in that MH2 source which I posted somewhere in forum, at this moment code is more mature a bit, I've quit using 2 or 3 iterations, grouping monsters in team and supporting up to 2000 creatures with no crash. There is no need for more redundant posting because problem was debated already, and even in XCGE thread. As long as there is no separate MH section, use Search Button and... patience. Like I said, you can join in places where MH is more loved and there we can enhance debates around this problem and how many things might go on the right way with a simple move.

Original MonsterHunt (see source-code) has a basic deal here - you can at least to fallback at original code as primary solution.
User avatar
sektor2111
Godlike
 
Posts: 3963
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: MH: Monsters should not move before map starts

Postby Barbie » Tue Mar 21, 2017 4:22 pm

That annoying monster hunting of bWaiting-Players before game start (and monster-against-monster also during game play) was one of the first things I changed in my derived version of MonsterHunt:
  1. in Monsterhunt.PostBeginPlay I call "SetAttitudeToPawns(SATP_SetIgnoreAndStore)"
  2. in Monsterhunt.Timer I call "SetAttitudeToPawns(SATP_SetIgnore)" if match has not been started
  3. in Monsterhunt.StartMatch I call "SetAttitudeToPawns(SATP_SetHateAndRestore)"

If the function "SetAttitudeToPawns()" is called with param "SATP_SetIgnoreAndStore", it records AttitudeToPlayer of all Pawns and sets them to ATTITUDE_Ignore. Furthermore it removes Pawn's enemy. If called with "SATP_SetHateAndRestore", it restores the old values.
function SetAttitudeToPawns
Code: Select all
function SetAttitudeToPawns(ESetAttitude WhatToDo) {
/******************************************************************************
Don't get confused with function *SetAttitudeToPawn()*
******************************************************************************/
local Pawn p;
local TPawnAttitudeToPlayer CurrentPawnAttitudeToPlayer;

   // log("DEBUG: SetAttitudeToPawns(" $ GetEnum(Enum'ESetAttitude', WhatToDo) $ ") called");
   if (bSetAttitudeToPawnsDisabled) {
      warn("call to SetAttitudeToPawns(" $ WhatToDo $ ") while bSetAttitudeToPawnsDisabled==True, aborting funtion");
      Return;
   }
   if (bSetAttitudeToPawnsLocked)
      warn("call to SetAttitudeToPawns(" $ WhatToDo $ ") while bSetAttitudeToPawnsLocked==True");
   bSetAttitudeToPawnsLocked = True;
   switch (WhatToDo) {

      case SATP_SetHateAndRestore: // this case should be executed once only on starting game
         //LogAttitudeToPlayer("Debug: Before doing revert:");
         // first step: set for all matching Actors the attribute *AttitudeToPlayer* to *ATTITUDE_Hate*
         foreach AllActors(class'Pawn', p)
            if (PawnIsCandidateForAttitudeToPlayer(p))
            {
               p.AttitudeToPlayer = ATTITUDE_Hate;
               if ((ParentBlob(p) != None || BiterFishSchool(p) != None))
               {
                  p.GotoState('stasis');
                  Logger(LOG_Debug, "SetAttitudeToPawns", "Sent" @ p @ "to state'" $ p.GetStateName() $ "'");

               }
            }
         // second step: restore original values for the ones that had a different value:
         if (PawnAttitudeToPlayer != None)
         {
            CurrentPawnAttitudeToPlayer = PawnAttitudeToPlayer; // not really necessary, because the list should not be used anymore after restoring
            do
            {
               CurrentPawnAttitudeToPlayer.SetAttitudeToPawn();
               CurrentPawnAttitudeToPlayer = TPawnAttitudeToPlayer(CurrentPawnAttitudeToPlayer.GetNext(true));
            } until (CurrentPawnAttitudeToPlayer == PawnAttitudeToPlayer)

         }
         //LogAttitudeToPlayer("Debug: After doing revert:");
         bSetAttitudeToPawnsDisabled = True;
         break;

      case SATP_SetIgnoreAndStore:
      case SATP_SetIgnore:
         // LogAttitudeToPlayer("Debug: Before changing to ATTITUDE_Hate:");
         foreach AllActors(class'Pawn', p)
            if (PawnIsCandidateForAttitudeToPlayer(p))
            {
               if ((WhatToDo == SATP_SetIgnoreAndStore) && (p.AttitudeToPlayer != ATTITUDE_Hate))
               { // store all pawns different from ATTITUDE_Hate in list *PawnAttitudeToPlayer*
                  if (PawnAttitudeToPlayer == None)
                     PawnAttitudeToPlayer = TPawnAttitudeToPlayer(Class'TPawnAttitudeToPlayer'.static.CreateNew(self));

                  PawnAttitudeToPlayer = PawnAttitudeToPlayer.Add(self, p);
               }

               p.AttitudeToPlayer = ATTITUDE_Ignore;
               if (ScriptedPawn(p) != None)
               {
                  if (ScriptedPawn(p).Hated != None || ScriptedPawn(p).Enemy != None)
                  {
                     //Log("SetAttitudeToPawns DEBUG: Inspecting" @ p $ ", ScriptedPawn(p).Enemy=" $ ScriptedPawn(p).Enemy $ ", ScriptedPawn(p).State=" $ p.GetStateName());
                     //ScriptedPawn(p).Hated = None;
                     ScriptedPawn(p).Enemy = None;
                     ScriptedPawn(p).OldEnemy = None;
                     ScriptedPawn(p).WhatToDoNext('','');
                  }
               }
               else if ((ParentBlob(p) != None || BiterFishSchool(p) != None) && p.GetStateName() != p.Class.name)
               {
                  Logger(LOG_Debug, "SetAttitudeToPawns", "Sending" @ p @ "from state '" $ p.GetStateName() $ "' to state ''");
                  p.GotoState('');
               }
            }
         // LogAttitudeToPlayer("Debug: After changing to ATTITUDE_Hate:");
         break;

      default:
         Warn("unknown ESetAttitude=" $ WhatToDo);
         break;
   }
   bSetAttitudeToPawnsLocked = false;
}
PS: Yes, I know that there is a linked Pawn list...
<EDIT>
PPS: TPawnAttitudeToPlayer is a child of a custom double linked list.
</EDIT>
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
Barbie
Godlike
 
Posts: 1654
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: MH: Monsters should not move before map starts

Postby Aldebaran » Tue Mar 21, 2017 6:40 pm

Thank you both for your help. Because sektor2111 has answered earlier I have implemented now his method he used in his monster hunt version.
In function PostBeginPlay he set AttitudeToPlayer = ATTITUDE_Ignore to almost all scripted pawns, in function StartMatch he set AttitudeToPlayer = ATTITUDE_Frenzy to almost all scripted pawns regardingless what values were stored there first.
After first test it seems to work well.
I don't know if scripted pawns can have important other ATTITUDE values which get lost with that method, so perhaps Barbies version is more professional in this case. If I see issues with sektors2111's method I will try Barbies one :)

Another thing comes up...
When looking into sektor2111's monster hunt code I found some garbage collection in function SetEndCams:
Code: Select all
local CreatureCarcass C;
foreach AllActors (class 'CreatureCarcass', C)
{
    if (C != None && (!C.bStatic && !C.bNoDelete))
        C.GoToState('Corroding','');
}

Isn't this the same as this code that is already implemented in MH2Gold:
Code: Select all
foreach AllActors(class'Carcass', C)
    C.Destroy();


I ask these questions because I have still problems with some maps using too many channels producing lag situations.
Perhaps some better garbage collection in my case will help by destroying almost all actors before new map is loading.
Last edited by Aldebaran on Sun Mar 26, 2017 4:17 am, edited 1 time in total.
Aldebaran
Masterful
 
Posts: 657
Joined: Thu Jan 28, 2016 7:30 pm

Re: MH: Monsters should not move before map starts

Postby Higor » Tue Mar 21, 2017 6:49 pm

Lol, just set spectator's and waiting player's health to 0 fam.
Otherwise you lose non-hate behaviours on hostile monsters.
Higor
Godlike
 
Posts: 1731
Joined: Sun Mar 04, 2012 6:47 pm

Re: MH: Monsters should not move before map starts

Postby sektor2111 » Tue Mar 21, 2017 6:57 pm

Te he... so much processing.
A more simple solution.
Using SetPawnDifficulty properly called from some CheckReplacement/IsRelevant and removing stupid shadow from servers you are setting AttitudeToPlayer FRENZY (really mad) discarding code from PostBeginPlay. Else if we have a Level.bStartUp InitialState ='GameEnded'. I assure you that NO PAWN will move regarding to attitude taken and no damage will occur in this stage. Take in account some Factory which might start if game is not running yet - I must check this because I have some solutions. You can use another bool value as default bGameEnded one for figuring when game is being started. If game is started by anyone... start iterating hidden monsters - unhide them, setup normal collision and send them in state StartUp-Begin - No longer needed previous iterators loading cycles and getting closer to a crash. If game uses more fixes in PostBeginPlay, too many craps will crash server in high loaded maps. Also StartMatch will be laggy if iterators are used there.

Actually 6k map doesn't crash regarding to mover tweaks - I've reduced iterations by doing another code optimization...

Edit:
I've added some codes because in some maps rebel Factories were still spawning Monsters post Game Ended having the same stupid effects (attacking ghost player) and looking retarded.
Edit2:
Perhaps I have to wake them up more smoother...
Last edited by sektor2111 on Tue Mar 21, 2017 7:17 pm, edited 1 time in total.
User avatar
sektor2111
Godlike
 
Posts: 3963
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: MH: Monsters should not move before map starts

Postby Aldebaran » Tue Mar 21, 2017 7:12 pm

I want to mention that in the MH2Gold code already a similar code exists in function PostBeginPlay:

Code: Select all
foreach AllActors(class'ScriptedPawn', S)
{
    if ( !S.IsA('Nali') && !S.IsA('Cow') && !S.IsA('NaliRabbit') )
        S.AttitudeToPlayer=ATTITUDE_Hate;
    [...]
}

Many servers run with this code and maps manipulated in this way, even if the monster behavior is manipulated it is not particularly noticeable to me.

Thank you sektor2111 for your thoughts, but I am still beginner. Perhaps somebody else is able to form this into code.
Last edited by Aldebaran on Sun Mar 26, 2017 4:19 am, edited 1 time in total.
Aldebaran
Masterful
 
Posts: 657
Joined: Thu Jan 28, 2016 7:30 pm

Re: MH: Monsters should not move before map starts

Postby sektor2111 » Tue Mar 21, 2017 7:55 pm

Doesn't matter beginner or advanced - answer is: Do it simple.

In original MH, Shrimp was annoyed by mad monsters attacking spectator player. Until to have game started he set AttitudeToPlayer IGNORE. Whatever fixes coming later removed the second iterator from start (Setting back the Hate - it lags after all ) using a single way - HATING in PostBeginPlay - TOO EARLY. Then, all stupid monsters are attacking player spectator before to have a game started - for me this was not fascinating, I could see this right in first game tested with MH2 types - by chance I tested BoomBoomBridge - immediately Tentacles were attacking me with no game start - I got mad in that time about this change.

By getting your hand in controller you have many ways in setting up things - no worries my tweaks and hints were concluded after some years of pushing A.I. using more or less cute methods...

I'm thinking at a bTestSession using Null monsters and awaking them on demand when some primary test is being done using a mutate thing or such, hm.... .

I'll finish some primary stage of controller which I'm doing, any you'll see codes - and then, because you were speaking about High Loads, probably this thing will work fine in a strong machine and using 2000-2500 monsters in Level (not all of them in a room of course). Your changes are welcomed for whatever compatibility if it needs.
User avatar
sektor2111
Godlike
 
Posts: 3963
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: MH: Monsters should not move before map starts

Postby Higor » Tue Mar 21, 2017 8:13 pm

If I want a friendly Krall or whathever I wouldn't like to have to rewrite all into a non-scriptedpawn class.

Again, monsters don't attack 'dead' players lol.
Higor
Godlike
 
Posts: 1731
Joined: Sun Mar 04, 2012 6:47 pm

Re: MH: Monsters should not move before map starts

Postby papercoffee » Tue Mar 21, 2017 8:42 pm

Higor wrote:If I want a friendly Krall or whathever I wouldn't like to have to rewrite all into a non-scriptedpawn class.

Again, monsters don't attack 'dead' players lol.

:loool: This should be in Tips, Tricks & Tutorials section.
User avatar
papercoffee
Site Staff
 
Posts: 9151
Joined: Wed Jul 15, 2009 11:36 am
Location: Cologne, the city with the big cathedral.
Personal rank: coffee addicted !!!

Re: MH: Monsters should not move before map starts

Postby sektor2111 » Tue Mar 21, 2017 8:45 pm

And Monsters are NOT iterating NOTHING in state GameEnded not to mention dropping NON bugged weapons :satan: . If game doesn't start ever, nothing is being processed (HomeBase, Team, Weapon).
No need to mention how smoother is the start compared with my older works.
User avatar
sektor2111
Godlike
 
Posts: 3963
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: MH: Monsters should not move before map starts

Postby Aldebaran » Tue Mar 21, 2017 10:07 pm

I played some MH maps now with my "AttitudeToPlayer = ATTITUDE_Ignore" modification and most works well with it.
But in MH-Face the kralls are attacking me without starting the game. Perhaps it has to do with the map itself?
However I will test more maps...
Aldebaran
Masterful
 
Posts: 657
Joined: Thu Jan 28, 2016 7:30 pm

Re: MH: Monsters should not move before map starts

Postby Barbie » Tue Mar 21, 2017 10:43 pm

Aldebaran wrote:But in MH-Face the kralls are attacking me without starting the game. Perhaps it has to do with the map itself?
This is because the Kralls are spawned by CreatureFactory after you have applied the changes to AttitudeToPlayer of existing ScriptedPawns.
Higor wrote:Lol, just set spectator's and waiting player's health to 0 fam.
That does not solve the Monster-fight-against-Monster-problem...
Aldebaran wrote:(Removing carcasses...) I ask these questions because I have still problems with some maps using too many channels producing lag situations.
The data of a carcass is transferred only once at game start; after that its state (in resulting transferring data again) changes only, if it is destroyed?
I just do the opposite with the life time of carcasses: :lol:
Spoiler: show
Code: Select all
function int FixDecoCarcassesLifeSpan(ELogType LogLevel) {
/*******************************************************************************
Sets Lifespan to 0 for all class'Carcass'
*******************************************************************************/
local Carcass c;
local int result;

   foreach AllActors(class 'Carcass', c)
      if (c.LifeSpan != 0)
      {
         c.LifeSpan = 0;
         Logger(LOG_Verbose, "FixDecoCarcassesLifeSpan", "changed LifeSpan to 0 (eternally) for" @ c);
         result++;
      }
   return result;
}
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
Barbie
Godlike
 
Posts: 1654
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: MH: Monsters should not move before map starts

Postby sektor2111 » Tue Mar 21, 2017 11:10 pm

Right a few minutes ago I was checking that MH-Facing_Worlds ("original" conversion) with those stupid triggers, I did not see issues with new codes toward that "IsOnTeam" bullshit and neither CTFFlag being still in map.
Here is another logic. PostBeginPlay making monsters cool takes a blink, after PostBeginPlay Factories are ignited by Monsters themselves and New Spawned creatures are just Hating player by default regarding to game started or not, for such a case default MH code will not help.

In a new tech, Monsters spawned have been blocked and... restarted after game start - this new way looks good.

What I have to check - Not sure if I do really need that - testing with Nexgen. Last time some of these monster tweaks were badly bugged by Nexgen which for some no reason probably is trying to control other pawns than players :loool: , it was about exactly this way of making "Tournament Monster". I moved an iterator from BaseMutator back into controller because of Nexgen deals - now I'm no longer using those foreach types. Someday I'll do a little check around removing dumb codes or replacing functions with XCGE if I'll be in a sudden love with Nexgen... At least NexgenMH doesn't have too many MH related things added...
By testing a short session I did not see major issue - only Nexgen HUD is still mooing in console - so to speak Nexgen is Not a My Server tool.

Carcasses, well... How many do you want ? 2000 4000 ? Exist a limit in a zone called MaxCarcasses. A carcass is checking this limit and it goes to destruction by itself if is beyond boundaries - not to mention Win servers 451 how nice are at chapter Carcass without XCGE :lol2: .
I'm not sure if those carcasses are guilty for eating channels that much and not other "toys" used blabbering around. Engine is old, resources should be wisely used which is not the case for super duper maps full of overpowered stuff gibing chunks from creatures in noob style, or mods spamming actors. By Playing maps with thousands of actors and using UT stock stuff, things are not that bad, so it's up on you how much damage gets server loaded with spam stuff attached.
User avatar
sektor2111
Godlike
 
Posts: 3963
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: MH: Monsters should not move before map starts

Postby Aldebaran » Tue Mar 21, 2017 11:24 pm

On a different modified server I saw that ignoring players by creaturefactory monsters in MH-Face works.
Last edited by Aldebaran on Sun Mar 26, 2017 4:23 am, edited 1 time in total.
Aldebaran
Masterful
 
Posts: 657
Joined: Thu Jan 28, 2016 7:30 pm

Next

Return to Coding, Scripting

Who is online

Users browsing this forum: No registered users and 3 guests