Modding Q&A [For Quick Questions and Answers]

Users who are viewing this thread

Status
Not open for further replies.
kalarhan said:
builder of the gods said:
Kalarkhan as you seem to now your stuff i am trying to add a ratio to my presentation for my mod For Rome

you can either work with operations that handle fixed point, or simple multiply everything for 100 before hand

x1=20
x2=40
res=50%

20/40 = 0 (as 0.5 doesn't compute)
(20*100) / (40) = 50 %

remember the % symbol already represents the /100


you should check for zero before the division, otherwise you will see the red text exploding on your screen if you ever change the balance

anything/0 = error


Code:
(lt, ":addorsub", 50),
you don't need this test



builder of the gods said:
And why aren't you making a mod yourself

Maybe I did... several mods...  :shifty:



builder of the gods said:
Why does the module system is harder than c# or something  :facepalm:

Handling float calculation is something you need to learn in any language, even MBScript. Just google for it and check the discussions, like in
http://stackoverflow.com/questions/20788793/c-how-to-calculate-a-percentageperthousands-without-floating-point-precision
or check wikipedia  :mrgreen:

but if you want to learn about this you should actually search for a math book (Knuth is a great reference)

Fixed it: for other people struggling  :mrgreen: (needs WSE)
Calculates friendly and enemy troops, adds a small number to hostile because you dont now exact numbers.
Then makes a two decimal ratio of it
adding 150 troops for siege, is for My siege system, in my mod For Rome
(link to siege system: http://www.moddb.com/mods/for-rome/features/sieges-you-wont-believe-your-eyes)
Code:
          (store_party_size_wo_prisoners, ":party_size", "p_main_party"),
          (assign, reg5, ":party_size"),

          (store_party_size_wo_prisoners, ":party_size2", "$g_encountered_party"), #get troops in city
          (val_add, ":party_size2", 150), #extra in the battle that are citizens fighting
          (store_random_in_range, ":missinfo", 0,100), #the info is 0 to 100 changing with the real info
          (store_random_in_range, ":addorsub", 0,100), #this determines whether the chance is added or substracted
          (try_begin),
               (ge, ":addorsub", 50),
               (val_add, ":party_size2", ":missinfo"),
          (else_try),
               (lt, ":addorsub", 50),
               (val_sub, ":party_size2", ":missinfo"),
          (try_end),
          (assign, reg6, ":party_size2"), 



	  (assign, ":ratio1", ":party_size"), #store friendlies to ratio
	  (val_div, ":ratio1", ":party_size2"), #divide friendlies with enemies giving a ratio number
	  
	  (val_mul, ":ratio1", 100), #0,5 gives 50% 5 gives 500% so this makes it procentual (V1)
	  (assign, reg7, ":ratio1"), #stored to reg to be able to put it in the string
	  (str_store_string, s1, "@{reg7}"), #procentual put in string 
	  
	  #following requires WSE
	  (str_length, ":s1length", s1), #we store the length of the string
	  (str_store_string, s2, "@empty"),
          (str_store_string, s3, "@empty"),
	  (try_begin),
	    (eq, ":s1length", 4), #as we divide by 100 it has two decimals: 3,21 or 9,47
		(str_store_substring, s2, s1, 0, 2), #stores first number
		(str_to_num, ":num1", s2), #make first letter an number
		(assign, reg10, ":num1"), #store first letter number to reg10
		(str_store_substring, s3, s1, 2, 4), #stores digits
		(str_to_num, ":num2", s3), #make first letter an number
		(assign, reg11, ":num2"), #store first letter number to reg10
		(str_store_string, s2, "@{reg10}.{reg11}"),
	  (else_try),
		(eq, ":s1length", 3), #as we divide by 100 it has two decimals: 3,21 or 9,47
		(str_store_substring, s2, s1, 0, 1), #stores first number
		(str_to_num, ":num1", s2), #make first letter an number
		(assign, reg10, ":num1"), #store first letter number to reg10
		(str_store_substring, s3, s1, 1, 3), #stores digits
		(str_to_num, ":num2", s3), #make first letter an number
		(assign, reg11, ":num2"), #store first letter number to reg10
		(str_store_string, s2, "@{reg10}.{reg11}"),
	  (else_try)
	        (eq, ":s1length", 2),
		(str_to_num, ":num3", s1), #make first letter an number
		(assign, reg12, ":num3"), #store first letter number to reg10
		(str_store_string, s2, "@0.{reg12}"),
	  (else_try),
	    (eq, ":s1length", 1),
		(str_to_num, ":num4", s1), #make first letter an number
		(assign, reg13, ":num4"), #store first letter number to reg10
		(str_store_string, s2, "@0.0{reg13}"),
	  (try_end),
 
bob123 said:
WFAS: Giving vassals fortress fiefs also gives them the village with it. Unlike towns which have their villages broken up.

How can i fix it for fortresses?

Start from what you know and follow the code from there.

Example: use the menu text (something similar to "give fief to lord") you see in the game to locate the code inside module_game_menus.py. Then check the menu option and what process is used (like calling a script similar to "give_center_to_lord". Then open that script(s) and study the code for towns, villages and castles. Finally include your changes for your new ruleset

Remember to verify what happens when the AI gives centers to vassals, or you could end up with empty villages.
 
kalarhan said:
bob123 said:
WFAS: Giving vassals fortress fiefs also gives them the village with it. Unlike towns which have their villages broken up.

How can i fix it for fortresses?

Start from what you know and follow the code from there.

Example: use the menu text (something similar to "give fief to lord") you see in the game to locate the code inside module_game_menus.py. Then check the menu option and what process is used (like calling a script similar to "give_center_to_lord". Then open that script(s) and study the code for towns, villages and castles. Finally include your changes for your new ruleset

Remember to verify what happens when the AI gives centers to vassals, or you could end up with empty villages.
Thanks for the tips. I found the cause in Module_scripts

Code:
	(try_begin),
        (party_slot_eq, ":center_no", slot_party_type, spt_castle),
        (try_for_range, ":cur_village", villages_begin, villages_end),
			(party_slot_eq, ":cur_village", slot_village_bound_center, ":center_no"),
			(call_script, "script_give_center_to_lord", ":cur_village", ":lord_troop_id", 0),
        (try_end),
    (try_end),

After hash-tagging, it seems to work fine, i verified AI lords too.

 
kalarhan said:
Madijeis said:
I destroyed my spacebar, but it still gives me the same error. I think I might just reinstall it.

you are still having indentation errors. Its simple, each scope belongs to a new block.

Madijeis said:
    print uid
    # Handle injections
    if type(entity) == tuple: entity = list(entity) # To guarantee we can make insertions

why are those lines, inside the same scope, using different indentation?

you can refer to the documentation (linked earlier) or some Python 101 guide if you need more examples. Or just forget about Python if that is too complicated for now, and focus on modsys.
After doing a course for python (3.0 but it said many things didn't change) I still can't comprehend that, especially since I only pressed spacebar 4 times to make the indentation on each line except the starting one. The course also didn't mention other types of indentation other than the 4 spaces suggested by PEP
 
Madijeis said:
After doing a course for python (3.0 but it said many things didn't change) I still can't comprehend that, especially since I only pressed spacebar 4 times to make the indentation on each line except the starting one. The course also didn't mention other types of indentation other than the 4 spaces suggested by PEP

okie, Python 101 lesson:

1) there is no rule on the ammount of spaces/tabs you use for indentation. There are conventions. Usually 4 spaces or 1 tab.
2) each scope must use the same indentation
3) a new scope must have a higher indentation
4) when you close a scope, you must use the indentation of the one before it
5) smart devs use a automatic tool (IDE, cool editor) that handle indentation automagically. Counting spaces is for kids.
6) you start your file from left margin (no spaces)

