Script working the second time I enter a map.

Sirren67

Look, Ma! Two Heads!
Sorry to bother you so soon but I have a problem with more than one scripts: they work, but only the second time I enter a map; they are supposed to work the * first * time. This is an exemple:

#include "..\headers\define.h"
#include "..\headers\florenc.h"
#include "..\headers\floffice.h"

#define NAME SCRIPT_FCJASON

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


procedure start;
procedure timed_event_p_proc;
procedure critter_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;

#define LVAR_Herebefore (4)
#define LVAR_Hostile (5)
#define LVAR_Personal_Enemy (6)

variable Only_Once:=0;
variable talkCount := 0;

#define TIMER_FLOAT 1

procedure start begin
end

procedure timed_event_p_proc begin
if (is_loading_game == false) then begin
if (local_var(LVAR_Herebefore) == 1) then begin
destroy_object(self_obj);
end
end
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(102));
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_POSEIDON_OIL);
critter_add_trait(self_obj,TRAIT_OBJECT,OBJECT_AI_PACKET,AI_LONER_CITIZEN);

end

procedure map_update_p_proc begin
end

procedure talk_p_proc begin
talkCount := 90;
end

procedure critter_p_proc begin

if (tile_num(self_obj) != 33506) then begin
animate_move_to_tile(33506);
if (game_time > talkCount) then begin
float_msg(self_obj, mstr(103 + Random(0, 4)), FLOAT_MSG_BLACK);
talkCount := game_time + (ONE_GAME_SECOND * 2);
end
end
if (tile_num(self_obj) == 33506) then begin
set_local_var(LVAR_Herebefore,1);
end

end

The related critter walks from point A to point B, where he "leaves" the map. I tested the script in-game: the first time I leave the map and reenter it I find that my critter is leaving the map again, while from the second time on I find no trace of the critter (as it should be). The map has two outdoors areas and I have to cross the "middle" area to actully leave the map: is this related in any way? I have the same problem with a script which creates a weapon in a guard's inventory: first time I run the map scripts does not work, the second time the guard has the weapon in his hand (same map). Is this related to map vars/script?
 
The problem is you put code that should destroy critter in timed_event_p_proc but this procedure is never called in your script. You need to use add_timer_event function to call this proc.
But you can destroy this object in very simple way.
Just place all code from timed_event_p_proc into map_enter_p_proc.
So the code will look like this:

Code:
procedure start; 
procedure timed_event_p_proc; 
procedure critter_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; 

#define LVAR_Herebefore (4) 
#define LVAR_Hostile (5) 
#define LVAR_Personal_Enemy (6) 

variable Only_Once:=0; 
variable talkCount := 0; 

#define TIMER_FLOAT 1 

procedure start begin 
end 

procedure timed_event_p_proc begin 

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(102)); 
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_POSEIDON_OIL); 
critter_add_trait(self_obj,TRAIT_OBJECT,OBJECT_AI_PACKET,AI_LONER_CITIZEN); 

if (is_loading_game == false) then begin 
if (local_var(LVAR_Herebefore) == 1) then begin 
destroy_object(self_obj); 
end 
end 

end 

procedure map_update_p_proc begin 
end 

procedure talk_p_proc begin 
talkCount := 90; 
end 

procedure critter_p_proc begin 

if (tile_num(self_obj) != 33506) then 
begin 
animate_move_to_tile(33506); 
if (game_time > talkCount) then 
begin 
float_msg(self_obj, mstr(103 + Random(0, 4)), FLOAT_MSG_BLACK); 
talkCount := game_time + (ONE_GAME_SECOND * 2); 
end 
end 
if (tile_num(self_obj) == 33506) then 
begin 
set_local_var(LVAR_Herebefore,1); 
end 

end

My english is too bad to write a guide for you how to use timed events, but I em sure dude_obj will do that ;), he is very good in that sort of things.
 
jargo said:
My english is too bad to write a guide for you how to use timed events, but I em sure dude_obj will do that ;)

Eventually yes, a scripting guide is in the plans, but for now the FAQ and new Topic Index will have to suffice. I wrote a program last weekend that generates the Topic Index. Had to look at every one of those threads and categorize them though (they are now in a database). There are a few topics related to timed events:

http://modguide.nma-fallout.com/#Scripting021
http://www.nma-fallout.com/forum/viewtopic.php?t=10854
http://www.nma-fallout.com/forum/viewtopic.php?t=9266
 
To Jargo: Thanks! I had the feeling it was something simple about script "architecture/project" , but I fought a couple of hours before deciding to give in.

To Dude_Object: I got more than one look to the Topic Index and I understood it's the result of a huge work. It was about time someone put the stuff in order, it's much easier to find information now.
Anyway I join Jargo's... uhm, invitation about a script tutorial. I really do not know if this is the correct way to phrase this, but something about "how you correctly project a script" would be extremely useful.

Thanks to you both and goodnight.
 
Sirren67 said:
I got more than one look to the Topic Index and I understood it's the result of a huge work.

Not as much as it would seem, I used fancy code like this:

URLConnection url = (new URL(ForumURL)).openConnection();
if (url instanceof HttpURLConnection) {readHttpURL((HttpURLConnection) url);}

To walk through the whole archive, grab all the info, and toss it into a database. Other fancy code to generate the page. It was a bit of work to classify the posts manually, each was assigned two meta tags. But the code did most of the hard work ;-)
 
I've bookmarked this scripting tut as well as the same guy's Dialogue tutorial. It's unfortunate that it's not step-by-step, as I learn better that way, but I understand the whole "teach a man to fish" idea.
 
