login

Author Topic: M&B Scripting Q&A  (Read 113092 times)

DarkAnd

  • Guest
Re: M&B Scripting Q&A
« Reply #180 on: June 19, 2007, 11:54:40 am »
how i make a scene props to move?
i used this code


Code: [Select]
  ("siege_tower",0,"tower","bo_tower", [
      (ti_on_init_scene_prop,[
           (assign,"$tower",0),
           (store_trigger_param_1, reg59),    ]),
   ]),

Code: [Select]
    ("tower",
   [
           (prop_instance_get_starting_position, 1, reg59),
           (prop_instance_get_position, 120, reg59),
           (prop_instance_animate_to_position, reg59, 1, 6000), #animate to position 1 in 55.5 second
]),

Code: [Select]
    "visit_town_horseback",0,-1,
    "You enter the area",
    [(0,mtef_scene_source|mtef_team_1,0,0,1,[]),
     (1,mtef_scene_source|mtef_team_1,0,0,1,[]),(2,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),(3,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),(4,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),(5,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),(6,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),(7,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),
     (8,mtef_scene_source,af_override_horse,0,1,[]),
     (9,mtef_scene_source,af_override_horse,0,1,[]),(10,mtef_scene_source,af_override_horse,0,1,[]),(11,mtef_scene_source,af_override_horse,0,1,[]),(12,mtef_scene_source,af_override_horse,0,1,[]),(13,mtef_scene_source,0,0,1,[]),(14,mtef_scene_source,0,0,1,[]),(15,mtef_scene_source,0,0,1,[]),(16,mtef_scene_source,0,0,1,[]),
     (17,mtef_scene_source,af_override_horse,0,1,[]),(18,mtef_scene_source,af_override_horse,0,1,[]),(19,mtef_scene_source,af_override_horse,0,1,[]),(20,mtef_scene_source,af_override_horse,0,1,[]),(21,mtef_scene_source,af_override_horse,0,1,[]),(22,mtef_scene_source,af_override_horse,0,1,[]),(23,mtef_scene_source,af_override_horse,0,1,[]),(24,mtef_scene_source,af_override_horse,0,1,[]),
     (25,mtef_visitor_source,af_override_horse,0,1,[]),(26,mtef_visitor_source,af_override_horse,0,1,[]),(27,mtef_visitor_source,af_override_horse,0,1,[]),(28,mtef_visitor_source,af_override_horse,0,1,[]),(29,mtef_visitor_source,af_override_horse,0,1,[]),(30,mtef_visitor_source,af_override_horse,0,1,[]),(31,mtef_visitor_source,af_override_horse,0,1,[])
     ],
    [
      (ti_inventory_key_pressed, 0, 0, [(eq,"$tower",0),(assign,"$tower",1),(call_script,"script_tower")], []),
      (ti_tab_pressed, 0, 0, [(set_trigger_result,1)], []),
     ],
  ),

but nothing hapens