For a easier example lets replace spaces with dots. Good IDEs/text editors also have that option (only a visual thingy)

scope 0
...scope 1
...scope 1
......scope 2
............scope 3
............scope 3
......scope 2
......scope 2
...scope 1

and that is it.

oh in case you didn't understand what a scope is. The "if" statement belong to the current scope. If you will handle a special case for that if, that will be inside a new higher scope

scope 0
...scope 1
...if sometest
......scope 2
...scope 1
 
Well i have been struggling with one particular problem for a long time, i want prop_instance_animate_to_position to stop when coming accros a wal so i need a collisision system i could simply do this by getting the coordinates of the walls and saying that when coordinates are further then that with y height between a and b but this will make it a lot of work to implent for each wall and will make it extremely difficult and slow to create. So i saw a pic in the dead mod cwe and i fought anybody knows how this works?
dZdDa.png


or any other collision system to let a animating scene prop stop when hitting a prop
 
Assuming I know the ID of the city, village or castle what would be the code to figure out its owner? I am assuming it's (party_get_slot, ":my variable", ":center_no", something), But what?
 
Basically I am altering the recruitment system to have the player faction recruit custom troops. However, and this is important, I am working based off an existing mod that has culture based recruitment disabled. Instead every fief has a fixed culture at the beginning of the game.

So I can't go the normal route of just changing the culture. Instead I have to rig up a code that basically says this:
IF "Player_Faction OWNS Fief" AND "lord BELONGS TO Player_Faction" THEN "my custom recruitment" ELSE "default stuff"
 
Do i need to rig player map icon if i make completly new or i just position and resize it as default
Is it possible to make camera shake (because i want somwthing like drunk in my mod you now and not shake like its earthaque rather slightly swing) and how difficult would it be (is it worth).
Do i rig armors i make?
Where is viking conquest thread in which they tell what can i or i can't do?
How much verticles in model can cause game to crash (if only one is used).I would ask for polys but i have no idea whats that so i refer to verticles number in openBRF.
:grin:
 
DarkNord said:
Where is viking conquest thread in which they tell what can i or i can't do?

on the VC forum  :razz:

https://forums.taleworlds.com/index.php/topic,349080.0.html



PPQ_Purple said:
IF "Player_Faction OWNS Fief" AND "lord BELONGS TO Player_Faction" THEN "my custom recruitment" ELSE "default stuff"

