Post reply

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.
Message icon:

Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?:

shortcuts: hit alt+s to submit/post or alt+p to preview

Topic Summary

Posted by: Kulyok
« on: June 22, 2009, 12:36:22 AM »

Originally written for Pen52; I hope it can help you, as well.

And here're a few new coding tips:

1) Suppose you are writing an NPC(romance) mod, and you need an influence variable, or something like "KivanLikes"/"KivanDislikes" variable from Domi's Kivan of Shilmista. Here's how it's done:

setting Sarevok's(for example) influence variable is very-very easy. Example:
Code: [Select]
++ ~Torture? And here I thought we were getting along so well. ~ + Sare8knives2 (SareInfluence +1)is:
Code: [Select]
++ ~Torture? And here I thought we were getting along so well. ~ DO ~IncrementGlobal("SareInfluence","GLOBAL",1)~ + Sare8knives2
IncrementGlobal = add something to this variable. IncrementGlobal("SarekInfluence","GLOBAL",1)=SareInfluence+1.

Obviously, decreasing it is just as easy:
Code: [Select]
++ ~Please, don’t hurt me. ~  + Sare8knives4 (SareInfluence -1)is:
Code: [Select]
++ ~Please, don’t hurt me. ~ DO ~IncrementGlobal("SareInfluence","GLOBAL",-1)~ + Sare8knives4

2) Comments in your code:

Also, if you want to use comments in your code, you can use these symbols: /* note */
This way the compiler will ignore them - and will not tell us that there's a mistake.
Code: [Select]
IF ~~ Sare8knives4 (and -1=<SareInfluence<2)is:
Code: [Select]
IF ~~ Sare8knives4 /* (and -1=<SareInfluence<2) */
You can also use

Code: [Select]
IF ~~ Sare8knives4 // (and -1=<SareInfluence<2)
- but be careful: "//" can only work for one line. If you've got long commentary, it will have to go like this:
Code: [Select]
// make sure
// you use tildas
// and finish each state with an END

3) If we have to choose Sarevok's answer to PC, depending on SareInfluence, here's what we do.
Original code:
Code: [Select]
++ ~Please, don’t hurt me. ~ DO ~IncrementGlobal("SareInfluence","GLOBAL",-1)~ + Sare8knives4

IF ~~ Sare8knives4 /* (and SareInfluence=>2) */
SAY ~So those knees of yours do know how to bend. ~
IF ~~ + Sare8knives1   

IF ~~ Sare8knives4 /* (and -1=<SareInfluence<2) */
SAY ~Pleading does not become you.  ~
IF ~~ + Sare8knives1   

How do we actually code it? The answer very simple: we write two replies, one for one condition, one for another.
And we insert our condition in both replies between two "+"'s, in tildas:

Code: [Select]
+ ~GlobalGT("SareInfluence","GLOBAL",1)~ + ~Please, don’t hurt me. ~ DO ~IncrementGlobal("SareInfluence","GLOBAL",-1)~ + Sare8knives4
+ ~GlobalLT("SareInfluence","GLOBAL",2)~ + ~Please, don’t hurt me. ~ DO ~IncrementGlobal("SareInfluence","GLOBAL",-1)~ + Sare8knives4

GlobalLT means that variable is less than(SareInfluence<2); GlobalGT means that variable is greater than(SareInfluence>=2, or SareInfluence>1)

If you want to add another condition(SareInfluence>=-1, or SareInfluence>-2), you just need to add an extra condition toi the line(no AND's):

Code: [Select]
+ ~GlobalGT("SareInfluence","GLOBAL",1)~ + ~Please, don’t hurt me. ~ DO ~IncrementGlobal("SareInfluence","GLOBAL",-1)~ + Sare8knives4
+ ~GlobalGT("SareInfluence","GLOBAL",-2) GlobalLT("SareInfluence","GLOBAL",2)~ + ~Please, don’t hurt me. ~ DO ~IncrementGlobal("SareInfluence","GLOBAL",-1)~ + Sare8knives4

4) Conditions for PC responses(race, class, etc)

Race is simple:

Code: [Select]
+ ~Race(Player1,ELF)~ + ~I am an elf.~ + elf
+ ~!Race(Player1,ELF)~ + ~I am not an elf.~ + notelf /* ! means NOT */
+ ~OR(2) Race(Player1,ELF) Race(Player1,HALF_ELF)~ + ~I am an elf or a half-elf.~ + elfish /* OR(2) and _two_ commands after it means A or B */



Gender(Player1,FEMALE) - Player1 is a woman
Gender(Player1,MALE) - Player1 is a man

Class id but basically the same:

Code: [Select]
+ ~Class(Player1,MAGE_ALL)~ + ~I am a wild mage, a mage, a sorcerer!~ + mage_or_sorcerer_or_wild_mage
+ ~Class(Player1,BARD_ALL)~ + ~I am a bard! A scald! A jester! A blade!~ + bards
+ ~!Class(Player1,MAGE_ALL) !Class(Player1,BARD_ALL)~ + ~I cannot cast mage spells.~ + notmageandnotbard
+ ~Class(Player1,FIGHTER_ALL)~ + ~I am a cool fighter!~ + fighter


Stats are a tad more difficult:

CheckStatGT and CheckStatLT are two commands you will need. For example: CheckStatGT(Player1,11,INT) means that Player1's Intelligence > 11 (12 or higher).

Code: [Select]
+ ~CheckStatGT(Player1,12,CHR)~ + ~I am pretty!~ + cha_13_or_higher
+ ~CheckStatLT(Player1,10,STR)~ + ~I am weak.~ + str_9_or_lower

All stats are: STR, DEX, CON, INT, WIS, CHR(not CHA!!).

Just in case - here is a full list of various commands(it looks complicated, though):

5) Setting and checking variables:

Now, there are two commands. Setting a variable is simple, just like with CLUAConsole: SetGlobal("variablename","GLOBAL",2)
And checking if our variable is 2 or not 2 is even simpler: Global("variablename","GLOBAL",2) checks if your variable=2 or not.

Clean code follows:

If you want to set SarevokPCLie=1(if PC lies), it's usually best to do it this way:

Code: [Select]
++ ~I love you, Sarevok! (truth)~ + sarevok_replies_truth /* we do nothing */
++ ~I love you, Sarevok! (lie)~ DO ~SetGlobal("SarevokPCLie","GLOBAL",1)~ + sarevok_replies_lie /* we set a variable*/

Now, if you want to check a variable, then you can do it this way:

Code: [Select]
+ ~Global("RE_SarevokPCLie","GLOBAL",0)~ + ~I never lied to you before, Sarevok!~ + this_is_true_sarevok_replies
+ ~Global("RE_SarevokPCLie","GLOBAL",1)~ + ~I never lied to you before, Sarevok!~ + this_is_NOT_true_sarevok_replies