Majesty Gold HD

Majesty Gold HD

Customize Majesty!
Create and upload new Quests and Mods for Majesty HD!
LookMyName 10 Aug, 2022 @ 3:12pm
Why doesn't this code function work?
Function Recruitment_Mod ( agent thisagent )
Declare
list Palaces;
agent Palace, ThisAgent;
string Hero_Type;

Begin

begin

//Doesn't matter which palace does the spawning;
Palaces = $ListPalaces ();

Foreach Palace in Palaces do
begin

Hero_Type = $Random_Hero_Type ( Palace );

$SpawnUnit ( Palace, Hero_Type, $RandomEdgeCoord ( $randomnumber ( 4 )), $GetUnitPlayerNumber ( Palace ));

end
end


$SetThreadInterval ( $Random_Time ( 1800 ));

End

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

From what I understand this function should be spawning a random hero just like the Function Friendly_Heroes on Special_Events.gpl, I tried to copy this function on a new mod in many ways but still I can't make it work outside of the "special events: reinforcements" on the freestyle mode.
From what I understand the Friendly_Heroes function is called by the in-game code so if you change the name of the function it stop working on that mode.
Maybe the actual code for it is not on that gpl?
Last edited by LookMyName; 10 Aug, 2022 @ 3:19pm
< >
Showing 1-8 of 8 comments
VikesRule 40 10 Aug, 2022 @ 9:07pm 
For
$SetThreadInterval ( $Random_Time ( 1800 ));
you need to declare which thread (function) you are setting in the first argument. So it should look something like this:
$SetThreadInterval (myFunctionHere, $Random_Time ( 1800 ));
Last edited by VikesRule; 10 Aug, 2022 @ 9:09pm
LookMyName 10 Aug, 2022 @ 10:27pm 
Originally posted by VikesRule:
For
$SetThreadInterval ( $Random_Time ( 1800 ));
you need to declare which thread (function) you are setting in the first argument. So it should look something like this:
$SetThreadInterval (myFunctionHere, $Random_Time ( 1800 ));