OK, so your doubt is...? If you start writing your code and show it to us, we can help finish it

And when in doubt about constants: check module_constants.py, it is divided by type (parties, troops, etc), which usually allows to find them quickly -> I want the lord of a town (party), so I should check the constants used for a party
Code:
slot_town_lord                 = 7
 
Well for a start I have no idea how to check what faction a town belongs to. I can check if it belongs to the player but that's not what I want. I want faction ID not player ID. And not culture ID either.

And the constant file is basically useless as nothing is commented in it.
 
Hello everyone, so I have a question about triggers.

So, while making my mod I discovered ti_on_missile_hit on an item occurs before ti_on_agent_hit in mission templates. But that causes a major problem.

What I want to do is when an agent is hit by the item, the victim equips it. However, if it doesn't hit an agent, it spawns the item where it hit. Since ti_on_agent_hit is triggered afterwards, it cause the victim to equip the item but it also spawns the item where it hit. I have tried to resolve this by removing ti_on_agent_hit out of the equation, and just using ti_on_missile_hit to determine how close someone was to the item when it hits. However, I do not know the exact measurements of the agent "hit box" and therefore there are cases where the victim is hit but doesn't equip the item. Any suggestions?
 
Nord Champion said:
Hello everyone, so I have a question about triggers.

So, while making my mod I discovered ti_on_missile_hit on an item occurs before ti_on_agent_hit in mission templates. But that causes a major problem.

What I want to do is when an agent is hit by the item, the victim equips it. However, if it doesn't hit an agent, it spawns the item where it hit. Since ti_on_agent_hit is triggered afterwards, it cause the victim to equip the item but it also spawns the item where it hit. I have tried to resolve this by removing ti_on_agent_hit out of the equation, and just using ti_on_missile_hit to determine how close someone was to the item when it hits. However, I do not know the exact measurements of the agent "hit box" and therefore there are cases where the victim is hit but doesn't equip the item. Any suggestions?
should work better but not superb with getting troop location and missile location
Maybe wait for the spawning by linking to an mission template so spawning is chosen after on agent hit
Do this by assigning an condition in ti on missile hit then add a 1 second trigger with the condition you just set up
 
PPQ_Purple said:
And the constant file is basically useless as nothing is commented in it.

you don't need comments, the constants themselves are the comments  :wink:

PPQ_Purple said:
Well for a start I have no idea how to check what faction a town belongs to.

a town is what? A party
a kindgom is what? A faction

operations use two major convention to acquire a value: store_XXX or XXX_get

we check Z09
Code:
store_faction_of_party                = 2204  # (store_faction_of_party, <destination>, <party_id>),
                                              # Retrieves current faction allegiance of the party.
that is a good bet. Test if it applies to your modsys.



Nord Champion said:
Any suggestions?

use globals or slots to flag your item. Global is best used if you only care about 1 agent (the player), while slots are better if you want a generic solution (any agent in the field).

then you can check for the flag on the agent_is_hit
 
Well it works... sort of. Basically I am a tad puzzled.

When exactly does the script update_volunteer_troops_in_village trigger? I thought it was the script that determined what troops you get to recruit and that should mean it is triggered when you try and recruit something. But apparently (added some debug outputs to see) it just seems to go around on its own (my output showed it triggering without me touching a village).
 
PPQ_Purple said:
When exactly does the script update_volunteer_troops_in_village trigger?

funny way to put it. You answered your own question there  :mrgreen:

trigger

some scripts are called directly by the engine. Those are (usually) annotated with comments about it. All others you should do a text search on the entire folder (Sublime Text, Notepad++ with Explorer plugin, etc) can do that.

Code:
module_scripts.py:
  818  	  
  819        (try_for_range, ":village_no", villages_begin, villages_end),
  820:         (call_script, "script_update_volunteer_troops_in_village", ":village_no"),
  821        (try_end),
  822  	  
  ...
 23851        (try_begin),
 23852          (party_slot_eq, ":center_no", slot_party_type, spt_village),
 23853:         (call_script, "script_update_volunteer_troops_in_village", ":center_no"),
 23854        (try_end),
 23855        
 .....
 31180       ]),
 31181       
 31182:   #script_update_volunteer_troops_in_village
 31183    # INPUT: arg1 = center_no
 31184    # OUTPUT: none
 31185:   ("update_volunteer_troops_in_village",
 31186      [
 31187         (store_script_param, ":center_no", 1),

module_simple_triggers.py:
 2527       (call_script, "script_update_villages_infested_by_bandits"),
 2528       (try_for_range, ":village_no", villages_begin, villages_end),
 2529:        (call_script, "script_update_volunteer_troops_in_village", ":village_no"),
 2530         (call_script, "script_update_npc_volunteer_troops_in_village", ":village_no"),
 2531       (try_end),

game_start (new game), a special event (change relation with center) and on a schedule of 72hours.

if you use Sublime Text don't forget to install MB Warband API
 
Status
Not open for further replies.
Back
Top Bottom