I also tried

    ("tower",
   [
           (prop_instance_get_starting_position, 1, reg59),
           (position_move_x, 1, 190),
           (prop_instance_animate_to_position, reg59, 1, 6000), #animate to position 1 in 55.5 second

bryce

  • Guest
Re: M&B Scripting Q&A
« Reply #181 on: July 01, 2007, 10:25:44 pm »
Ok, this is a crosspost. I read at some point of a way to disable troops so if you get within a certain distance (or any other arbitrary thing in a trigger) they suddenly become aware and attack. Anyone know of this method???

It seemed easy and simple at the time, like setting some bits, but I can't for the life of me think what it was or find it in the heards.

Offline Winter

  • I am Tek Jansen!
  • Administrator
  • *****
  • Posts: 476
  • MBX Forum owner
    • View Profile
    • Street of Eyes: The Writing of Ryan A. Span
Re: M&B Scripting Q&A
« Reply #182 on: July 02, 2007, 04:36:46 pm »
Ok, this is a crosspost. I read at some point of a way to disable troops so if you get within a certain distance (or any other arbitrary thing in a trigger) they suddenly become aware and attack. Anyone know of this method???

It seemed easy and simple at the time, like setting some bits, but I can't for the life of me think what it was or find it in the heards.

The easiest way is to send the AI troops to their spawn entry points and then clearing their scripted behaviour when the player gets within X distance.

Regards,
Winter

bryce

  • Guest
Re: M&B Scripting Q&A
« Reply #183 on: July 02, 2007, 10:10:03 pm »
Ok, this is a crosspost. I read at some point of a way to disable troops so if you get within a certain distance (or any other arbitrary thing in a trigger) they suddenly become aware and attack. Anyone know of this method???

It seemed easy and simple at the time, like setting some bits, but I can't for the life of me think what it was or find it in the heards.

The easiest way is to send the AI troops to their spawn entry points and then clearing their scripted behaviour when the player gets within X distance.

Regards,
Winter

Thanks, Winter. I see to have some problems.

I call a script like thus:

("hold_positions",[

(display_message, '_calling hold positions...._'),

(entry_point_get_position,3,20),


(try_for_agents,":current_agent"),

(agent_set_scripted_destination,":current_agent",3),


(try_end),

and nothing happens. Any idea?

Do I have to do anything with the mission template?



]),

Offline Winter

  • I am Tek Jansen!
  • Administrator
  • *****
  • Posts: 476
  • MBX Forum owner
    • View Profile
    • Street of Eyes: The Writing of Ryan A. Span
Re: M&B Scripting Q&A
« Reply #184 on: July 03, 2007, 12:43:08 pm »
Thanks, Winter. I see to have some problems.

I call a script like thus:

("hold_positions",[

(display_message, '_calling hold positions...._'),

(entry_point_get_position,3,20),


(try_for_agents,":current_agent"),

(agent_set_scripted_destination,":current_agent",3),


(try_end),

and nothing happens. Any idea?

Do I have to do anything with the mission template?

When exactly are you calling it?

bryce

  • Guest
Re: M&B Scripting Q&A
« Reply #185 on: July 03, 2007, 01:37:23 pm »
Thanks, Winter. I see to have some problems.

I call a script like thus:

("hold_positions",[

(display_message, '_calling hold positions...._'),

(entry_point_get_position,3,20),


(try_for_agents,":current_agent"),

(agent_set_scripted_destination,":current_agent",3),


(try_end),

and nothing happens. Any idea?

Do I have to do anything with the mission template?

When exactly are you calling it?

I call it on a trigger every .7 seconds from within the mission template. I know it gets called, but nothing seems to happen :(

Offline Winter

  • I am Tek Jansen!
  • Administrator
  • *****
  • Posts: 476
  • MBX Forum owner
    • View Profile
    • Street of Eyes: The Writing of Ryan A. Span
Re: M&B Scripting Q&A
« Reply #186 on: July 05, 2007, 01:44:43 pm »
I call it on a trigger every .7 seconds from within the mission template. I know it gets called, but nothing seems to happen :(

I'm assuming the problem is that everyone is standing still. That would happen if you're calling it in a mission template where no enemies are present. In order for any agent to move, it needs to have a hostile in the same scene. Arrange this in the mission template with a hostile visitor spawned at a position of your choosing, hidden and boxed in with barrier scene props.

It's possible to make particular NPCs move or stay still as you choose. Look at the Craftmod patrolling-NPCs mission template for an example of how it's done.

bryce

  • Guest
Re: M&B Scripting Q&A
« Reply #187 on: July 05, 2007, 02:09:22 pm »
I call it on a trigger every .7 seconds from within the mission template. I know it gets called, but nothing seems to happen :(

I'm assuming the problem is that everyone is standing still. That would happen if you're calling it in a mission template where no enemies are present. In order for any agent to move, it needs to have a hostile in the same scene. Arrange this in the mission template with a hostile visitor spawned at a position of your choosing, hidden and boxed in with barrier scene props.

It's possible to make particular NPCs move or stay still as you choose. Look at the Craftmod patrolling-NPCs mission template for an example of how it's done.

Maybe I will look in the source.

It's the enemies I am trying to get to move. Is that the problem?

Actually, none of my side will move either.

It seems I am doing everything right. I mean, it is pretty simple to do the basic case. So, I don't see how this can be happening.

Offline Ahadhran

  • Mysterious Old Man
  • Craftsman
  • **
  • Posts: 137
    • View Profile
Re: M&B Scripting Q&A
« Reply #188 on: July 06, 2007, 06:23:33 pm »
I am having a problem with a script I wrote which checks the player's and the opponents skill level in spotting and tactics when the battle choice menu comes up with the options to; charge, leave, surrender...ect. The difference is I am adding more options than just charge at default battle size. All the battle stuff works fine however, the problem is getting the right value for the skills of the enemy party. The script is below:
Quote
("get_tactical_status",
  [
  #find the enemies tactical abilities
   (store_encountered_party,":party"),
   (party_get_skill_level,":tactics",":party",9),
   (party_get_skill_level,":spotting",":party",7),

   (store_add,":enemy_tactic_advantage",":tactics",":spotting"),
   #error checking display
   (assign,reg0,":spotting"),
   (assign,reg1,":tactics"),
   (display_message,"str_enemy_spotting",0x3300ff),
   (display_message,"str_enemy_tactics",0x3300ff),
  #find players tactical abilities   
   (party_get_skill_level,":tactics","p_main_party",9),
   (party_get_skill_level,":spotting","p_main_party",7),
   (store_add,":player_tactic_advantage",":tactics",":spotting"),
    #error checking display
   (assign,reg2,":spotting"),
   (assign,reg3,":tactics"),
   (display_message,"str_player_spotting",0x3300ff),
   (display_message,"str_player_tactics",0x3300ff),
  #find the tactical advantage based on numbers
   (store_party_size_wo_prisoners,":enemy_party_size",":party"),
   (store_party_size_wo_prisoners,":player_party_size","p_main_party"),
   (store_sub,":party_difference",":player_party_size",":enemy_party_size"),
   (store_div,":tactical_size_mod",":party_difference",10),
   #error checking display
   (assign,reg4,":tactical_size_mod"),
   (display_message,"str_tactical_size_mod",0x3300ff),
  #calculate the players tactical status
   (store_sub,"$tactical_status",":player_tactic_advantage",":enemy_tactic_advantage"),
   (val_add,"$tactical_status",":tactical_size_mod"),
   #error checking display
   (assign,reg5,"$tactical_status"),
   (display_message,"str_tactical_status",0x3300ff),
  ]),

The code in red is whats not working. The enemy skill values always come up as 0 even when some of the members of the party being attacked have very high skill levels in spotting and tactics. All the code for the player part displays correctly. I'm guessing that I am miss using the operations in some small fundamental way.

Any help will be much appreciated.
Ahadhran

Offline Hellequin

  • Journeyman
  • ***
  • Posts: 254
    • View Profile
Re: M&B Scripting Q&A
« Reply #189 on: July 06, 2007, 07:39:01 pm »
Are the enemies with those skills marked trp_hero?  Regular troops don't contribute to the party's effective skill when they're on your own side... can't imagine it'd be otherwise on the other side, either.

You can manually loop through the party members of the other team and check their skills; the only 'virtue' of party_get_skill_level is that it incorporates the "companions' skills are reduced if too different from the player's" logic of 0.8x.  For stuff like this, you're better off just finding the actual highest skill.  Come to that, the "reduce skill if too distinct from player's skill" may have weird interactions if the player is not, in fact, even on their side.  That could be the reason, too.

Offline Ahadhran

  • Mysterious Old Man
  • Craftsman
  • **
  • Posts: 137
    • View Profile
Re: M&B Scripting Q&A
« Reply #190 on: July 07, 2007, 12:50:31 am »
ah ha, thats the problem then, I need hero captains for all the parties. Somewhat tedious way of keeping track of skills, but I suppose it can't be helped.

As to companions having the lowered effect, I think thats just nitpicking. Most of my differences for battles are in a range of three or more skill points so I think just ignoring that is the easiest route.

Offline Ahadhran

  • Mysterious Old Man
  • Craftsman
  • **
  • Posts: 137
    • View Profile
Re: M&B Scripting Q&A
« Reply #191 on: August 10, 2007, 03:45:44 pm »
I'm having a very weird issue with the math operations doing strange things. I didn't realize it till I starting displaying messages that told me the variable values.

Here is the chunk of code:

Quote
   (val_add,":current_spawn_sum","$peak_lost_souls"),
   (val_add,":current_spawn_sum","$peak_dark_wanderers"),
   (val_add,":current_spawn_sum","$peak_damned_hosts"),
   (val_add,":current_spawn_sum","$peak_slayer_border_guard"),
      (assign,reg0,"$peak_lost_souls"),
      (assign,reg1,"$peak_dark_wanderers"),
      (assign,reg2,"$peak_damned_hosts"),
      (assign,reg3,"$peak_slayer_border_guard"),
      (display_message,"str_variable_report",0xff0000),

   (val_add,":current_spawn_sum","$peak_blood_riders"),
   (val_add,":current_spawn_sum","$peak_slayer_host"),
   (val_add,":current_spawn_sum","$peak_rampagers"),
   (val_add,":current_spawn_sum","$peak_slayer_scouts"),
      (assign,reg0,"$peak_blood_riders"),
      (assign,reg1,"$peak_slayer_host"),
      (assign,reg2,"$peak_rampagers"),
      (assign,reg3,"$peak_slayer_scouts"),
      (display_message,"str_variable_report",0xff0000),

   (val_add,":current_spawn_sum","$peak_followers"),
      (assign,reg0,"$peak_followers"),
      (assign,reg1,":current_spawn_sum"),
      (assign,reg2,0),
      (assign,reg3,0),
      (display_message,"str_variable_report",0xff0000),

All the the spawn $peak variables show up correctly, but the sum ends up being wildly huge. All I'm trying to do is add all the $peak values up into one number in the variable ":current_spawn_sum". One time it came out as 427, the next as 63697506 (it should come to 34)  :shock: By the way, I do zero it out after running through the script, even though I shouldn't need to since its a local variable...

Please help before I go insane  :lol:

Offline fujiwara

  • Master
  • *****
  • Posts: 858
    • View Profile
Re: M&B Scripting Q&A
« Reply #192 on: August 10, 2007, 04:20:25 pm »
At first glance I don't see an issue here. I assume all the $peak variables are constants that don't change? Maybe seeing the whole operations block might help.

The horses tend to get their legs caught in the catapult rather than being properly launched.

Offline Ahadhran

  • Mysterious Old Man
  • Craftsman
  • **
  • Posts: 137
    • View Profile
Re: M&B Scripting Q&A
« Reply #193 on: August 10, 2007, 04:58:48 pm »
I fixed the problem by zeroing ":current_spawn_sum" right before the operation, rather than after. It appears the variable was getting filled with something in the interim between script runs even though nothing I have written does so.

Is it possible that I have gone over the limit on local variables such that the memory space for this one is overlapping with another? This doesn't make sense to me though since the whole idea behind local variables is that they don't exist outside the operations block.

As to the $peak values, they didn't change during my test runs...

Here is the whole script with the display message parts removed:

Quote
("army_base_enable_calc",
  [
  (try_begin),
   (eq,"$player_is_good",0),
   (display_message,"str_false",0xff0000),
   (assign,":current_spawn_sum",0),
   (val_add,":current_spawn_sum","$peak_alliance_foragers"),
   (val_add,":current_spawn_sum","$peak_alliance_scouts"),
   (val_add,":current_spawn_sum","$peak_alliance_harassers"),
   (val_add,":current_spawn_sum","$peak_alliance_war_parties"),
   #(val_add,":current_spawn_sum" for when more rangers are added
   #(val_add,":current_spawn_sum" for when more guardians are added
   (val_mul,":current_spawn_sum",100),
   (store_div,":percent_enable_chance",":current_spawn_sum",sum_alliance_spawn_forces),
   (store_random_in_range,":random_num",1,101),
   (try_begin),
      (le,":random_num",":percent_enable_chance"), #chance that a party will be enabled as scheduled"
      (assign,"$enable_base_ready",1),
   (try_end),
  (else_try),
   (eq,"$player_is_good",1),
   (assign,":current_spawn_sum",0),
   (val_add,":current_spawn_sum","$peak_lost_souls"),
   (val_add,":current_spawn_sum","$peak_dark_wanderers"),
   (val_add,":current_spawn_sum","$peak_damned_hosts"),
   (val_add,":current_spawn_sum","$peak_slayer_border_guard"),
   (val_add,":current_spawn_sum","$peak_blood_riders"),
   (val_add,":current_spawn_sum","$peak_slayer_host"),
   (val_add,":current_spawn_sum","$peak_rampagers"),
   (val_add,":current_spawn_sum","$peak_slayer_scouts"),
   (val_add,":current_spawn_sum","$peak_followers"),
   (val_mul,":current_spawn_sum",100),
   (store_div,":percent_enable_chance",":current_spawn_sum",sum_damned_spawn_forces),
   (store_random_in_range,":random_num",1,101),
   (try_begin),
      (le,":random_num",":percent_enable_chance"), #chance that a party will be enabled as scheduled
      (assign,"$enable_base_ready",1),
   (try_end),
  (try_end),
  ]),

Basically the script takes the current number of parties allowed to spawn for a faction and divides by what it would be at its strongest point (sum_xxxxxx_spawn_forces) in order to determine the % strength of the faction. This is then compared against the random number, if the faction is at full strength, its military expansion will continue unabated but as it loses (the $peak #s go down) it becomes less likely to expand its army bases.

The idea is to have the $peak numbers go down as result of completing quests.

Just for further info, here are the triggers that run the script and determines when it is run.

Quote
#Expansion of NPC army bases
(3,0,1.0,[
   (ge,"$darmy_base_counter","$darmy_base_wait"),
   (ge,"$aarmy_base_counter","$aarmy_base_wait"),
   ],
   [
   (call_script,"script_army_base_enable_calc"),
   (try_begin),
      (eq,"$player_is_good",1),
      (eq,"$enable_base_ready",1),
      (call_script,"script_choose_army_base_damned"),
   (else_try),
      (eq,"$player_is_good",0),
      (eq,"$enable_base_ready",1),
      (call_script,"script_choose_army_base_alliance"),
   (try_end),
   (assign,"$darmy_base_counter",0),
   (assign,"$aarmy_base_counter",0),
   (assign,"$enable_base_ready",0),

Quote
#counter trigger
(1,0,1.0,[],
[
(val_add,"$darmy_base_counter",1),
(val_add,"$aarmy_base_counter",1),
]),

Offline fujiwara

  • Master
  • *****
  • Posts: 858
    • View Profile
Re: M&B Scripting Q&A
« Reply #194 on: August 11, 2007, 12:04:51 pm »
I find it's good programming practice to zero variables before using them, since I'm not certain whether or not MBScript does any initialization beforehand.

As far as memory goes, I would think not. I would be surprised if that were the case, given the amounts of memory available on modern boxen.

The horses tend to get their legs caught in the catapult rather than being properly launched.