Random Quest

Lich

Water Chip? Been There, Done That
Its my new scripting research
NPC will give you one randomly selected quest
Result: game will be never twice the same


Global.h
Code:
#define GVAR_QUEST1     (699)
#define GVAR_QUEST2     (700)
#define GVAR_QUEST3     (701)

Vault13.gam
Code:
GVAR_QUEST1   :=0;   //   (699)
GVAR_QUEST2   :=0;   //   (700)
GVAR_QUEST3   :=0;   //   (701)

Quests.txt
Code:
# 1A Bring knife
1500, 141, 699, 1, 2

# 1B Bring leather armour
1500, 142, 700, 1, 2

# 1C Bring hunting riffle
1500, 143, 701, 1, 2

Quests.msg
Code:
{141}{}{Bring knife person X}
{142}{}{Bring leather armour person X}
{143}{}{Bring hunting riffle person X}


Dialogue script from NPC who will give you the quest

Code:
procedure start;
procedure talk_p_proc;
procedure Node999;
procedure Node001;
procedure Node002;
procedure Node003;
procedure Node004;
procedure Node005;
procedure Node006;
procedure Node007;
procedure Node008;

procedure start begin
end

procedure talk_p_proc begin 
start_gdialog(NAME,self_obj,4,-1,-1);
gSay_Start; 
if (global_var(GVAR_QUEST1) == 1) then begin
call Node002; 
end else
if (global_var(GVAR_QUEST2) == 1) then begin
call Node004;
end else 
if (global_var(GVAR_QUEST3) == 1) then begin
call Node006; 
end else 
if ((global_var(GVAR_QUEST1) == 2) or (global_var(GVAR_QUEST2) == 2) or (global_var(GVAR_QUEST3) == 2)) then begin
call Node008; 
end else begin
call Node001; 
end
gSay_End; 
end_dialogue; 
end

procedure Node001 begin 
variable los;
los := random(1,3);
if (los == 1) then begin
Reply(122);
set_global_var(GVAR_QUEST1,1);
NOption(101,Node999,003); 
end else
if (los == 2) then begin
Reply(123);
set_global_var(GVAR_QUEST2,1);
NOption(101,Node999,003); 
end else
if (los == 3) then begin
Reply(124);
set_global_var(GVAR_QUEST3,1);
NOption(101,Node999,003); 
end else begin
Reply(125);
NOption(126,Node999,003);
end
end

procedure Node002 begin
if (obj_is_carrying_obj_pid(dude_obj, 4) >=1) then begin
Reply(102); 
NOption(103,Node003,003); 
end else begin
Reply(104); 
NOption(105,Node999,003); 
end
end

procedure Node003 begin 
Reply(106); 
remove_pid_qty(dude_obj, 4, 1) 
item_caps_adjust(dude_obj,150);
give_exp_points(100);
set_global_var(GVAR_QUEST1,2);
NOption(107,Node999,003); 
end 

procedure Node004 begin
if (obj_is_carrying_obj_pid(dude_obj, 1) >=1) then begin
Reply(108); 
NOption(109,Node005,003); 
end else begin
Reply(110); 
NOption(111,Node999,003); 
end
end

procedure Node005 begin
Reply(112); 
remove_pid_qty(dude_obj, 1, 1) 
item_caps_adjust(dude_obj,300);
give_exp_points(200);
set_global_var(GVAR_QUEST2,2);
NOption(113,Node999,003); 
end 

procedure Node006 begin
if (obj_is_carrying_obj_pid(dude_obj, 10) >=1) then begin
Reply(114); 
NOption(115,Node007,003); 
end else begin
Reply(116); 
NOption(117,Node999,003); 
end
end

procedure Node007 begin
Reply(118); 
remove_pid_qty(dude_obj, 10, 1) 
item_caps_adjust(dude_obj,200);
give_exp_points(400);
set_global_var(GVAR_QUEST3,2);
NOption(119,Node999,003); 
end 

procedure Node008 begin
Reply(120); 
NOption(121,Node999,003); 
end 

procedure Node999 begin
end


And example content file.msg of that dialogue

Code:
{100}{}{do something for me, bring me knife}
{101}{}{ok i will do it}
{102}{}{i see you got knife i searching}
{103}{}{yes, find it was easy}
{104}{}{do you find that knife?}
{105}{}{no i working on that}
{106}{}{here is you reward}
{107}{}{thanx}
{108}{}{i see you got armour, how you do it?}
{109}{}{i got some problems but i found it}
{110}{}{did you find that armour?}
{111}{}{no but i made some progress on that}
{112}{}{gratulations, here is your reward}
{113}{}{thanx}
{114}{}{incredible, you found that riffle!}
{115}{}{yes, but this was hard}
{116}{}{did you found that riffle?}
{117}{}{uh its hard, but i try do it}
{118}{}{gratulations, here is you big reward}
{119}{}{wow, thanx, many money}
{120}{}{thanx again for this item}
{121}{}{it was interesting adventure}
{122}{}{here is your quest, bring me knife}
{123}{}{here is your quest, bring me leather armour}
{124}{}{here is your quest, bring me hunting riffle}
{125}{}{nothing1}
{126}{}{nothing2}
 
Code:
procedure Node001 begin 
variable los; 
 los := random(1,3); 
 Reply(121+los); 
 set_global_var(GVAR_QUEST1-1+los,1); 
 NOption(101,Node999,003); 
end

