Scripting combat

taag

Still Mildly Glowing
How do you script combat in an existing area? I would like to do something similar to what occurs when Modoc fights Ghost Farm.

Particularly, I'm interested in seeing how those NPCs appeared out of nowhere and "knew" whom to attack.
 
I am not quite certain, but mostly you handle the attacking via teams.
I'll have a look and post if I find anything specific.

As for them appearing 'out of nowhere', this is simply handled over the set_obj_visibility command. Be aware, that this command expects a '0' to turn a critter visible and a '1' vice versa. Kinda weird.
I know that this is used for Laras Gang at the den westside. They already are there as protos with their scripts attached in the map, but turn invisible and remain so as long as the 'gangwar' is not started.

The other possibility is, wich expect to be it in modoc vs ghost farm, to tell a critter that he shall be created at a given map, under given circumstances. But I have to admit, that that never worked for me so far, except when meddling with existing party-members. I always had to do it as above.
 
Well, who would have thought that, the creation code seems to not work just for me. Had a look at the ghost farm, and everyone's there. Balthas, Jo, e.t.c. just standing in the middle of the way between farmhouse and mapexit.
The slags guards start behind the farmhouse and the workers inside it.
Okay, as for the battle, this can take a while. Their teams seem to be given out through their scrits, as in the mapper they are all team 1.

I post again, if I checked it out.
 
Okay, it all starts with a check for the map they are at, in the map_enter_p_proc...

Code:
         if (cur_map_index != MAP_GHOST_FARM) then begin
            critter_add_trait(self_obj,TRAIT_OBJECT,OBJECT_TEAM_NUM,TEAM_MODOC);
         end

... where they are assigned to modoc-team (28) if they are NOT at the ghost farm.

Then, in combat_p_proc ...

Code:
   end else if (cur_map_index == MAP_GHOST_FARM) then begin
      critter_add_trait(self_obj,TRAIT_OBJECT,OBJECT_TEAM_NUM,TEAM_PLAYER);

... they are reassigned to the player-team(0).

The fight is initialized in critter_p_proc...

Code:
   if ((cur_map_index == MAP_GHOST_FARM) and (hostile == false) and (dude_enemy_modoc == false)) then begin
      Do_Attacking_Slag(10,7)

...where Do_Attacking_Slag(x,y) is a macro defined in modoc.h...

Code:
#define Do_Attacking_Slag(x,y)
   if (obj_is_visible_flag(self_obj)) then begin
      if (obj_can_see_obj(self_obj, ghost_farm_slag_obj)) then begin
         attack(ghost_farm_slag_obj);
         end else begin
            Follow_Dude(x,y)
         end
      end

... in which ghost_farm_slag_obj seems to be a pointer to some export variable from ghost farm map script, assigned to all slags as it appears.

And finally 'check_show_ghost_farm_attackers', another macro from modoc.h takes care of their appearance...

Code:
#define check_show_ghost_farm_attackers
   if (is_loading_game == false) then begin
      if (obj_in_party(self_obj) == false) then begin
         if (cur_map_index == MAP_GHOST_FARM) then begin
            if (all_slags_dead) then begin
               debug_msg("no need for attackers");
               check_set_obj_visiblility(self_obj, true);
               destroy_object(self_obj);
            end else if (attacking_slags) then begin
               debug_msg("showing need for attackers");
               critter_add_trait(self_obj,TRAIT_OBJECT,OBJECT_TEAM_NUM,TEAM_PLAYER);
               check_set_obj_visiblility(self_obj, false);
            end else begin
               debug_msg("hiding need for attackers");
               check_set_obj_visiblility(self_obj, true);
            end
         end
      end
   end

This looks like a load at first, but is real easy. It first checks if the object is in players party. next it checks (once again) if the object is in ghost farm. Next, if there are any slags to beat. If not, it displays a msg in debug mode and makes them disappear. If yes, it also displays a debug msg, adds them to the player team and turns them visible. In any other case it shows the notorious msg and turns them invisible.

Is that, what you were particularly interested in?

Edit: yeah, I forgot one: the very first thing, the check_ghost_....blahblah macro does is, what every macro does, it checks if the game loads, as it'll do nothing, if.
 
Well, truely beats me, but 'ghost_farm_slag_obj' seems to appear nowhere else then in modoc.h, but there only inside the macro 'Do_Attacking_Slag(x,y)' wich I posted earlier. Strange, how would they know who's a slag?

I'll check out them slag scripts and post again.
 
Ahright, checked their scripts and see, there's a define...

Code:
#define export_slag_ptr
   if (ghost_farm_slag_obj == 0)
      then ghost_farm_slag_obj := self_obj;
   else if (tile_distance_objs(self_obj, dude_obj) < tile_distance_objs(ghost_farm_slag_obj, dude_obj))
      then ghost_farm_slag_obj := self_obj

... this simply passes himself as 'ghost_farm_slag_obj' to all, who share their header.
So I was right about my thinking, of it being a pointer halfway at least. But I never had it expected to be done in the script instead of in the header.

But why I didn't get it at first is that the slags also share modoc.h.

Well, I hope that clears all things up, Alex.
 
Please do not double post. Please do not triple post. Please do not quadruple post. Please do not quintuple post.

In fact, if you have to add something to what you posted earlier, please use the EDIT button. It's there for a reason.

All of your posts were within several minutes of each other, so there's really no reason to multi-post.

The only valid scenario for multi-posting would be if several weeks/months have elapsed with nobody else posting in between. In almost all other cases it's a better idea to EDIT your previous post and APPEND your new post.
 
Back
Top