Modding Q&A [For Quick Questions and Answers]

Users who are viewing this thread

Status
Not open for further replies.
Caba`drin said:
A few ways you could find out about land/water. The easiest would likely be
(party_get_current_terrain,<destination>,<party_id>),
with the result rt_water = 0  (see header_terrain_types)
How can I find the terrain around a party (village in this case)? Something like:
0###0
#####
##P##
#####
0###0

Edit: not one tile randomly. I want to know all the tiles around a village.

Or to check where a certain type of terrain lie within a certain radius (of the village). For example, is there water (ocean or river) within radius of 2.
 
Well, I got it working with some work around. Id still want to know how to do it withe the slot suggestion. The arrow death sounds don't work. So how do I make it so that when an arrow specific death sound? I'm currently trying this

Code:
	[(ti_on_missile_hit, 0, 0, [],[
		(assign, ":item", reg0),
		(store_trigger_param_1, ":inflicted_agent"),
		(agent_is_human, ":inflicted_agent"), #no animal abuse?
		(store_trigger_param_3, ":damage"),
		(store_agent_hit_points, ":hp", ":inflicted_agent", 1),
		(val_sub, ":hp", ":damage"),
		(le, ":hp", 0),
		(try_begin),
			(eq, ":item", "itm_arrows),
			(agent_play_sound, ":inflicted_agent", "snd_arrow_death"),
		(try_end),
    #or fetch sound from item slot, etc.
	])]],
Using it on arrow itm.
 
SPD_Phoenix said:
Edit: not one tile randomly. I want to know all the tiles around a village.

Or to check where a certain type of terrain lie within a certain radius (of the village). For example, is there water (ocean or river) within radius of 2.
You can't know all the tiles, because there is no "tiles" - map is arbitrary triangulated mesh.
Maximum you can do is check whever water is available around party - use <map_get_water_position_around_position>. It can fail AFAIR, so if it fails - there is no water.

If you want to know approximate terrain around party, you can run e.g. monte-carlo spray of positions in some circle around your party, gathering statistics with party_get_current_terrain, then analyse this statistics.

 
mr.master said:
Hmm. Found out that you cant change the order of the weapons or the game will explode. Any suggestions? I though that I could use your suggestion dunde but I'm not too sure how to do it.

Define some constants at module_constants.py :
Code:
   slot_item_weapon_type = 200 # pick your number, search for unused item slot
   weapon_type_polearm = 1
   weapon_type_sword   = 2
   weapon_type_axe     = 3
   weapon_type_mace    = 4 


Put this above the scripts = [ of module_scripts.py (below last import):
Code:
from module_items import *

def set_item_weapon_type():
  weapon_type = []
  for i_item in xrange(len(items)):
    if items[i_item][7] == imodbits_polearm:
      weapon_type.append((item_set_slot, i_item, slot_weapon_type, weapon_type_polearm))
    if items[i_item][7] == imodbits_sword:
      weapon_type.append((item_set_slot, i_item, slot_weapon_type, weapon_type_sword))
    if items[i_item][7] == imodbits_sword_high:
      weapon_type.append((item_set_slot, i_item, slot_weapon_type, weapon_type_sword))
    if items[i_item][7] == imodbits_axe:
      weapon_type.append((item_set_slot, i_item, slot_weapon_type, weapon_type_axe))
    if items[i_item][7] == imodbits_mace:
      weapon_type.append((item_set_slot, i_item, slot_weapon_type, weapon_type_mace))
  return weapon_type[:]


Make a new script :
Code:
("init_weapon_type", set_item_weapon_type()),


Call the script on "game_start" script :
Code:
   (call_script, "script_init_weapon_type"),

Ok, those codes will init your weapon type for all items. You can use at mission template :
  (item_slot_eq,":weapon",slot_item_weapon_type,weapon_type_polearm),
      < Play sound for polearm >

The Problem is : I found some weapon types above have same imodbits. by default. (imodbits_mace=imodbits_axe). You should make each imodbits for each wapon type be unique by adding /removing some imodbit from the constants at module_items.py.
 
To find the ammo being used (inside a ti_on_agent_hit trigger):
Code:
(store_trigger_param_2, ":dealer_agent"),
(agent_get_ammo, ":ammo", ":dealer_agent", 1),

Otherwise, if you don't need to fetch the actual type to use it anywhere else, you can use the following instead:
Code:
from module_items import *
from id_sounds import *
def set_item_weapon_type():  
    weapon_type = []  
    for i_item in xrange(len(items)):    
        if items[i_item][7] == imodbits_polearm:
            weapon_type.append((item_set_slot, i_item, slot_item_sound, snd_spear_death))
        elif (items[i_item][7] == imodbits_sword) or (items[i_item][7] == imodbits_sword):
            weapon_type.append((item_set_slot, i_item, slot_item_sound, snd_sword_death))
        elif items[i_item][7] == imodbits_axe:
            weapon_type.append((item_set_slot, i_item, slot_item_sound, snd_axe_death))
        elif items[i_item][7] == imodbits_mace:
            weapon_type.append((item_set_slot, i_item, slot_item_sound, snd_club_death))

    return weapon_type[:]

And then use it here:
Code:
(item_get_slot, ":sound", ":item", slot_item_sound),
(gt, ":sound", 0),
(agent_play_sound, ":inflicted_agent", ":sound"),
 
GetAssista said:
You can't know all the tiles, because there is no "tiles" - map is arbitrary triangulated mesh.
Maximum you can do is check whever water is available around party - use <map_get_water_position_around_position>. It can fail AFAIR, so if it fails - there is no water.

If you want to know approximate terrain around party, you can run e.g. monte-carlo spray of positions in some circle around your party, gathering statistics with party_get_current_terrain, then analyse this statistics.
How would I do a "spay of position"?

My plan is this:
- Use "map_get_land_position_around_position" to get a position. How do I manipulate the positions as I want to?
- Put a dummy party there.
- Get the terrain type where the dummy party sit.

I want to get the type of terrain a round a village and build the village economy on top of that. It's also an AI check when it decides to erect a new village. The ability for AI to put a village in the best location (production wise). Anyway, this is still far down in my modding list. Just gather some info.
 
Make a bunch of disabled dummy parties in a grid. At startup, store their terrain information into slots, and associate each existing village to its nearest neighboring grid element. You should preferrably have some easy algorithm to associate the x-y components of party_get_position with each dummy party. You can make the grids with whatever (uniform) spacing you feel like, in whatever form (hexagonal, rectagular) as long as you have a way of determining its neighbours.
 
Code:
   if items[i_item][7] == imodbits_polearm:
It will be more accurate if we can use [i_item][0] ->(item ID). Any one know how to check if there is substring "polearm" in string items[i_item][0] in python?  For I know almost nothing about python syntax. By using item Id, we don't need to make imodbits for each weapon being unique. We just need to make sure the each item ID is contain 'sword', 'polearm', etc according to it's type.
 
That would be quite good if it's possible. Anyways, went along and tried the codes. Something went wrong since cant hear nothing now. Ill post the codes here to be safe

Module constants
Code:
slot_item_weapon_type = 200 # pick your number, search for unused item slot
weapon_type_polearm = 1
weapon_type_sword   = 2
weapon_type_axe     = 3
weapon_type_mace    = 4  
slot_item_sound = 230

module scripts at top after last import.

Code:
from module_items import *
from ID_sounds import *
def set_item_weapon_type():  
    weapon_type = []  
    for i_item in xrange(len(items)):    
        if items[i_item][7] == imodbits_polearm:
            weapon_type.append((item_set_slot, i_item, slot_item_sound, snd_spear_death))
        elif (items[i_item][7] == imodbits_sword) or (items[i_item][7] == imodbits_sword):
            weapon_type.append((item_set_slot, i_item, slot_item_sound, snd_sword_death))
        elif items[i_item][7] == imodbits_axe:
            weapon_type.append((item_set_slot, i_item, slot_item_sound, snd_axe_death))
        elif items[i_item][7] == imodbits_mace:
            weapon_type.append((item_set_slot, i_item, slot_item_sound, snd_club_death))
        elif items[i_item][7] == imodbits_missile:
            weapon_type.append((item_set_slot, i_item, slot_item_sound, snd_arrow_death))
    return weapon_type[:]

and

Code:
scripts = [

  ("init_weapon_type", set_item_weapon_type()),
  
  #script_game_start:
  # This script is called when a new game is started
  # INPUT: none
  ("game_start",
   [   
      (call_script, "script_init_weapon_type"),
     

module mission templates

Code:
	(ti_on_agent_hit, 0, 0, [],[
		(assign, ":item", reg0),
		(store_trigger_param_1, ":inflicted_agent"),
		(agent_is_human, ":inflicted_agent"), #no animal abuse?
		(store_trigger_param_3, ":damage"),
		(store_agent_hit_points, ":hp", ":inflicted_agent", 1),
		(val_sub, ":hp", ":damage"),
		(le, ":hp", 0),
		(try_begin),
			(item_get_slot, ":sound", ":item", slot_item_sound),
			(gt, ":sound", 0),
			(agent_play_sound, ":inflicted_agent", ":sound"),
		(try_end),
    #or fetch sound from item slot, etc.
	]),



 
Try changing ID_sounds to module_sounds (although that might already be included in module_scripts) and add quotations around "snd_whatever". To check if the slots were set properly, go in game_get_item_extra_text, and paste the following after the parameters.
Code:
(try_begin),
  (eq, ":extra_text_id", 0), #so it only plays once
  (item_get_slot, ":sound", ":item_no", slot_item_sound),
  (play_sound, ":sound"),
(try_end),
When you mouse over the item in your inventory, the appropriate sound should play.

Also, the second imodbits_sword should be imodbits_sword_high
 
Nope. Wont work in inventory nor in battle.

Code:
from module_items import *
from module_sounds import *
def set_item_weapon_type():  
    weapon_type = []  
    for i_item in xrange(len(items)):    
        if items[i_item][7] == imodbits_polearm:
            weapon_type.append((item_set_slot, i_item, slot_item_sound, "snd_spear_death"))
        elif (items[i_item][7] == imodbits_sword) or (items[i_item][7] == imodbits_sword_high):
            weapon_type.append((item_set_slot, i_item, slot_item_sound, "snd_sword_death"))
        elif items[i_item][7] == imodbits_axe:
            weapon_type.append((item_set_slot, i_item, slot_item_sound, "snd_axe_death"))
        elif items[i_item][7] == imodbits_mace:
            weapon_type.append((item_set_slot, i_item, slot_item_sound, "snd_club_death"))
        elif items[i_item][7] == imodbits_missile:
            weapon_type.append((item_set_slot, i_item, slot_item_sound, "snd_arrow_death"))
    return weapon_type[:]

 
wtype.jpg
Code:
    if items[i_item][7] == imodbits_polearm:
        print items[i_item][0] + " is a polearm"
    elif (items[i_item][7] == imodbits_sword) or (items[i_item][7] == imodbits_sword_high):
        print items[i_item][0] + " is a sword"
    elif items[i_item][7] == imodbits_axe:
        print items[i_item][0] + " is an axe/mace"
I'm not sure why the slots aren't properly set then.
 
Could it be that I set the init_weapon type and call script to wrong places?

scripts = [

  ("init_weapon_type", set_item_weapon_type()),
 
  #script_game_start:
  # This script is called when a new game is started
  # INPUT: none
  ("game_start",
  [ 
      (call_script, "script_init_weapon_type"),

 
dunde said:
game_start should be the 1st script. make init_weapon_type below. the safe place is to be the last script
alrighty, I made. Still no change. I can't really see what the problem is with the code.


Ill just post the current state of the codes, just in-case.

Module Constants
Code:
slot_item_weapon_type = 200 # pick your number, search for unused item slot

weapon_type_polearm = 100

weapon_type_sword   = 101

weapon_type_axe     = 102

weapon_type_mace    = 103 

slot_item_sound = 104

module scripts after last import

Code:
from module_items import *
from module_sounds import *
def set_item_weapon_type():  
    weapon_type = []  
    for i_item in xrange(len(items)):    
        if items[i_item][7] == imodbits_polearm:
            weapon_type.append((item_set_slot, i_item, slot_item_sound, "snd_spear_death"))
        elif (items[i_item][7] == imodbits_sword) or (items[i_item][7] == imodbits_sword_high):
            weapon_type.append((item_set_slot, i_item, slot_item_sound, "snd_sword_death"))
        elif items[i_item][7] == imodbits_axe:
            weapon_type.append((item_set_slot, i_item, slot_item_sound, "snd_axe_death"))
        elif items[i_item][7] == imodbits_mace:
            weapon_type.append((item_set_slot, i_item, slot_item_sound, "snd_club_death"))
        elif items[i_item][7] == imodbits_missile:
            weapon_type.append((item_set_slot, i_item, slot_item_sound, "snd_arrow_death"))
    return weapon_type[:]

module scripts game start

Code:
scripts = [
 
  #script_game_start:
  # This script is called when a new game is started
  # INPUT: none
  ("game_start",
   [   
      (call_script, "script_init_weapon_type"),

Module scripts at the end

Code:
   (try_end),  
  ]),
  
 ("init_weapon_type", set_item_weapon_type()), 
 
]

module mission templates at singleplayer battle.

Code:
....
        ]),

      common_battle_init_banner,
	  
	(ti_on_agent_hit, 0, 0, [],[
		(assign, ":item", reg0),
		(store_trigger_param_1, ":inflicted_agent"),
		(agent_is_human, ":inflicted_agent"), #no animal abuse?
		(store_trigger_param_3, ":damage"),
		(store_agent_hit_points, ":hp", ":inflicted_agent", 1),
		(val_sub, ":hp", ":damage"),
		(le, ":hp", 0),
		(try_begin),
			(item_get_slot, ":sound", ":item", slot_item_sound),
			(gt, ":sound", 0),
			(agent_play_sound, ":inflicted_agent", ":sound"),
		(try_end),
    #or fetch sound from item slot, etc.
	]),
		 
      (ti_on_agent_killed_or_wounded, 0, 0, [],
       [
.....


Any possibility if you guys could test it with a test sound to see if it's just with me codes in wrong place or something?
 
try to use slot_item_sound=61 then set slot_item_multiplayer_availability_linked_list_begin=62.
One more, if you use it on quick battles, then "game_start" script is not called. So put
  (call_script, "script_init_weapon_type"),
in "game_quick_start" script also.
 
SPD_Phoenix said:
My plan is this:
- Use "map_get_land_position_around_position" to get a position. How do I manipulate the positions as I want to?
- Put a dummy party there.
- Get the terrain type where the dummy party sit.
Well, "map_get_land_position_around_position" returns you a random land position, so cycle through it like 50-100 times and store resulting terrains. On second thought though - it does choose among passable terrains, so water and mountains would not appear in statistics, which is bad.

You can probably do a simple position manipulation instead, with taking village initial position, then using position_rotate_z and position_move_y in a cycle to go through dots in a circle (or several concentric circles) around village, reading terrain each time.
 
Status
Not open for further replies.
Back
Top Bottom