Library Script

Lich

Water Chip? Been There, Done That
One from my best inventions: hundread books in one item and one script.

When you use that item first time, it will be just "some book" then set random content and tile (when you read it) Olways book will have the same content after roll, because use local vars. You can place hundreads the same item on bookshelfs and almost every will have different content- look like other item. So you dont need create many book items. Its only way to made library (i got that location in my mod) every bookshelf will contain some book.

Its dont need write these books, to made content: just copy fragments from real books found on net.



Code:
procedure start;
procedure look_at_p_proc;
procedure use_p_proc;
procedure talk_p_proc;

procedure Node999;
procedure Node001;
procedure Node002;

#define LVAR_Q1 (0)

procedure start begin
end

procedure look_at_p_proc begin
variable G;
G := local_var(LVAR_Q1);
script_overrides;
display_mstr(200+G); 
end

procedure use_p_proc begin
if ((obj_pid(critter_inven_obj(dude_obj,INVEN_TYPE_RIGHT_HAND)) == 602) or 
(obj_pid(critter_inven_obj(dude_obj,INVEN_TYPE_LEFT_HAND)) == 602)) then begin
call talk_p_proc;
end else begin
display_mstr(600);
end
end

procedure talk_p_proc begin 
start_gdialog(NAME,self_obj,4,-1,-1); 
gSay_Start; 
if (local_var(LVAR_Q1) == 0) then begin
call Node001; 
end else
if (local_var(LVAR_Q1) >= 1) then begin
call Node002;
end else begin
call Node002; 
end
gSay_End; 
end_dialogue; 
end

procedure Node001 begin 
variable x;
x:=random(1,5);
set_local_var(LVAR_Q1,x);
Reply(100+x); 
NOption(300,Node999,002);
end

procedure Node002 begin
variable G;
G := local_var(LVAR_Q1);
Reply(100+G); 
NOption(300,Node999,002);
end

procedure Node999 begin
end


Code:
{100}{}{abc}
{101}{}{Content 1}
{102}{}{Content 2}
{103}{}{Content 3}
{104}{}{Content 4}
{105}{}{Content 5}
{200}{}{Some Book.}
{201}{}{Title 1}
{202}{}{Title 2}
{203}{}{Title 3}
{204}{}{Title 4}
{205}{}{Title 5}
{300}{}{Close.}
{600}{}{Before use that item, hold it on hands.}
 
Nice script, good idea, only one thing:
this code
Code:
procedure talk_p_proc begin
start_gdialog(NAME,self_obj,4,-1,-1);
gSay_Start;
if (local_var(LVAR_Q1) == 0) then begin
call Node001;
end else
if (local_var(LVAR_Q1) >= 1) then begin
call Node002;
end else begin
call Node002;
end
gSay_End;
end_dialogue;
end

should be

Code:
procedure talk_p_proc begin
start_gdialog(NAME,self_obj,4,-1,-1);
gSay_Start;
if (local_var(LVAR_Q1) == 0) then
call Node001;
else
call Node002;
gSay_End;
end_dialogue;
end
Do the same and is smaller(less code less bugs) :wink:
 
So what's it do exactly?

Create a random book from a given set of title/description pairs that keeps its content?
 
Ashmo said:
So what's it do exactly?

First time you see only "some book" in your inventory. When first read it set it content and title. Then you see in inventory book with some title and content that will be remember by engine (saved Lvar), so when use second time this book you will read the same content as before. Titles and contents are connected 100+x and 200+x. You can place the same item in many bookshelfs instead of create twenty similar books proto.

I wonder that the same could be made in weapons, probably hardcoded. But when possible- you can made only one weapon (for example spear) which every got different domage, ap cost, and else attributes.
 
I wonder that the same could be made in weapons, probably hardcoded. But when possible- you can made only one weapon (for example spear) which every got different domage, ap cost, and else attributes.
Sorry Lich but weapons stats(and any other stats) are read from proto files and you can't change them from script.
 
Dont give up, olways is fev ways to reach some point, let's do this alternate way then.

The idea is to create weapon with random attributes, and they must be saved. Weapon as any item may got thier script (but nobody used that possibility) When dude use that item (it means first shoot by it) then it will roll bonus and save to that item Lvars.

First we should try change weapon name to see other description when look at: spear of (1:wind,2:fire,3:earth,4:water)

Second is domage bonus:

When dude hold spear_of_fire, it means some spear with Lvar=2 then critter gets some extra domage. I think that script should be in the critter script. Other way is place code in obj_dude.int

Obviously weapon will got standard attributes with plus/minus bonus.

EDIT

My first experimental weapon with script:
Spear will have random name, when you hold it- dude will display some random comments from time to time.

Code:
procedure start;
procedure look_at_p_proc;
procedure map_update_p_proc;

#define LVAR_Q1 (0)

procedure start begin
end

procedure look_at_p_proc begin
variable x;
variable G;
if (local_var(LVAR_Q1) == 0) then begin
x:=random(1,4);
set_local_var(LVAR_Q1,x);
G := local_var(LVAR_Q1);
script_overrides;
display_mstr(100+G); 
end else begin
G := local_var(LVAR_Q1);
script_overrides;
display_mstr(100+G); 
end
end


procedure map_update_p_proc begin
if ((obj_pid(critter_inven_obj(dude_obj,INVEN_TYPE_RIGHT_HAND)) == 603) or 
(obj_pid(critter_inven_obj(dude_obj,INVEN_TYPE_LEFT_HAND)) == 603)) then begin
float_msg(dude_obj,mstr(random(200,204)),8);  
end
end

Code:
{100}{}{Some Spear}
{101}{}{Spear of Earth}
{102}{}{Spear of water}
{103}{}{Spear of fire}
{104}{}{Spear of wind}
{200}{}{Uh warriors got hard life}
{201}{}{Lets hunt for something}
{202}{}{I must search some battle}
{203}{}{Nothing happends again}
{204}{}{I must sharp my spear}

spr1.jpg


When use only look_at and map_update procedures it is possible to made random armours, every critter may have script who place in thier inventory (after destroyed) one armour with random attributes. If dude wear that item- gain extra bonus. Its easy to made compare to weapons and it should made it first.
 
The idea is to create weapon with random attributes, and they must be saved. Weapon as any item may got thier script (but nobody used that possibility) When dude use that item (it means first shoot by it) then it will roll bonus and save to that item Lvars.
We have no way to check when weapon is used we can only check when critter hits something in combat.
But after that what can you change, you can't change amount of engine damage you only can add more from script.
You can add radiation and poison but that works only on player so it's not a very good idea.
Most functions don't work in combat mode.
 
Back
Top