Basic syntax:
Most of my work so far has been done on people so some information will be missing for map and item scripts, I'm sure.
(Note: Pretty much all commands except 'if .. then', should be terminated by semi-colons. I've tried to indicate this where appropriate, but I may have missed some [note also that Var and begin are correctly not terminated by semicolons.]).
Script Files
A script file has the form:
(Yes, that final end is terminated by a period.)Script File wrote: script ScriptName('ScriptName');
uses ScriptLibs;
VarBlock
ProcedureList
Procedures
begin
end.
ScriptName- I haven't messed around with this much- having it the same as the int and msg file names works fine (acklint for the script acklint.ipp that uses acklint.msg for example.
ScriptLibs- Again, one I haven't messed around with much- basically the list of the lib files to use. This is just a comma-delimited list of other ipp files (minus the ipp extension). (The basic ones which you'll need to include are "system,stdlib").
VarBlock - A list of the variables for the script- explained later.
ProcedureList- An optional list of the procedures in the script file in the format procedure ProcedureName;forward;. there is no problem with not including this.
Procedures- The procedures that are contained in this script file. (Explained below).
Procedures
Pretty much all code is stored in procedures. These have the format
CodeBlock - This is the block of code (explained later) that is contained in that procedure.Procedures wrote: procedure ProcedureName;
VarBlock
CodeBlock
VarBlock - This is the block of vars (explained later) that is limited to that procedure.
ProcedureName - This is the name of the procedure. In general, this can be whatever you like (no spaces), with two warnings-
1) I'd bet you things will go wrong if you name it the same as another function. I haven't actually tried it, but if you are in this situation, you are probably doing something wrong.
2) There are certain functions that will be called for certain purposes in the game. These (the ones I know about anyhow) are:
talk_p_proc - Called when the person is talked to. More details on dialogue are available in the Fallout Modding 2: Dialogue thread.
destroy_p_proc - Called when the person is destroyed (killed).
look_at_p_proc - Called when the person is looked at (when you rest the mouse over the person- this is where you would show the basic description).
description_p_proc - This is called when the person is examined (here you would show the detailed description).
use_skill_on_p_proc - Called when a skill is used on the person. You can find out what skill was used with UseSkill (described later).
damage_p_proc - Called when the person is dealt damage.
map_enter_p_proc - Called when the player enters the map.
critter_p_proc - Called all the time (If the person wanders, for example, it would be coded in here.
pickup_p_proc - Called when someone is caught placing or taking an item from the person (using steal).
combat_p_proc - Called during the person's turn during combat. (The only script I've seen it in is the Overseer's in order to (I believe) give him unlimited ammo.).
CodeBlocks
A code block is a group of commands and functions surrounded by begin and end;. Thus, the following is a CodeBlock:
begin
writeln(GetStr(_script_,110);
writeln(GetStr(_script_,112);
writeln(GetStr(_script_,114);
end;
as is
begin
end;
VarBlocks
This is simply a list of the variables that will be usable within a given scope. A VarBlock at the start of the script file will be global variables. VarBlocks between a function name and the CodeBlock for the function will be limited to that function. VarBlocks have the form:
List of vars is a list of the variable names. (Example:VarBlocks wrote: Var
ListOfVars
)Var
s;
medium;
LongVariableName;
Commands
Assignment
:= is used to assign a value to another (x:=2; for example).
= is 'is equal to' for comparisons (if x=2 then for example).
> is 'is greater than' for comparisons
< is 'is less than' for comparisons.
>= is 'is greater than or equal to' for comparisons.
<= is 'is less than or equal to' for comparisons.
<> is 'is not equal to' for comparisons.
+ is used for addition.
- is used for subtraction.
* is used for multiplication.
/ is used for division.
' is used to surround strings (Editorial Comment: *Slamming head against brick wall for not noticing this sooner.*)
@ address of (I think) (Used when you need to pass a function (the function, not the results of the function) to another function (mainly 'answer').
if:
This is used to create conditional statements. the syntax is
if wrote: if Condition then
CodeBlock
Condition should be true or false (false=0, true= not 0). If it is true, the block is executed. Comparisons (=,<,<>,etc.) will return 1 if they are true- false otherwise.
(example:
if x>2 then
begin
...
end;
will execute if x is greater than 2.
GetStr(353,top_msg-1)<>''
Functions
Functions are used for the majority of the work in the script, and must be defined (most of them are defined in stdlib.ipp. For those that aren't defined there, I'll provide the code you have to insert into stdlib.ipp in order for them to work (after I get most or all of them in, I'll probably provide a file that will have all the code in one spot). Unless otherwise specified, these can be inserted anywhere you would use a number and it will use the return value. (for example if GetStr(_Script_,102)='' then).
Note: When a script/.msg file number is required, you can use _script_ to refer to the current script and associated .msg file.
Self
This is used to indicate the person who is running the script (so, for example, Self in klint's script would refer to klint. )
Player
This is used to indicate the player.
Sender
This is used to indicate who triggered the script. (For example, if Sender=Player then would test to see if the person who triggered the event was the player)
writeln(str)
Outputs a string to the message window (on the bottom left of the screen).
str - this is a string to output. This can either be a string bounded by '' or a string retrieved with other functions.
GetStr(scrnum,strnum)
Returns a string from a file.
scrnum- the .msg file number to get the string from.
strnum- the number of the string to get (this will be the first number in the line in the msg file (Example, for {102}{}{This is a string}, the number would be 102 for the string 'This is a string'.).
SayForAnswer(scrnum,str)
Displays dialogue. Should be followed by Answers.
scrnum- the .msg file number to get the string from.
str- the string to display- either a '' string, or the number of the string to get from the msg file.
SayWOAnswer(scrnum,str,parm1)
Displays dialogue that a response is not expected to.
scrnum- the .msg file number to get the string from.
str- the string to display- either a '' string, or the number of the string to get from the msg file.
parm1- Not sure. Might be used with Empathy..
Answer(int,scrnum,str,funcnum,parm1)
Used to display a user-choosable answer.
int- the min intelligence to be able to choose this answer. A range of 7 can use the answer (Thus, with a value of '2', chars with INT 2-8 could choose that answer). The commonly used values are:
-3 - for Low-INT chars
4 - for average and above
7 or 8 - for high-INT chars.
DebugPrint(msg)
Should print a message out to the Debug window (or maybe to the normal message window, but when you are in debug mode?) - I haven't been able to get into debug mode, so I can't be sure- if anybody knows how, let me know, please.
See(who,whom)
This returns true or false determining if who can see whom
who- the person who will be doing the seeing.
whom- the person who might be seen.
(Example: 'if See(Self,Player) then' will do the code in the if statement if the person who's script it is can see the player.)
GetStat(obj,stat)
Returns the value of a stat.
obj- the person/object to get the stat from.
stat- the stat to get the value of. Known numbers are (If/when you get more, please let us know since I haven't gotten around to testing (other) numbers to see what they refer to yet):
0 - Strength
1 - Perception
2 - Endurance
3 - Charisma
4 - Intelligencee
5 - Agility
6 - Luck
34- Gender (0=male, 1=female)
PlayerHasSexAppealTrait
Return 1 (true) if player has the Sex Appeal trait, false (0) otherwise.
PlayerHasPresencePerk
Return 1 (true) if player has the Presence trait, false (0) otherwise.
Month
Returns the current month:
1 - Jan
2 - Feb
3 - Mar
4 - Apr
5 - May
6 - Jun
7 - Jul
8 - Aug
9 - Sep
10- Oct
11- Nov
12- Dec
TimeOfDay
This is the current time. For example, at 3am, it will return 300, at 4:14 pm, it will return 1614.
SetLight(p1)
Sets the current light level. 100 is full brightness, 40 seems to be used for darkest night value.
GetSkill(obj,skillnum)
Get the value of a skill.
obj- person to get the skill value from.
skillnum- skill to get value of:
0 -Small Guns
1 -Big Guns
2 -Energy Weapons
3 -Unarmed
4 -Melee Weapons
5 -Throwing
6 -First Aid
7 -Doctor
8 -Sneak
9 -Lockpick
10-Steal
11-Traps
12-Science
13-Repair
14-Speech
15-Barter
16-Gambling
17-Outdoorsman
(UsedSkill at bottom of page)
Not Gotten To - you can ignore this
I'm going through the stdlib provided with the compiler, and then I'll go through the functions you need that aren't in the stdlib but that you may run across in a decompiled script. I'm just putting these here so I know which of the functions in the stdlib I haven't gotten through yet. As long as there is a list under here, you know I haven't gotten through writing up all the stdlib functions yet.
GetName(obj)
FrameID(obj)
Misc(parm1,parm2)
OpenDialog(scr,obj,parm1,parm2,parm3)
CloseDialog
Attack(who)
SetBattleParm(obj,parm1,parm2,parm3)
GetItemCountByXY(xy,level,objectid)
GetItemAddressByXY
Friend(critterid)
SetXY(obj,xy,level)
DistanceObj(parm1,param2)
CreateObj(p4,p3,p2,p1)
GiveItems(p3,p2,p1)
RetN(p1)
SetPlayerPos(p4,p3,p2,p1)
GetPerk(p4,p3,p2)
TotalTime
AddExp(XP)
Say(obj,strnum,color)
Non StdLib
This isn't a stdlib function, but I made reference to it earlier, so I should post it here:
UsedSkill
Used to determine what skill triggered a call to use_skill_on_p_proc
The code you need to insert for this is:
function UsedSkill;inline;
begin int 80fa end; end;