Modding Q&A [For Quick Questions and Answers]

Users who are viewing this thread

Status
Not open for further replies.
HyperCharge said:
How can I make some sort of gravity

you can spawn a entity and push it

you can spawn a static entity and animate movement from X to Y

first is easier, but lacks control of destination
second is harder to make look good, but you can easily choose destination

see header_operations.py
 
Khamukkamu said:
When you increase the amount of items, do you just increase the range? for example, from 0 - 100, to 0 - 200 ?
I never had to do that (I added new cases to some party spawn triggers, but they didn't require the result, i.e. there was 'free space' - like I generated a number between 1 and 1000, and if it was between 0 and 200, a party spawned, otherwise nothing happened, so when I added more parties, I just increased the effective range, like added 200-300 and 300-450), but I guess so. It depends on the situation, on how you want probabilities to change - all evenly, or at the cost of 1-2 (if a new case resembles 1 of the old ones, for example).
 
Khamukkamu said:
Hi all,

Can anyone recommend a better way of doing randomized, weighted selection? I'm currently doing it in a very inelegant way:

Code:
  ("get_freelancer_mission", [
      (assign, "$cheat_imposed_quest", 0),
      (store_random_in_range, ":chance", 0, 100),
      (try_begin),
        (le, ":chance", 20),
        (assign, ":continue", 0),
        (assign, "$cheat_imposed_quest", "qst_deliver_message"), #deliver Message
        (call_script, "script_get_quest", "$enlisted_lord"),
        (try_begin),
          (eq, reg0, "$cheat_imposed_quest"),
          (assign, ":continue", 1),
        (try_end),
        (eq, ":continue", 1),
        (start_map_conversation, "$enlisted_lord"),
        
      (else_try),
        (le, ":chance", 35),
        (assign, "$cheat_imposed_quest", "qst_scout_waypoints"), #Scout Waypoints
        (start_map_conversation, "$enlisted_lord"),
        
      (else_try),
        (le, ":chance", 45),
        (jump_to_menu, "mnu_freelancer_bandits"), #Troublesome Bandits
        (start_map_conversation, "$enlisted_lord"),
        
      (else_try),
        (le, ":chance", 65),
        (assign, ":continue", 0),
        (assign, "$cheat_imposed_quest", "qst_hunt_down_fugitive"), #hunt down fugitive
        (call_script, "script_get_quest", "$enlisted_lord"),
        (try_begin),
          (eq, reg0, "$cheat_imposed_quest"),
          (assign, ":continue", 1),
        (try_end),
        (eq, ":continue", 1),
        
      (else_try),
        (le, ":chance", 85),
        (jump_to_menu, "mnu_freelancer_training_choose"), #Training
        
      (else_try),
        (jump_to_menu, "mnu_freelancer_looters"), #Looters
      (try_end),
  ]),
This method is fine unless your code itself gives you a shortcut. For example, instead of simply a random number 0-100 use a starting point (like 20 or 0-20) and then add to it based on other factors, like party size, player level, etc. Adding 5 each time the lowest quest is assigned for example will lower the chance of getting the same quest, or organize them so that you can add party size to the random number so that quests given are appropriate for player strength (scouting if you have few troops, etc etc)

It might not end up saving many lines, but with just a bit of variable manipulation you transform simple codes like this from boring 0-100 rng to dynamic codes that are directly influenced by the players own game.
 
While giving a random castle to a starting player I found that an "empty" castle, or a castle not assigned to an npc, works as intended and that's what the player will start with but if the castle has a lord already in it, it (the castle) doesn't get assigned to the player. How should I clear the castle of it's current lord to make sure it gets assigned to the player? I have a feeling that I just need to know the correct slot to call but here's what I have so far...
Code:
(troop_get_slot, ":center_lord", reg48, slot_town_lord),
	(remove_party,":center_lord"),
 
Iron Sight said:
While giving a random castle

bunch of stuff to setup. So that bunch of stuff is hidden inside a script. You call the script (one line of code), and you don't worry about all that stuff. That is the gist.

script_give_center_to_lord
 
Out of curiosity, can you think of a way to change the water level or simply disable water in a scene? The water level modifier in module_scenes doesn't seem to do anything (some say it works for indoor scenes, but I haven't tried it).
 
Hi,
When I add these codes;
To scripts:
Code:
(assign, ":name", "str_ct_inf_1_name"),
       (assign, ":desc", "str_ct_inf_1_desc"),
       (troop_set_slot, "trp_ct_inf_1", slot_troop_name, ":name"),
       (troop_set_slot, "trp_ct_inf_1", slot_troop_desc, ":desc"),


(assign, ":name", "@Infantry"),
       (assign, ":desc", "@Maybe this unit ca not be a terrible force, but at least better than other militia units."),
       (troop_set_slot, "trp_ct_inf_2", slot_troop_name, ":name"),
       (troop_set_slot, "trp_ct_inf_2", slot_troop_desc, ":desc"),


(assign, ":name", "@Elite Infantry"),
       (assign, ":desc", "@This unit is a terrible force! Any other units who saw them, runs like cowards! There is no unit that can show force to this unit."),
       (troop_set_slot, "trp_ct_inf_3", slot_troop_name, ":name"),
       (troop_set_slot, "trp_ct_inf_3", slot_troop_desc, ":desc"),



(assign, ":name", "@Novice Archer"),
       (assign, ":desc", "@This unit hasn't got too much accuracy. But against large armird with positioed at tight formation, this unit can cause terrors in armies."),
       (troop_set_slot, "trp_ct_arc_1", slot_troop_name, ":name"),
       (troop_set_slot, "trp_ct_arc_1", slot_troop_desc, ":desc"),