procedure talk_p_proc begin
variable node_x;
 start_gdialog(NAME,self_obj,4,-1,-1); 
 gSay_Start; 

 if (global_var(GVAR_QUEST1) == 1) then node_x:="Node002";
 else if (global_var(GVAR_QUEST2) == 1) then node_x:="Node004";
 else if (global_var(GVAR_QUEST3) == 1) then node_x:="Node006";
 else if ((global_var(GVAR_QUEST1) == 2) or (global_var(GVAR_QUEST2) == 2) or (global_var(GVAR_QUEST3) == 2)) then node_x:="Node008";
 else node_x:="Node001";

 call node_x; 

 gSay_End; 
 end_dialogue; 
end

More readable and compact variant :)
 
>>Error
Are you sure? :)

#define GVAR_QUEST1 699

before preprocessor:
set_global_var(GVAR_QUEST1-1+los,1);

after preprocessor:
set_global_var(699-1+los,1);

Where is error?
 
Missunderstanding i thinking you count something else, but right GVAR is just name of defined number.
Now i can say its brilliant.

I olways write simple code to made many and quick modiffy (experiments)

EDIT

Anyway, perfect code should look like that heh:

Code:
procedure talk_p_proc begin 
variable x;
variable y;
variable z;
x := global_var(699);
y := global_var(700);
z := global_var(701);

start_gdialog(NAME,self_obj,4,-1,-1);
gSay_Start; 
if (x == 1) then begin
call Node002; 
end else
if (y == 1) then begin
call Node004;
end else 
if (z == 1) then begin
call Node006; 
end else 
if (x or y or z == 2) 
 then begin
call Node008; 
end else begin
call Node001; 
end
gSay_End; 
end_dialogue; 
end
 
Maybe this variant better? :) No comments needed :)

Code:
#define quest1_given global_var(699)==1
#define quest2_given global_var(700)==1
#define quest3_given global_var(701)==1
#define complete_quest (global_var(699)==2 or global_var(700)==2 or global_var(701)==2)

procedure talk_p_proc begin
 variable node_x;
  start_gdialog(NAME,self_obj,4,-1,-1); 
  gSay_Start; 

   if quest1_given then node_x:="Node002";
   else if quest2_given then node_x:="Node004";
   else if quest3_given then node_x:="Node006";
   else if quest_complete then node_x:="Node008";
   else node_x:="Node001";

   call node_x;

  gSay_End; 
  end_dialogue;  
end
 
Yes, in this version script is more readable. But in all versions finall results is the same: NPC will give you one from three quest. And possibility to take all quests is 33%. Lets stop this pointless discussion and invent something new:

NPC will give you three quests but possibilities are:
1-50%
2-30%
3-20%
 
part of code

Code:
#define var_in(x, y, z)     ((x>=y) and (x<=z))

variable tmp_var;
variable los;
 tmp_var:=random(1, 10);
 if var_in(tmp_var, 1, 5) then los:=1;
 else if var_in(tmp_var, 6, 8) then los:=2;
 else if var_in(tmp_var, 9, 10) then los:=3;
 
Great! but ofcourse i go different way to solve this. TRIPLE_ROLL
Variables a,b,c got chances 50,30,20 winner begin action


Code:
procedure Node001 begin 
variable a;
variable b;
variable c;
a := random(1,50);
b := random(1,30);
c := random(1,20);
if (a>=b and a>c) then begin 
Reply(122); 
set_global_var(GVAR_QUEST1,1); 
NOption(101,Node999,003); 
end else 
if (b>a and b>=c) then begin 
Reply(123); 
set_global_var(GVAR_QUEST2,1); 
NOption(101,Node999,003); 
end else 
if (c>=a and c>b) then begin 
Reply(124); 
set_global_var(GVAR_QUEST3,1); 
NOption(101,Node999,003); 
end else begin 
Reply(125); 
NOption(126,Node999,003); 
end 
end
 
Hmm... TRIPLE_ROLL... for what? Why this variant bad?
Code:
procedure Node001 begin 

 variable tmp_var; 
 variable los; 

  tmp_var:=random(1, 10); 

  if var_in(tmp_var, 1, 5) then los:=1; 
  else if var_in(tmp_var, 6, 8) then los:=2; 
  else if var_in(tmp_var, 9, 10) then los:=3 

  set_global_var(GVAR_QUEST1-1+los,1); 
 
  Reply(121+los); 
   NOption(101,Node999,003); 

end
 
Its ok
Tell me, how made percentage?

i try (to get 25):

50 * 50%

and:

50 * (50 / 100)

and not work

i tested this on script:

procedure description_p_proc begin
float_msg(dude_obj,"text" + (50 * (50/100)),9);
end
 
hmm... i not really sure, but try this:

temporary_variable:=50*(50/100);
float_msg(dude_obj, "text: "+temporary_variable, 9)

or this

float_msg(dude_obj, "text: "+(50*50)/100, 9)
 
Yes, its work
My new code:
variables a,b,c got the same starting chance and decreased by given %

Code:
R := random(5,100);
a := (R * 50) / 100
b := (R * 30) / 100
c := (R * 20) / 100
winA := (a>=b and a>c)
winB := (b>a and b>=c)
winC := (c>=a and c>b)

EDIT

This will not work, because random number R is selected only once in script, so olways will win only one variable.
 
Code:
a:=random(1, 50);
b:=random(1, 30);
c:=random(1, 20);
winA := (a>=b and a>c) 
winB := (b>a and b>=c) 
winC := (c>=a and c>b)
Thats all folks :))))

PS: Lich, AFAIK you wrote Fallout Scripts Tutorial? :)))
 
Its triple roll like before
Seem like using percentage just complicate thing, but now i known how made %

Yes i written this "Experiments with Fallout2 game scripts"
 
Back
Top