It still didn't work I also tried with
$SetThreadInterval (ThisAgent's "EventScript", $Random_Time ( 180 ));

But, really, thanks man, I wasn't expecting help.
Enerril 16 11 Aug, 2022 @ 1:13am 
You also need to call that function in the first place.

If you want something to be called periodic you need place where you can store that function. It can be any unit or building or agent or prototype.

If it is a quest then you can store this function in AIRootAgent. Most quest variables and functions are stored there.

If it is a mod then... I recommend to start with the quest to learn a bit how it works.


Big map You can get easy reference how to setup periodic functions here. This is empty big map quest with periodic monsters spawning. Download it. Look it up in steam workshop folders and take a look at the map .gpl file.
LookMyName 12 Aug, 2022 @ 11:38am 
Originally posted by SpiralBeam:
You also need to call that function in the first place.

If you want something to be called periodic you need place where you can store that function. It can be any unit or building or agent or prototype.

If it is a quest then you can store this function in AIRootAgent. Most quest variables and functions are stored there.

If it is a mod then... I recommend to start with the quest to learn a bit how it works.


Big map You can get easy reference how to setup periodic functions here. This is empty big map quest with periodic monsters spawning. Download it. Look it up in steam workshop folders and take a look at the map .gpl file.


I just don't get it, there are some mods I've downloaded and even if I follow the exact same logic it still doesn't work.

What is wrong here exactly? Sorry if I sound whyny or frustrated.


Function recruitment2 ( agent ThisAgent )
Declare
list Palaces;
agent Palace, ThisAgent;
string Hero_Type;

Begin

Palace = $GetPalace (ThisAgent);

if ($isvalidgamepiece(palace))
begin

//Doesn't matter which palace does the spawning;
Palaces = $ListPalaces ();

Foreach Palace in Palaces do
begin

Hero_Type = $Random_Hero_Type ( Palace );

$SpawnUnit ( Palace, Hero_Type, $RandomEdgeCoord ( $randomnumber ( 4 )), $GetUnitPlayerNumber ( Palace ));

end
end


$SetThreadInterval ( $recruitment2, $Random_Time ( 180 ));

End
Last edited by LookMyName; 12 Aug, 2022 @ 11:39am
Enerril 16 12 Aug, 2022 @ 12:24pm 
Do you call this function from anywhere in your code?

The fact that it exists in your mod doesn't automatically executes it. I just want to establish what your level of coding is.

The first thing that would help you to understand is to download big map quest and look at its code. It is really easy to understand and modify. Then you can move on
Last edited by Enerril; 12 Aug, 2022 @ 12:25pm
LookMyName 12 Aug, 2022 @ 1:36pm 
Originally posted by SpiralBeam:
Do you call this function from anywhere in your code?

The fact that it exists in your mod doesn't automatically executes it. I just want to establish what your level of coding is.

The first thing that would help you to understand is to download big map quest and look at its code. It is really easy to understand and modify. Then you can move on

So that is what the problem is?

It's weird, since I've downloaded some mods for reference I've seem some of them creating new functions but nowhere else i've seen that function being called, I tought all it was needed was to just compile a gpl on the RGS the function and it would run by default.

So there is no way to do what I'm trying to do? (reinforcements mod for all quests).
My idea actually is to replace the recruitment of heroes with this function I'd later make it work like the embassy does. I've worked on how to disable the recruitment of heroes but keeping the guilds intact, it's a shame we can't edit the UI.

My level of coding is not so good, but I've done some big things on some other games like Darkest Dungeon, mostly by being stubborn.
Last edited by LookMyName; 12 Aug, 2022 @ 2:14pm
LookMyName 17 Aug, 2022 @ 11:23am 
Originally posted by SpiralBeam:
Do you call this function from anywhere in your code?

The fact that it exists in your mod doesn't automatically executes it. I just want to establish what your level of coding is.

The first thing that would help you to understand is to download big map quest and look at its code. It is really easy to understand and modify. Then you can move on


So I tried storing this code on the following function

///////////////////////////////////////////////////////////////////////////////
// This function is called before the first frame of the game
// it is needed to force the palace's upgrade button to be correct
// IT ALSO sets thisagent to title palace if it is an outpost

// This is run AFTER all the birthscripts for units have run

function Palace_Pre_Birth( agent thisagent )

Declare
list Palaces;
agent Palace;
string Hero_Type;

Begin

Palace = $GetPalace (ThisAgent);

if ($isvalidgamepiece(palace))
begin

//Doesn't matter which palace does the spawning;
Palaces = $ListPalaces ();

Foreach Palace in Palaces do
begin

Hero_Type = $Random_Hero_Type ( Palace );

$SpawnUnit ( Palace, Hero_Type, $RandomEdgeCoord ( $randomnumber ( 4 )), $GetUnitPlayerNumber ( Palace ));

end
end


$SetThreadInterval ( $Palace_Pre_Birth, $Random_Time ( 180 ));

End


////////////////////////////////////////////////////////////////////////////////

And it worked but it worked just once, wich means that the function doesn't loop, how can I make it loop? Should I search for another function wich does and insert this code there?

I'd rather learn how to make it loop, since this is one of he only functions that I found that there was no harm in replacing.
Last edited by LookMyName; 17 Aug, 2022 @ 11:28am
Enerril 16 17 Aug, 2022 @ 11:44am 
Replace your function with this. It is ugly but should work.

function Palace_Pre_Birth( agent thisagent )

Declare
list Palaces;
agent Palace, AIRootAgent;
string Hero_Type;

Begin

Palace = $GetPalace (ThisAgent);

if ($isvalidgamepiece(palace))
begin

//Doesn't matter which palace does the spawning;
Palaces = $ListPalaces ();

Foreach Palace in Palaces do
begin

Hero_Type = $Random_Hero_Type ( Palace );

$SpawnUnit ( Palace, Hero_Type, $RandomEdgeCoord ( $randomnumber ( 4 )), $GetUnitPlayerNumber ( Palace ));

end
end


AIRootAgent = $RetrieveAgent ("GplAIRoot");
AIRootAgent's "SpecialSpawnScript2" = $Palace_Pre_Birth;

$NewThread( AIRootAgent's "SpecialSpawnScript2", 5000,Palace );



End
< >
Showing 1-8 of 8 comments
Per page: 1530 50