Not as much as it would seem, I used fancy code like this:

URLConnection url = (new URL(ForumURL)).openConnection();
if (url instanceof HttpURLConnection) {readHttpURL((HttpURLConnection) url);}

To walk through the whole archive, grab all the info, and toss it into a database. Other fancy code to generate the page. It was a bit of work to classify the posts manually, each was assigned two meta tags. But the code did most of the hard work

What would we do without a little automatization ;).
Still it was a great idea and a lot of work, good job.

Anyway I join Jargo's... uhm, invitation about a script tutorial. I really do not know if this is the correct way to phrase this, but something about "how you correctly project a script" would be extremely useful.

Well to tell the truth from about a year now i systematically write small tutorials for basic scripting in Fallout 2.
They are all on FMC but the only problem is they are in Polish so i need to get some good translator for that work.

This are the topics so far:

Basic script structure
First script
Operators and flow control... (IF Then Else etc)
All about Procedure
All about vars
What can be done with items
Spatial scripts (By Kulawy_Sam)
Writing dialogues(Daniel Sjoblom - http://koti.mbnet.fi/dsjoblom/Dialogue.html)
Writing quests
Using Imported variables
How to use Macro's

That's all
I plan to write two more: Timed events and Animations.
 
Jargo I know about your tutorials, they are something I'm drooling upon...
When I started learning English I had the crazy idea to get a dictionary and translate a small text I was interested in, word by word...
A real pain in the neck, if you ask me. I really hope you'll be able to find a translator, or my last resort involves getting a Polish/Italian dictionary (I find automatic translators are not reliable at all, my sister tried one with NMA homepage and the result was relly senseless).

EDIT I hope someone will see this one...)

Jargo, flush_add_timer_event did not work, but I don't know if this is due to fcjason script. Apparently when the PC gets from layer 0 (starting area) to layer 2 of the same map (another outdoor area)
the whole map behaves just like it is entered AGAIN for the first time. I also get the starting message you see in the massage window when you enter a town for the first time. This happens both in the mapper and the game.
Map script is as follows:

#include "..\headers\define.h"
#include "..\headers\floffice.h"
#include "..\headers\updatmap.h"

#define NAME SCRIPT_FLOFFICE

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

procedure start;
procedure map_enter_p_proc;
procedure map_update_p_proc;

procedure start begin
end

procedure map_enter_p_proc begin
override_map_start_hex( 25511, 0, 0 );

if (map_first_run) then begin
display_msg(mstr(100));
end

if (elevation(dude_obj) == 1) then begin
Full_Light;
end
else begin
Lighting;
end

set_global_var(GVAR_LOAD_MAP_INDEX,0);
end

procedure map_update_p_proc begin
if (elevation(dude_obj) == 1) then begin
Full_Light;
end
else begin
Lighting;
end
end

Its pretty standard as one of my map scripts for now, but it is the only one that behave strangely. Any leads?
 
Sorry for the double post but I edited my last one yesterday and no one noticed.
The FCJASON script trouble is indeed caused by the map being loaded TWICE for "the first time". I split the map in two so it only contains a single outdoor area, still for the game I have to enter it twice to get the script var to work. I also think the problem is not due to the map script, damn apparently it is due to nothing...
Did this happen to somebody else?
 
Jargo, flush_add_timer_event did not work, but I don't know if this is due to fcjason script
Ok here is a sample how to use simple timed events:

Make new script and put there talk_p_proc
Code:
procedure talk_p_proc 
begin 
add_timer_event(self_obj,game_ticks(2),1);
add_timer_event(self_obj,game_ticks(5),2);
add_timer_event(self_obj,game_ticks(10),3);
end

And then add timed_event_p_proc

Code:
procedure timed_event_p_proc 
begin 
if fixed_param == 1 then
float_msg(Self_obj,"timed event 2 seconds",FLOAT_MSG_NORMAL);
if fixed_param == 2 then
float_msg(Self_obj,"timed event 5 seconds",FLOAT_MSG_GREEN);
if fixed_param == 3 then
float_msg(Self_obj,"timed event 10 seconds",FLOAT_MSG_RED);
end

Here you have syntax of add_timer_event :
add_timer_event(object_pointer,time,fixed_param);

object_pointer - Object that has a script with timed_event_p_proc to call.

time - Time of delay in ticks, best use game_ticks function that convert from seconds to ticks.

fixed_param - sets up fixed_param value, you can read it in timed_event_p_proc.

BTW Syntax of flush_add_timer_event is the same but it first clears prior timed events with same fixed_param.

the whole map behaves just like it is entered AGAIN for the first time. I also get the starting message you see in the massage window when you enter a town for the first time. This happens both in the mapper and the game.

Hmm that is normal in mapper( F8 ) but not in game, i have no clue.
 
O.K., I’m trying your latest info about timer_event in my next scripts. By the way, there are some of your tutorials I’m really interested in (vars handling and importing, and the quest tutorials): next week I’m getting a Polish/Italian dictionary. If I manage to get something which makes sense I’ll test them and send you the English versions.
As far as the map trouble is concerned I browsed the forum and only found this: if you have unofficial patches installed (1.3, 1.4(the one I have), 1.5) something similar happens with Den Business 1 map. You enter the map twice for the first time, and after you enter Den B.1 and Den B. 2 for a bunch of times then the game freezes and you are sent back to the desktop (something that does not happen with my map). For now I just added a smaller area to the starting map thus sidestepping the problem, but I’m still adding/re-organizing maps…If I knew for sure that a clean, fresh install can solve the problem I’d do so.
 
Back
Top