Majesty Gold HD

Majesty Gold HD

Customize Majesty!
Create and upload new Quests and Mods for Majesty HD!
How would I add more than 1 extra guard to a guardhouse?
Say, I wanted to program up to six guards at a single guardhouse, a guardhouse level 3, each containing: 1 Elite City Guard, 2 Veteran City Guards, and 3 City Guards. I know that there is a set of code called "City_Guard_Spawner", and "City_Guard_birth", but when I tried to modify it, it would either: Spit out the first and only one city guard OR Change the city guard out for a veteran or elite guard. I cannot get it to have the six guards. I also can't seem to get the gpl to recognize that the Elite City Guard has a home. When spawning the elite city guard, it will return with an error that states "List members tried to access a agent beyond the list value.", where the list is "Waiting_Guardhouses", and it lists all guardhouses. It works fine when using only 1 unit at a time, but not 2 or more.
< >
Showing 1-7 of 7 comments
VikesRule 40 7 Apr, 2020 @ 8:55pm 
Have you increased the max_guards attribute for the guardhouse to 6?
Dracoceros 11 8 Apr, 2020 @ 6:48am 
Originally posted by VikesRule:
Have you increased the max_guards attribute for the guardhouse to 6?

Yes I have. I'll show you by posting a mod snippet for you to look at.
Dracoceros 11 8 Apr, 2020 @ 7:13am 
Originally posted by VikesRule:
Have you increased the max_guards attribute for the guardhouse to 6?

https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=2053035922

Here's the mod in question.
VikesRule 40 8 Apr, 2020 @ 11:41am 
Ok, I'll take a look and let you know if I see anything.
Dracoceros 11 8 Apr, 2020 @ 12:59pm 
Originally posted by VikesRule:
Ok, I'll take a look and let you know if I see anything.
Thank you so much! I'm also looking into it as well, so two minds and eyes are better than one!
VikesRule 40 8 Apr, 2020 @ 4:36pm 
Ok, so I have been messing around with this and I kinda got it working, though I had to edit some extra functions.

https://i.imgur.com/rbT0sOR.png

Here's the functions I changed from original files/what your files were:
  • City_Guard_Birth
  • RestartGuardSpawnThread
  • Guard_Find_Target

