Need Guiding About Event Handling in PW Module System

Currently viewing this thread:

Saptor

Sergeant
WBWF&SNWVC
Hello  :smile:. I have experience with Python. Can anyone tell me about events in PW Module System?

How can I handle something like event during game?

Example: A method or a script calling when a player attacked to another?
 
Sorry, but you are asking an impossible question here, Find out for yourself, watch tutorials on YouTube etc. etc. Before you start asking such a big question.
This question shows you have no experience in Warband scripting.
 

Saptor

Sergeant
WBWF&SNWVC
That's true, I don't. My experience is on Python as I told so.

And actually I known Warband scripting is not like a plugin system so we can't handle events directly and because of that I said "something like event".

I guess my question is about triggers (not sure). What happens when a player did something? Which trigger gets called? (not sure again)

Note: I want to learn these because I will not add any object, item, building or such thing on modules.
 

Ra'Jiska

Subforum Moderator
WF&SWBNWM&BVC
Your experience in Python won't help you AT ALL as Warband scrypting uses Python to be built (which is why files are *.py), but uses its own scripting language.
Concerning your question, events are all hard coded and can be found in the file 'module_mission_templates.py'.
Here is a little example :

mission_templates.py
PHP:
player_exit = (ti_on_player_exit, 0, 0, [], # The ti_on_player_exit is the hard coded event
   [(store_trigger_param_1, ":player_id"), # The argument it takes
    (call_script, "script_cf_save_player_exit", ":player_id"), # The code it'll execute (here, it's a script called, all the called scripts are in 'module_scripts.py'
    ])

module_scripts.py
PHP:
  ("cf_save_player_exit", # Here is the script in question called by the event
   [(store_script_param, ":player_id", 1), # This is the argument sent in the call_script of the event handler

    # And all what follows are the scripts of the block
    (player_get_troop_id, ":troop_id", ":player_id"),
    (is_between, ":troop_id", playable_troops_begin, playable_troops_end),
    (player_get_unique_id, ":player_unique_id", ":player_id"),
    (troop_get_slot, ":inactive_array_size", "trp_inactive_players_array", slot_player_array_size),
    (assign, ":loop_end", ":inactive_array_size"),
    (assign, ":inactive_index", slot_player_array_begin),
    (try_for_range, ":unused", 0, ":loop_end"),
      (this_or_next|troop_slot_eq, "trp_inactive_players_array", ":inactive_index", 0),
      (troop_slot_eq, "trp_inactive_players_array", ":inactive_index", ":player_unique_id"),
      (assign, ":loop_end", -1),
    (else_try),
      (val_add, ":inactive_index", player_array_entry_size),
    (try_end),
    (try_begin),
      (call_script, "script_cf_player_store_inactive", ":player_id", ":inactive_index"),
      (troop_set_slot, "trp_inactive_players_array", ":inactive_index", ":player_unique_id"),
      (player_set_slot, ":player_id", slot_player_inactive_index, ":inactive_index"),
      (neq, ":loop_end", -1),
      (val_add, ":inactive_array_size", 1),
      (troop_set_slot, "trp_inactive_players_array", slot_player_array_size, ":inactive_array_size"),
    (try_end),
    (assign, ":loop_end", factions_end),
    (try_for_range, ":faction_id", castle_factions_begin, ":loop_end"),
      (faction_get_slot, ":lord_player_uid", ":faction_id", slot_faction_lord_player_uid),
      (eq, ":lord_player_uid", ":player_unique_id"),
      (assign, ":loop_end", -1),
      (store_mission_timer_a, ":current_time"),
      (faction_set_slot, ":faction_id", slot_faction_lord_last_seen_time, ":current_time"),
    (try_end),
    ]),

Read the comments in both blocks (both were not in the scripts by default) if you want more infos about how it works.
 

Vornne

Count
M&BWBNWVC
The above link is a good basic overview, and I would also suggest to read header_triggers.py and header_operations.py in the module system: the PW versions of those files have some extra comments to specify available parameters. If you are using Warband 1.165+ on your server and / or clients, you could also get the 4.4_merge_1.166 branch in the PW module system git repository: it includes some new or tweaked operations made available from that game engine version (differences viewable online here and here).
 
Top Bottom