vitali-attila
Regular
kalarhan said:vitali-attila said:Well, I could not find a way to define the IMOD of the ":cur_item". Maybe you know how to do this?kalarhan said:Imagine you have two lances, one is a masterwork lance and the other is a cracked lance.
You are using the cracked lance... it *breaks*. Your script will remove the first one that finds, so it will remove the masterwork one (expensive, better quality).
Slot Weapon Quality Item_ID
0 Lance Masterwork 333
1 Lance Cracked 333
2 Shield Plain 50
3 Sword Plain 67
Or you could find a lance in the ground and pick it up. That won't match your troop slots. And so on.
You are missing a try_end there. Fix your identation as that makes it easier to see it.
Did you download Lav's version of the modules? It has a better header_operations.py (with documentation)
Add display_message for debugging when you are doing something new and that you are unsure about it. After it is working you can exclude them
Anyway, even without using a modifier the item is not removed when I get back to the World Map after a battle.
Code:#If it's a player remove it from the inventory forever(cause it's broken) (try_begin), #vitali TEST(not working yet. work on) (eq, ":cur_agent", ":player_agent"), (assign, ":has_item", -1), (try_for_range, ":slot_no", 0, 4), (troop_get_inventory_slot, ":cur_slot", ":player_agent", ":slot_no"), (eq, ":cur_slot", ":cur_item"), #(store_item_kind_count, ":num_cur_items", ":cur_item"), #add this(if 2 hussar lances, decide which to remove) and extend when the simple removing will work (assign, ":has_item", ":cur_item"), (try_end), (try_begin), (ge, ":has_item", 0), (troop_remove_item, "trp_player", ":cur_item"), (display_message, "@The broken lance is removed form the inventory :)"), (else_try), (display_message, "@The lance could not be found :("), (try_end), (try_end),
You are still confused about troops X agents . Check Caba's comment again, and download Lav's version of modules as his header_operations.py is very well organized and has more helpful text in there...
Code:(troop_get_inventory_slot, ":cur_slot", ":player_agent", ":slot_no"),
Code:troop_get_inventory_slot = 1541 # (troop_get_inventory_slot, <destination>, <troop_id>, <inventory_slot_no>), # Retrieves the item_id of a specified equipment or inventory slot. Returns -1 when there's nothing there.
Besides that you should remember to post the debug messages on future questions, as saying something doesn't work can mean a lot of things . That is why the debug messages are there, so show them to us too.
use this struct to print variables
Code:(assign, reg10, ":cur_item"), (assign, reg11, ":player_agent"), (display_message, "@Stuff I am debugging... and my variables are {reg10} , {reg11}"),
Hi. Thank you very much for the advises. With your help I finally managed to make the lance get lost.
It's curious that the same code(removing the lance from the player's inventory) did not succeed when I launched it during the battle, but worked perfectly when I called from the mnu_battle_debrief.
Anyway if you are interested how I made it:
The code works the following way:
First a script is called from module_mission_template
Then if the agent is the player, a global variable "$g_hussar_lance_broken" is incremented. That means that there is one broken lance in the player's inventory
Afterwards, when the mission(battle) is complete the game checks how many lances have been broken
It is done in mnu_battle_debrief
Finally, depending on how many lances are broken the following script removes them from the player's inventory
...And assigns the global variable back to 0.
What do you think? Maybe I left something vital?
First a script is called from module_mission_template
Code:
# Trigger Param 1: damage inflicted agent_id
# Trigger Param 2: damage dealer agent_id
# Trigger Param 3: inflicted damage
# Register 0: damage dealer item_id
# Position Register 0: position of the blow
# rotation gives the direction of the blow
vitali_on_couched_lance_damage = (
ti_on_agent_hit, 0, 0, [],
[
(store_trigger_param_1, ":inflicted_agent"),
(store_trigger_param_2, ":cur_agent"),
(store_trigger_param_3, ":inflicted_damage"),
(assign, ":cur_item", reg0),
(call_script, "script_vitali_game_event_agent_hit", ":inflicted_agent", ":cur_agent", ":inflicted_damage", ":cur_item"),
(try_end),
])
Then if the agent is the player, a global variable "$g_hussar_lance_broken" is incremented. That means that there is one broken lance in the player's inventory
Code:
#script_vitali_game_event_agent_hit
("vitali_game_event_agent_hit",
[
#(store_script_param, ":inflicted_agent", 1), #uncomment the line when will you use this variable
(store_script_param, ":cur_agent", 2),
(store_script_param, ":inflicted_damage", 3),
(store_script_param, ":cur_item", 4),
(get_player_agent_no, ":player_agent"),
(try_begin),
(gt, ":inflicted_damage", 90), #if this is a big damage
(agent_is_active, ":cur_agent"),
#If a polish hussar lance is used
(this_or_next|eq, ":cur_item", itm_gusar_lanza),
(this_or_next|eq, ":cur_item", itm_gusar_lanza_b),
( eq, ":cur_item", itm_gusar_lance),
(play_sound_at_position, "snd_lance_broken", pos0),
#If it's a player
(try_begin),
(eq, ":cur_agent", ":player_agent"),
(troop_has_item_equipped, "trp_player", ":cur_item"),
#add 1 more broken lance
(val_add, "$g_hussar_lance_broken", 1),
(try_end),
. . . etc.
Afterwards, when the mission(battle) is complete the game checks how many lances have been broken
It is done in mnu_battle_debrief
Code:
#If there is 1 or more broken lances, call the script
(try_begin),
(ge, "$g_hussar_lance_broken", 1),
(call_script, "script_vitali_remove_hussar_lance"),
(try_end),
Finally, depending on how many lances are broken the following script removes them from the player's inventory
Code:
#script_vitali_remove_hussar_lance
("vitali_remove_hussar_lance",
[
#Through the lance away(cause it's broken)
(display_message, "@script_vitali_remove_hussar_lance started"),
(try_for_range, ":i", 0, "$g_hussar_lance_broken"), #loop as many times as the player broke the lances in the previous battle
(assign, ":break", 0),
(try_for_range, ":slot_no", 0, 4),
(eq, ":break", 0),
(troop_get_inventory_slot, ":cur_slot", "trp_player", ":slot_no"),
(this_or_next|eq, ":cur_slot", "itm_gusar_lanza"),
(this_or_next|eq, ":cur_slot", "itm_gusar_lanza_b"),
( eq, ":cur_slot", "itm_gusar_lance"),
(troop_set_inventory_slot, "trp_player", ":slot_no", -1),
(assign,":break", 1),
(assign, reg10, ":cur_slot"),
(assign, reg11, ":slot_no"),
(display_message, "@The broken lance is removed from the inventory"),
(display_message, "@hussar lance = {reg10}, slot_no = {reg11}"),
(try_end),
(try_end),
(assign, "$g_hussar_lance_broken", 0), #obnulim :)
]),
What do you think? Maybe I left something vital?