Wandering critters and "undead" ones.

Sirren67

Look, Ma! Two Heads!
A): I managed to get my critters to wander randomly (I am using the code that Dude_Object put in his F.A.Q.), but there's a thing I'd like to know: is there a way to keep the critter within a given radius from the original "hometile"? I noticed that my critters tend to wander across my whole maps.
B): If I kill one of my critters, change map via green exit grids and then come back I always find that my critter is alive again. I tried both original and new critter protos and they all had scripts I made.
If I put in my maps a critter with a original script and then kill it then it simply disappears when I enter the map again. Is this related to vars? I opened many map headers, but found nothing.
What's wrong?
 
Sirren67 said:
is there a way to keep the critter within a given radius from the original "hometile"?

On map enter save the home tile:
procedure map_enter_p_proc begin
starttile := self_tile;

Then in your random wandering calculate the distance from starttile, and if it exceeds your desired threshold, move critter in direction of home tile rather than just any random direction.

if (tile_distance(tile_num(self_obj), starttile) > 15) then
animate_move_to_tile(tile_num_in_direction(starttile, Random(0, 5), Random(3, 10)));
else // do your normal random wandering

Sirren67 said:
B)critter is alive again

Are these critters manually placed on the map or are they spawned with create_object_sid?
Can you paste one of your scripts that does this in here?
 
If I kill one of my critters, change map via green exit grids and then come back I always find that my critter is alive again. I tried both original and new critter protos and they all had scripts I made.
If I put in my maps a critter with a original script and then kill it then it simply disappears when I enter the map again. Is this related to vars? I opened many map headers, but found nothing.
What's wrong?

If you using mapper then it does not save map state when exiting (like in normall game) so when you go out and back then all critters will be there alive even if you killed them before in game all should be ok.
 
To Dude_Object: Thanks for the Home Tile bit.
My critters are still placed manually, but I am going to try the create_oject_sid command in a later stage. I hope Jargo is right, but here is one of my scripts: not a fine one but it works.

/* Include Files */
#include "..\headers\define.h"
#include "..\headers\florence.h"

#define NAME SCRIPT_FCTOWNA
#define TOWN_REP_VAR (GVAR_TOWN_REP_FLORENCE)

#include "..\headers\command.h"
#include "..\headers\ModReact.h"

/* Standard Script Procedures */
procedure start;
procedure timed_event_p_proc;
procedure pickup_p_proc;
procedure destroy_p_proc;
procedure push_p_proc;
procedure use_p_proc;
procedure look_at_p_proc;
procedure description_p_proc;
procedure use_skill_on_p_proc;
procedure use_obj_on_p_proc;
procedure damage_p_proc;
procedure map_enter_p_proc;
procedure map_update_p_proc;
procedure talk_p_proc;

/* Script Specific Procedure Calls */
procedure Node998; // This Node is Always Combat
procedure Node999; // This Node is Always Ending

procedure Node001;
procedure Node002;

#define LVAR_Herebefore (4)
#define LVAR_Hostile (5)
#define LVAR_Personal_Enemy (6)
#define LVAR_State (7)
#define LVAR_HomeTile (8)

variable Only_Once:=0;

#define TIMER_MOVE 1
#define TIMER_FLOAT 2


procedure start begin
end

procedure timed_event_p_proc begin
if (((critter_state(self_obj) bwand DAM_KNOCKED_DOWN) == FALSE)
and (not(combat_is_initialized))) then begin
reg_anim_clear(self_obj);
reg_anim_begin();
animate_move_to_tile(tile_num_in_direction(tile_num(self_obj),random(0,5),3));
reg_anim_end();
end
add_timer_event(self_obj,game_ticks(random(5,7)),1);

/*variable tile;
variable hello;

if (fixed_param == TIMER_MOVE) then begin
if (self_visible) then begin
tile := tile_num_in_direction(local_var(LVAR_HomeTile), Random(0, 5), Random(5, 7));
if (not anim_busy(self_obj)) then begin
reg_anim_clear(self_obj);
reg_anim_begin();
animate_move_to_tile(tile);
reg_anim_end();
end
end else begin
tile := tile_num_in_direction(local_var(LVAR_HomeTile), Random(0, 5), Random(5, 7));
if (not anim_busy(self_obj)) then begin
reg_anim_clear(self_obj);
reg_anim_begin();
animate_move_to_tile(tile);
reg_anim_end();
end
end
add_timer_event(self_obj, ONE_GAME_SECOND * Random(5, 10), TIMER_MOVE);
end else if (fixed_param == TIMER_FLOAT) then begin*/
if (self_visible) then begin
call Node002 ;
end
end
/*add_timer_event(self_obj, ONE_GAME_SECOND * Random(5, 10), TIMER_FLOAT);
end

procedure use_p_proc begin
end


procedure look_at_p_proc begin
script_overrides;
if (local_var(LVAR_Herebefore) == 0) then
display_msg(mstr(100));
else
display_msg(mstr(101));
end


procedure description_p_proc begin
script_overrides;
display_msg(mstr(114));
end



procedure use_skill_on_p_proc begin
end


procedure use_obj_on_p_proc begin
end



procedure damage_p_proc begin
end


procedure map_enter_p_proc begin
Only_Once:=0;
critter_add_trait(self_obj,TRAIT_OBJECT,OBJECT_TEAM_NUM,TEAM_FLORENCE);
critter_add_trait(self_obj,TRAIT_OBJECT,OBJECT_AI_PACKET,AI_TOUGH_CITIZEN);
if (not is_loading_game) then begin
if (not local_var(LVAR_HomeTile)) then begin
set_local_var(LVAR_HomeTile, self_tile);
end
add_timer_event(self_obj, ONE_GAME_SECOND * Random(5, 10), TIMER_MOVE);
/*add_timer_event(self_obj, ONE_GAME_SECOND * Random(5, 10), TIMER_FLOAT);*/
end
end

procedure map_update_p_proc begin
end

procedure talk_p_proc begin
call Node001;
end

procedure push_p_proc begin

end

procedure destroy_p_proc begin

/* Increment the aligned critter counter*/
inc_good_critter
/* Set global_variable for Enemy status*/

end

procedure pickup_p_proc begin
if (source_obj == dude_obj) then begin
set_local_var(LVAR_Hostile,2);
end

end

procedure Node998 begin
set_local_var(LVAR_Hostile,2);
end

procedure Node999 begin
end

procedure Node001 begin
float_msg(self_obj, mstr(102 + Random(0, 4)), FLOAT_MSG_BLUE);
end

procedure Node002 begin
float_msg(self_obj, mstr(107 + Random(0, 6)), FLOAT_MSG_RED);
end


To Jargo: Thanks for the info, I hope this is the final solution for the problem.

Bye
 
Sirren67 said:
I hope Jargo is right

Yes, he pointed out the obvious when I didn't see the forest through the trees :lol: Every time you press F8 (game mode) or reload your map in the mapper, it starts as new. You can open one of the originals and play, but no state is saved unless you actually save the map.

For an in-game test, you can save your map as artemple.map and run the actual game. But don't forget to make your protos read-only or they will be deleted.
 
It took sometime to me to properly define starttile (VARIABLE starttile := 0; for those who need this) but now it's working: woohoo!
 
Back
Top