City_Guard_Birth: I took out the if (parent == palace) check that you had.
New version:
Function City_Guard_Birth (agent ThisAgent) Declare list GuardHouses; agent Home; agent Palace; Begin Palace = $GetTruePalace (ThisAgent); ThisAgent's "Target" = $NullAgent (); ThisAgent's "Home" = $ListMember (Palace's "Waiting_Guardhouses", 1); $RemoveListMember (Palace's "Waiting_Guardhouses", 1); Home = ThisAgent's "Home"; If ($IsDead (Home) == False) begin if ( ThisAgent's "title" == "City_Guard") begin Home's "Guards" << ThisAgent; (home's "num_guards") ++; (home's "num_city_guards") ++; end else if (Thisagent's "title" == "Veteran_City_Guard") begin Home's "Guards" << ThisAgent; (home's "num_guards") ++; (home's "num_veteran_guards") ++; end else if (Thisagent's "title" == "Elite_City_Guard") begin Home's "Guards" << ThisAgent; (home's "num_guards") ++; (home's "num_elite_guards") ++; end $RestartGuardSpawnThread(Home, #Guard_Spawn_Time); end $NewThread (ThisAgent's "ActiveScript", #Henchmen_Cycle, ThisAgent); End

Next, on RestartGuardSpawnThread function from original SDK files, I removed an "IsRunning" check that seemed to hold up the spawning from triggering.

New version:
function RestartGuardSpawnThread(agent thisAgent, integer delay) Declare integer numGuards; begin numGuards = thisAgent's "num_guards"; if (numGuards < thisAgent's "max_guards") begin $RunThread (thisAgent's "Guard_Spawn_Function", delay, thisAgent); end end

Next, on Guard_Find_Target function, I commented out the trigger that would swap out city guards for veteran guards.

New version:
Function Guard_Find_Target (agent ThisAgent) Declare list Targets; agent Home; agent Palace; agent Building; list Under_Const; boolean flag; // guard finds a target Begin Home = ThisAgent's "Home"; if ($isvalidgamepiece(home) == FALSE) begin thisagent's "activescript" = $guard_goto_palace; thisagent's "backScript" = $guard_goto_palace; ThisAgent's "Target" = $NullAgent (); return; end // Home's "Waiting_Guards" -= ThisAgent; // first look for enemies Targets = $list_enemies_seen(home,$getattribute (Home, #ATTRIB_SightRange)); If ($ListSize (Targets) > 0) begin // targets! pick closest, then set script to attack $DebugOut ("Guard has targets...picking closest!"); ThisAgent's "Target" = $ListMember (Targets, 1); //ThisAgent's "Target" = $Pick_Closest (ThisAgent, Targets); $say(thisagent,"VFX_GO_COMBAT"); ThisAgent's "ActiveScript" = $Guard_Attack_Object; // Home's "Waiting_Guards" -= ThisAgent; // $debugout("Guard has targets."); end Else begin //See if there are any buildings under construction that need to be patrolled. Under_Const = Home's "Under_Const_In_Sight"; If ($ListSize (Under_Const) > 0) begin Foreach Building in Home's "Under_Const_In_Sight" do begin if ($isdead(building) == FALSE) $Move (ThisAgent, $LocationOf (Building), "Add_Waypoint"); end //Have the agent put their home on the list, so that they patrol it as well //NOTE that it is also their destination $Move (ThisAgent, $LocationOf (Home), "Add_Waypoint"); //ThisAgent's destination should be his home, so thay they include it on their patrol route ThisAgent's "Destination" = $LocationOf (Home); ThisAgent's "Target" = ThisAgent; ThisAgent's "ActiveScript" = $Voyaging_Guard_Travel_To; ThisAgent's "BackScript" = $Guard_Find_Target; end Else //If home is a Guardhouse, then see if it wants ThisAgent to wander If (Home's "Title" == "Guardhouse" && Home's "TaskName" == "Wander") begin ThisAgent's "ActiveScript" = $Guard_Wander; //Init ThisAgent's counter to 0, so they wander the right number of times ThisAgent's "Counter" = 0; end Else // no targets, guard must go home begin flag = false; // do I need to be exchanged for a veteran guard? // if (thisagent's "title" == "City_Guard") // If ($GetAttribute (Home, #ATTRIB_ResearchGoodGuard) != 0) // begin // // switch me for a new guard // thisagent's "activescript" = $guard_goto_palace; // thisagent's "backScript" = $guard_goto_palace; // ThisAgent's "Target" = $NullAgent (); // Thisagent's "home" = $NullAgent(); // // if ($agentinlist(thisagent,home's "guards")) // begin // Home's "Guards" -= ThisAgent; // (Home's "num_guards") --; // end // // If ($AgentInList (ThisAgent, Home's "Waiting_Guards")) // Home's "Waiting_Guards" -= ThisAgent; // // Home's "Guard_Function" = $Building_Guard; // // $runthread(home's "Guard_Spawn_Function",1,home); // flag = TRUE; // end if (flag == FALSE) begin Home's "Waiting_Guards" << ThisAgent; Home's "Guard_Function" = $Building_Guard; $DebugOut ("Setting newthread (scanning) on Guardhouse because there aren't any targets."); ThisAgent's "ActiveScript" = $Guard_Return_Home; $debugout("Guard has no targets!"); $DebugOut (ThisAgent,"is returning home."); end end end //Reset home's taskname so that Guard doesn't keep wandering Home's "TaskName" = ""; End

Doing this I was able to get the max amount of guards to spawn for each building. However, it was kinda buggy as they tended to get piled up at the entrance and hop in/out of the guardhouse, only a few were out patrolling, so I suspect there is some other wandering/patrol logic to update.

I also did have a few times where Elite_City_Guards would spawn in and just sit at the palace like you had observed, but other times they would work just like the other guards. So I was getting that error that you had noted in your City_Guard_Birth function occasionally.
Last edited by VikesRule; 8 Apr, 2020 @ 4:42pm
Dracoceros 11 8 Apr, 2020 @ 5:47pm 
I just located the swap guard, but had no idea about the isrunning function. This is very helpful, perhaps I can find the wandering patrol logic based on what you've given me. Thanks for taking time out of your hand for this

It's also interesting to know that with you, the elite city guard would just spawn and sit. I guess it's probably also located in the wandering/patrol logic.
< >
Showing 1-7 of 7 comments
Per page: 1530 50