Would you be willing to help a noob with Python?

Users who are viewing this thread

Lanister

Veteran
First off, I'd like to say thanks if you opened the topic and took the time to read it, as I feel like a complete idiot trying to figure out Python. The only programming experience I have is in C#, so looking at this type of scripting is completely foreign to me, and I lack any understanding of it. Now to the point...

I am planning to do a few minor adjustments to the coding to allow for the ability to enjoy the game somewhat as a bandit. In the past I have done extensive modding to the txt files without the help of tools, simply through trial and error, allowing me to completely alter troop trees, factions, items, and so on, but it's still not enough.

There are two things I am trying to do. First is I want to initiate a reputation check when encountering both bandit factions and manhunters in order to determine the dialog that will be presented, allowing for a more immersive roleplaying experience (bad reputation gets you attacked, good reputation allows for friendly discussion). In association with this change, I'd like to make it so friendly encounters could allow for recruitment of the group you've run into for a fair price.

Now typically a system like this for me would be like... an example.
Code:
	if(heroRelationship < 0)
	{
		Dialog;
			battleEvent = true;
		
		Dialog;
			removeGold = charGold * 0.25f;
	}
	else if(heroRelationship >= 0)
	{
		Dialog;
			addCharParty = PartyID;
			Destroy (gameObject);
		
		Dialog;
			exitMenu;
	}
Maybe not the best example, lol, but that's just a quick scribble.

But then I look at some of the scripting in the module system, I just end up all  :shock:. So I'm not looking for anyone to just hand me a script for what I want done, but if someone could perhaps take the time to explain the following to me...

Code:
  [party_tpl|pt_looters|auto_proceed,"start", [(eq,"$talk_context",tc_party_encounter),(encountered_party_is_attacker),], "{!}Warning: This line should never be displayed.", "looters_1",[
	(str_store_string, s11, "@It's your money or your life, {mate/girlie}. No sudden moves or we'll run you through."),
	(str_store_string, s12, "@Lucky for you, you caught me in a good mood. Give us all your coin and I might just let you live."),
	(str_store_string, s13, "@This a robbery, eh? I givin' you one chance to hand over everythin' you got, or me and my mates'll kill you. Understand?"),
	(store_random_in_range, ":random", 11, 14),
	(str_store_string_reg, s4, ":random"),
	(play_sound, "snd_encounter_looters")
  ]],
  [party_tpl|pt_looters,"looters_1", [], "{s4}", "looters_2",[]],
  [party_tpl|pt_looters|plyr,"looters_2", [[store_character_level,reg(1),"trp_player"],[lt,reg(1),4]], "I'm not afraid of you lot. Fight me if you dare!", "close_window",
   [[encounter_attack]]],
  [party_tpl|pt_looters|plyr,"looters_2", [[store_character_level,reg(1),"trp_player"],[ge,reg(1),4]], "You'll have nothing of mine but cold steel, scum.", "close_window",
   [[encounter_attack]]],

Just so I can get a better understanding of how calls are performed and what not. And if someone could also explain how I would perform a check on reputation with the faction it would be appreciated.

Thanks again for taking the time to read.