(assign, ":name", "@Archer"),
       (assign, ":desc", "@This unit's accuracy is neither good nor bad. Both can prove a show against enemies which are formationed as thight or loose formation."),
       (troop_set_slot, "trp_ct_arc_2", slot_troop_name, ":name"),
       (troop_set_slot, "trp_ct_arc_2", slot_troop_desc, ":desc"),

(assign, ":name", "@Elite Archer"),
(assign, ":desc", "@This unit has quite good accuracy. Can fight well, can kill an enemy with a bow well, and gives you a great advantage well."),
       (troop_set_slot, "trp_ct_arc_3", slot_troop_name, ":name"),
       (troop_set_slot, "trp_ct_arc_3", slot_troop_desc, ":desc"),


(assign, ":name", "@Novice Cavalry"),
       (assign, ":desc", "@This unit can not fight well, but at least, they can hack a hole with a little charge."),
       (troop_set_slot, "trp_ct_cav_1", slot_troop_name, ":name"),
       (troop_set_slot, "trp_ct_cav_1", slot_troop_desc, ":desc"),


(assign, ":name", "@Cavalry"),
       (assign, ":desc", "@Can this unit hack a hole in formations? Well, this unit proves it much more of predicted."),
       (troop_set_slot, "trp_ct_cav_2", slot_troop_name, ":name"),
       (troop_set_slot, "trp_ct_cav_2", slot_troop_desc, ":desc"),


(assign, ":desc", "@This unit is like turtles! Unstoppable, greatly equippped, great charging, and much more!"),
       (assign, ":name", "@Elite Cavalry"),
       (troop_set_slot, "trp_ct_cav_3", slot_troop_name, ":name"),
       (troop_set_slot, "trp_ct_cav_3", slot_troop_desc, ":desc"),
And to prsnt:
Code:
(troop_get_slot, ":n", "$chosen_unit", slot_troop_name),
      (troop_get_slot, ":d", "$chosen_unit", slot_troop_desc),
      (str_store_string, s1, ":n"),
      (str_store_string, s2, ":d"),
Game says "no string". How can I solve it?
 
kalarhan said:
Iron Sight said:
While giving a random castle

bunch of stuff to setup. So that bunch of stuff is hidden inside a script. You call the script (one line of code), and you don't worry about all that stuff. That is the gist.

script_give_center_to_lord

I already have the code to give a random castle to a new player, although, as stated, if the castle has an npc in it, the castle won't actually get assigned to the player but if the castle happens to be "empty", with no lord in it at the time the game starts, then the castle will belong to the player. So, it works about half the time. I just need help referencing the lord of the castle so I can remove him. Also, I can give a random town remove it's current lord to give to a new player but the referencing for a town lord and a castle lord doesn't seem to be the same.
 
kalarhan said:
Iron Sight said:
I just need help referencing the lord of the castle so I can remove him.

that is what the script does  :razz:

open it, read it, see all the stuff it does

I have, over and over. That's how I came to the conclusion to call the slots that I have so far, to no avail. I did actually try to solve this already. Thanks tho.
 
Kortlcha said:
Game says "no string". How can I solve it?

string is not a number. You use a number for its reference index. But it is not a number. So you can't use a numeric function/operation with a string. How can you do this: "a + 10"

what you do with strings is concatenation. You use registers (numeric type variables) and tokens. A example:

Code:
(assign, reg1, 10),
(str_store_string, s1, "@hi my value is {reg10}"),

you can find more about different types of variables in the tutorial section



Iron Sight said:
I have, over and over. That's how I came to the conclusion to call the slots that I have so far, to no avail.
call the script, simple as that.

if you have a specific issue you will need to show us what is wrong (logs, example of slot values, screenshots, etc).
 
Kortlcha said:
I didn't use numbers.

Code:
(troop_get_slot, ":n", "$chosen_unit", slot_troop_name),
      (troop_get_slot, ":d", "$chosen_unit", slot_troop_desc),
      (str_store_string, s1, ":n"),
      (str_store_string, s2, ":d"),

both ":n" and ":d" are local variables. Local variables are numeric. As in, numbers. They are not strings.

Btw you have a operation to retrieve a troop name (not from a slot).
 
I Want to set a string to troop's slot like:sad:Vanilla code)
(faction_set_slot, "fac_kingdom_1", slot_faction_adjective, "str_kingdom_1_adjective"),
And get it's slot like this code:sad:Vanilla code)
(str_store_string, s0, ":string_index"),
But I want to set a string as local variable. I want to do this.
 
Iron Sight said:
Code:
(troop_get_slot, ":center_lord", reg48, slot_town_lord),
	(remove_party,":center_lord"),
Oh jesus.
All operations are explained in Lav's module system.
Don't use operations before learning how they work.

Kortlcha, try storing names and descriptions in strings, not in quick_strings.
Example from my code:

("fi_bettertools", "Better Tools"), #from module_stings
(troop_set_slot, ":fi_cache_troop", fief_improvements_cached_data_slots_begin, "str_fi_bettertools"), #from scripts

(troop_get_slot, ":improvement_name", ":eek:ffset", fief_improvements_cached_data_slots_begin), #from presentations
(str_store_string, s1, ":improvement_name"),
(create_text_overlay, reg1, s1, tf_left_align),
 
Status
Not open for further replies.
Back
Top Bottom