Edit:
I guess the major bits I'm lost on are...
[party_tpl|pt_looters,"looters_1", [], "{s4}", "looters_2",[]],
[party_tpl|pt_looters|plyr,"looters_2", [[store_character_level,reg(1),"trp_player"],[lt,reg(1),4]]
 
That looter code isn't really the greatest or most straight-forward example of dialogue. First, you'll need to understand that dialogs are evaluated on a top-down basis, with the first matching option being displayed or all valid options being displayed (in the order they appear) if it has the |plyr flag (spoken by the player). The other relevant flag is party_tpl, which will check when the encountered party on the world map has a certain party template (in this case, pt_looters). Here, the rarely used auto_proceed flag will cause the process to trickle down to the next dialog state, that is looters_1. However, before that occurs, a random quick string is stored in three string registers and then a random string register is picked and put in s4. Not how I would have done it (since you can actually randomize between strings if they are referenced in module_strings), but it works nonetheless.

The next dialog state, looters_1 has no condition and the pt_looters flag, which is a continuation of the above. If this dialog state is reached from another party template, it won't fire. Normally, however, you really don't care about explicitly restricting dialogs and the anyone flag is used for conversations after the first one has already been evaluated and directs the flow to looters_1. Here this just displays the random string from above, then branches out to looters_2, which allows the player to respond since all of the following dialogs have the plyr flag.

Here, you have two options: One where the player's level is stored in reg1, and checked if it's less than 4. The second does the same and checks if it's at or above 4, presenting a different string for the player to shout. The end result is the same - the operation (encounter_attack) redirects to the party encounter menu.

As for your question of storing relation, this is automatically done for you in a pre-processing dialog at the top. It takes advantage of the fact that the first dialog must be evaluated before any further ones can be checked. This sets up a bunch of variables that are very useful, and the one you want are probably $g_talk_troop_faction and $g_talk_troop_faction_relation, both of which should work for outlaws (fac_bandits) and manhunters (fac_manhunters). Note that since $g_talk_troop_faction is stored from the faction of $g_talk_troop_faction, your troop definition in module_troops must match that of the faction you want. Since manhunters can upgrade to slavers, and the slaver troop tree has a different faction, you'll want to modify those to match. Alternatively, if you have set up the party template factions properly, you can use $g_encountered_party_relation or $g_encountered_party_faction instead.

Check out the wiki for more info I guess
 
This is related to the original question, so instead of a new topic I'm posting here. :grin:

So my question:
How can I make a dialog that changes the faction of a party to the player faction?

Then, after that, (I understand that this will be slightly more complicated) how to make those parties occasionally spawn as parties of a different faction? For example: most mercenary parties would be fac_outlaws or fac_deserters, (haven't decided which to use yet) but occasionally spawn as fac_kingdom_1 (Swadia) or any other kingdom, so there would be other mercenaries besides the player.
 
Thank you Somebody, that helped make better sense of the script for me. I'll take some time to view and read the link you added in a bit, then dive into it and see what I can accomplish.

Edit: Just to be sure... This is the right understanding of these correct?

neq = not equal to
eq = equal to
lt = less then
le = equal or less then
gt = greater then
ge = equal or greater then
 
Lanister said:
Edit: Just to be sure... This is the right understanding of these correct?
Yes. Try not to confuse neq with neg, which is the operation negation flag and used to generate, lt, neq, and le.

cwr said:
This is related to the original question, so instead of a new topic I'm posting here. :grin:
It's trivial to make use of party_set_faction, which will answer both your problems. You should really be making your own entry in module_factions though and the other topic about mercenaries.
 
Lanister said:
First off, I'd like to say thanks if you opened the topic and took the time to read it, as I feel like a complete idiot trying to figure out Python. The only programming experience I have is in C#, so looking at this type of scripting is completely foreign to me, and I lack any understanding of it. Now to the point...
In case you didn't realise, the M&B module system is not actually Python: it's a custom scripting language that looks quite different, using Python just to compile the user edited .py files into masses of numbers for the game to read, in the .txt files. I recommend this guide as a good place to start for people with prior programming knowledge.

Your C# example converted into proper Python would look very similar, like this (though the Dialog lines and indentation after in your code seem a bit odd):
Code:
    if heroRelationship < 0:
        Dialog
        battleEvent = True
        
        Dialog
        removeGold = charGold * 0.25
        
    elif heroRelationship >= 0:
        Dialog
        addCharParty = PartyID
        
        Dialog
        exitMenu
 
Yah, I didn't realize it wasn't Python, I've never encountered Python, and just jumped to the assumption it was. Thank you for the clarification and the link, I'll be sure to check it out, currently reading through some of the module script and viewing stuff on the wiki posted by Somebody.

And sorry for the poor structure on the C# example, lol. I typically rely on auto complete functions and auto tabbing from visual studio, just sorta tossed that together in wordpad fast.
 
Somebody said:
It's trivial to make use of party_set_faction, which will answer both your problems. You should really be making your own entry in module_factions though and the other topic about mercenaries.

So for the player dialog I could just say "how would you like to join my faction" --> "Ok sure" --> party_set_faction "players_supporters"
Thanks! :grin:

How would that work for spawning as a different faction such as any of the kingdoms? Looking at the party templates it has the faction predetermined.


Sorry for the stupid questions- I'm a new modder. :sad: But I'm learning! :grin:
 
Back
Top Bottom