Author Topic: Advanced Scripts  (Read 15499 times)

0 Members and 1 Guest are viewing this topic.

Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 728
    • View Profile
    • Email
Advanced Scripts
« on: October 29, 2013, 06:10:31 pm »
This will be a breakdown of all of the Scripts in the Advanced Scripts Document that is sent out to new scriptors.  I will break each part down by their parts.  Perhaps using this we can come up with new examples to use in an updated version of this handout.   These current examples are what's in the current handout - I have skipped section 0, though may add on some of the information there at the end. Here is the index of what will be here.

1.  PERSONAL REMOTE FLAG

2.  PERSONAL GLOBAL FLAG

3.  TAKE/GIVE PREVENT/RESTRICT

4.  RESTRICT CONSEQUENCES OF AN ACTION TO A CERTAIN ROOM/ROOMS

5.  RANDOM SCRIPTS

6.  DOUBLE KEYWORD SPEECH SCRIPT

7.  LOAD HELPER

8.  LOAD SEVERAL HELPERS

9.  MOB TRANSFORM AND HEAL

10. OBJECT TRANSFORM

11. ROOM SWITCH

12. RESTRICT ENTRY

13. RANDOM LOAD MOBS

14. RANDOM LOAD OBJECTS

15. MULTIPLE RECEIVE

16. AVOID THE USE OF CHARMED MOBS IN RESTRICTED QUESTS

17. MULTIPLE ANSWERS

18. EXPERIENCE SCRIPT AND ONCE PER REBOOT SCRIPT

19. FOLLOWER IN RESCUE QUESTS

20. GOLD SCRIPT

21. HUNT SCRIPT

22. GROW FLOWER

23. TWO ITEMS WORN TOGETHER BECOME STRONGER

24. DOOR SCRIPTS

25. CONTAINER SCRIPTS

26. MAKE A MOB HUNT A CERTAIN PLAYER

27. TIME SCRIPTS

28. NUM ARG ON OBJECT SCRIPTS

29. DAMAGE ACTOR IN PROPORTION TO HITPOINTS

30. ZONE ECHO

31. PREVENT FROM USING TWO OF THE SAME ITEM

32. CHECK FOR PLAYERS IN THE ROOM

33. STOP SCRIPT LOOP

34. %ACTOR% and %ACTOR.NAME%, HIS AND HER

35. %PURGE% RULES

36. COMMAND TRIGGERS

37. SET PLAYER FLAGS WITH SCRIPTS

38. RANDOM SPELLS ON A POTION

39. SEX CHANGE AND ABORTION PILLS

40. ARRAY EXAMPLES

Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 728
    • View Profile
    • Email
1. PERSONAL REMOTE FLAG
« Reply #1 on: October 29, 2013, 06:12:13 pm »
1. PERSONAL REMOTE FLAG

This flag stays on the player file until it is removed by an imp or

another script.



OBS!!!! This flag is essential for most quests, because the reward

should always be lower after the first time a quest is performed,

if the quest is repeatable (to avoid script abuse).

Make sure that you choose a unique name for the flag, preferably

something referring to your zone or the quest/mob/object the script

is set on!

For example: mob3321, feniziawoman, textilesubskill, vikingmother etc.



Commands:

if !%actor.varexists(whatever)%

 set whatever 1

 remote whatever %actor.id%

endif



To make a script remove a flag from a player, use the line:

rdelete whatever %actor.id%



EXAMPLES

ONE TIME QUEST:

if !%actor.varexists(quest5)%

 %send% %actor% Well done for doing this Quest!

 set quest5 1

 remote quest5 %actor.id%

else

 %send% %actor% You cannot get in here again, %actor.name%!

 %teleport% %actor% 3001

endif



QUEST EQUIPMENT RESTRICTION:

trigger type: wear

if !%actor.varexists(quest5)%

 return 0

 wait 1

 %echoaround% %actor% This creature isn't worthy of using this item!

 %send% %actor% You didn't do this Quest yourself, %actor.name%.

 %send% %actor% So what makes you think you are worthy of the Reward?

 %purge% %self.name%

endif



REMOVE REMOTE FLAG:

if %actor.varexists(quest5)%

 rdelete quest5 %actor.id%

endif



MULTIPLE STEP QUEST:

if !%actor.varexists(whatever)%

 set whatever 1

 remote whatever %actor.id%

 halt

elseif %actor.varexists(whatever)%

 if %actor.whatever% == 1

  set whatever 2

  remote whatever %actor.id%

  halt

 elseif %actor.whatever% == 2

  set whatever 3

  remote whatever %actor.id%

  halt

  *etc. - for as many steps as you like...

 endif

endif


Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 728
    • View Profile
    • Email
2. PERSONAL GLOBAL FLAG
« Reply #2 on: October 29, 2013, 06:13:43 pm »
2. PERSONAL GLOBAL FLAG

This flag only stays on the player file until crash or reboot. It can

ensure that a player only gets the same reward once per reboot, while

at the same time leaving the reward available for other players. A very

useful loop for Quests that you want the player to be able to do more

than once, but not TOO often.



Note that this flag cannot be used on a mob that purges itself after

the Quest. Next time the zone resets the player will be able to do the

quest again. The same thing happems if the mob simply is killed.

Use it on room scripts or mobs that are hard or impossible to kill.



Commands:

context %actor.id%

if !%done%

 <insert whatever commands you want here>

 eval done 1

 global done

else

 <insert whatever you want here>

endif

context 0



EXAMPLE

context %actor.id%

if %done% == 0

 %send% %actor% You just found a treasure!

 %load% obj 3300

 eval done 1

 global done

else

 %send% %actor% Aaaaw - You have taken this treasure already!

endif

context 0



** Note: the last I knew context was not working right.  Beware of that if you choose to use this**

Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 728
    • View Profile
    • Email
3. TAKE/GIVE PREVENT/RESTRICT
« Reply #3 on: October 29, 2013, 06:14:45 pm »
3. TAKE/GIVE PREVENT/RESTRICT

This can be used to stop players from giving away Quest items, or from

picking up certain objects. Unless they have the flag, they cannot receive

or get the object. It can be used with or without messages to the actor

and/or victim (but with messages is usually better).

Use a give or get trigger on the object.

OBS!!!! Note that there cannot be any delay before the return 0 line,

or the script won't work.



(give trigger)

Commands:

if %victim.varexists(whatever)%

 <insert whatever you want here>

else

 <insert whatever you want here>

return 0

endif



(get trigger)

if !%actor.varexists(whatever)%

 <insert whatever you want here>

return 0

else

 <insert whatever you want here>

endif



EXAMPLE

if !%actor.varexists(whatever)%

 %send% %actor% You can't get that!

 %echoaround% %actor% %actor.name% tries in vain to get %object.shortdesc%

 return 0

else

 return 1

endif



Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 728
    • View Profile
    • Email
4. RESTRICT CONSEQUENCES OF AN ACTION TO A CERTAIN ROOM/ROOMS
« Reply #4 on: October 29, 2013, 06:15:50 pm »
4. RESTRICT CONSEQUENCES OF AN ACTION TO A CERTAIN ROOM/ROOMS

This can be used for instance if you want the player to get a nasty chock

the first time he picks up an item, but otherwise want the item to be

'normal'. It can also be used so that the player only hears a message or

performs an act if he is in a certain room.

Or maybe for a dragon, who will devour an intruder in its lair, but is

too lazy to hunt him if he flees.



Commands:

if %actor.room% == <vnum of room>

 <insert whatever you want here>

endif



You can also use the following lines for similar effects:

if %actor.room% == %self.room%

if %actor.canbeseen%



EXAMPLE 1:

Object script, Trigger type: get

Commands:

if %actor.room% == 8128

 wait 1

 %damage% %actor% 200

 %force% %actor% sit

 %echo% {cRYou have awoken the wrath of Pharaoh!{c0

 %echo% {cRNow suffer the consequences!{c0

 wait 2 s

 %load% mob 8119

 %force% guardian kill %actor.name%

else

 return 0

 %echo% Better be careful with what you are getting!

 %echo% The mummy crumbles to dust before your eyes.

 %purge% %self.name%

endif



EXAMPLE 2:

Mob script, Trigger type: Greet

Num arg: 100

Commands:

wait 1

emote roars, letting out a blast of fire.

%damage% %actor% 100

wait 5 s

if %actor.room% == %self.room%

 emote opens its gap to devour you.

 mkill %actor.name%

else

 tell %actor.name% Next time, mortal!

 say damn - the brat got away!

endif



EXAMPLE 3:

The script below executes the action in all rooms between a set range of vnums

(the numbers need to be in a sequence)



*choose one of the 'a's below

 

eval a %actor%

eval a %self%

eval a %self.carried_by%

eval a %self.worn_by%



if %a.vnum%<0

 if %a.room%>=<firstroom> || %a.room%<=<secondroom>

  *do stuff

 end

end

Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 728
    • View Profile
    • Email
5. RANDOM SCRIPTS
« Reply #5 on: October 29, 2013, 06:17:00 pm »
5. RANDOM SCRIPTS

These can be set up in different forms.



EXAMPLE 1:

The first example is the simplest one, which makes the mob perform

one of the actions 50% of the times.



Commands:

if %random.10% <= 5

 poke %actor.name%

else

 bite %actor.name%

endif



EXAMPLE 2:

The example below will make the mob perform 5 different actions randomly,

with about the same chance for each of them triggering.



Commands:

if %actor.vnum% < 0

eval number %random.5%

  switch %number%

   case 1

    snicker

    break

   case 2

    nudge %actor.name%

    break

   case 3

    giggle

    break

   case 4

    puke

    break

   default

    growl

    break

  done

endif



EXAMPLE 3:

The script below executes a random number of the same command,

(for instance to load a random number between 2 and 6 of the same object).

 

eval r 2+%random.4%

while %r%>0

eval r %r%-1

*do stuff

done



------------------------------

TO SET AN ACTOR TO RANDOM SCRIPTS:



set actor %random.char%

or

set actor %room.people%

to get a %actor% variable.





TO LOAD A RANDOM OBJECT FROM A ZONE

just do:

eval ovnum 12300 + %random.99%

%load% obj %ovnum%

Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 728
    • View Profile
    • Email
6. DOUBLE KEYWORD SCRIPT
« Reply #6 on: October 29, 2013, 06:18:05 pm »
6. DOUBLE KEYWORD SCRIPT

Sometimes you might want to use a double keyword to trigger a speech

script, for instance two lines of a poem. The first line sets a counter,

the second line triggers the action you want.



SCRIPT 1

--

Argument: Keyword 1

commands:

context %actor.id%

<insert whatever action you want to happen here>

set HCounter 1

global HCounter



SCRIPT 2

--

Argument: Keyword 2

commands:

if %HCounter% == 1

 <insert whatever action you want to happen here>

 set HCounter 0

 global HCounter

 unset HCounter

endif



EXAMPLE:

This script will allegedly summon a Keeper to the room with the first

keyword, and make him open a door with the second. If you say the

second key phrase without the first, nothing will happen.

(The Keeper is never really there, it is all done with room scripts).



Part 1. say Key phrase 1

Commands:

%echo% You feel a strange presence as the Keeper appears before you.

%echo% The Keeper booms, '{cWWhat do you want, puny mortal?{c0'

set HCounter 1

global HCounter



Part 2. say Key phrase 2

Commands:

if %HCounter% == 1

  wait 2 s

  %echo% The door silently slides to one side.

  %door% 8145 east flags a

  wait 10 s

  %echo% The door silently slides shut again.

  %door% 8145 east flags b

  set HCounter 0

  global HCounter

  unset HCounter

else

  %echo% %actor.name%'s voice echoes hollowly from the walls of the room.

endif



Here is another variation. You want the script to react to three

different keywords, but the order in which they are said is not

important. Below is an example of how to do it.



if (%speech.contains(word1)%&&%speech.contains(word2)%&&%speech.contains(word3)%)

 %echo% The room echoes your words, '%speech%'

 <insert any wanted action here>

endif


Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 728
    • View Profile
    • Email
7. LOAD HELPERS
« Reply #7 on: October 29, 2013, 06:18:58 pm »
7. LOAD HELPERS

You may want a mob to load a helper, if he is under attack. To avoid

him loading an unrestricted number of helpers, use the following

hitprc trigger, when he drops below a certain hitprc:



1: load one mob

Num arg: 30 (or whatever you want it to be)

Commands:

if (%load_helper% != 1)

 %echo% whatever

 %load% mob 1838

 %force% helper kill %actor.name%

 set load_helper 1

 global load_helper

endif



OR

2:Load multiple mobs (5 in this example), one per combat round.

Commands:

if (%load_helper% <= 5)

 %echo% whatever

 %load% mob 1838

 eval load_helper (%load_helper%+1)

 global load_helper

endif



Make the loaded mob either helper or aggro, or

set a load trigger on the helper 'assist mob-name'

or use this line in the first script:

%force% mobname kill %actor%



If the loaded mob is aggro, set the load script to make it go away and purge

itself after a suitable wait. (We don't want aggro mobs hanging around).

Commands:

wait 20 T

%purge% self


Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 728
    • View Profile
    • Email
8. LOAD SEVERAL HELPERS
« Reply #8 on: October 29, 2013, 06:20:22 pm »
8. LOAD SEVERAL HELPERS - ALL AT ONCE

Maybe you want the mob to load several helpers? Use the script

below to restrict the number.



Commands:

if !(%all_done%)

eval load_mob 1

while (%load_mob% < 3)

%load% mob <vnum>

eval load_mob (%load_mob%+1)

done

set all_done 1

global all_done

end



(*3 being the amount you want to load.)





Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 728
    • View Profile
    • Email
9. MOB TRANSFORM AND HEAL
« Reply #9 on: October 29, 2013, 06:21:43 pm »
9. MOB TRANSFORM AND HEAL

The script below makes the mob transform into a bigger and tougher mob,

when it drops below 80% of its hitpoints. The - before the vnum ensures

that the new mob is at full hp. This means that you can make a mob

virtually unkillable, by just loading itself with a negative vnum, each

time it drops below a certain point. It should be used with restraint,

since it is extremely frustrating to the player, but can be practical

on Quest mobs that you don't want to put in a peaceful room.



Hitprc 80

Commands:

if !%activated%

eval activated 1

global activated

wait 3 s

%echo% The kitten begins to mutate!

wait 2 s

%echo%  DEVOLVING INTO...

wait 2 s

%echo% ... A LIONESS!!

%echo The lioness roars at you!

mtransform  -203

end



The following script will make a mob transform itself in five different

shapes - it starts out with the mob 1200, then changes to 1201, when

it reaches 70% hit, then changes to 1202 when it reaches 70% the second

time etc. Each new mob is at full hp, and the fight will continue as

if nothing happened. (You will have to make all 5 mobs in OLC of course).



if !(%stop_transform%)

switch %self.vnum%

  case 1200

    %echo% The wizard transform to a lion!

    mtransform 1201

    break

  case 1201

    %echo% The wizard transform to a Dragon!

    mtransform 1202

    break

  case 1202

    %echo% The wizard transform to a Fire Flame!

    mtransform 1203

    break

  case 1203

    %echo% The wizard transform to a Demon!

    mtransform 1204

    break

  case 1204

    %echo% The wizard returns to his original shape!

    mtransform 1200

    set stop_transform 1

    global stop_transform

    break

  default

    break

done



The following script will make the mob transform into itself with full

hitpoints. This script is extremely irritating for the players, so

don't misuse it. Basically it should only be used for Quest mobs, which

are supposed to be unkillable.



%echo% {cWIt is impossible to kill <Whoever>, you'd better give it up.{c0

mtransform -%self.vnum%



Another way to make a mob heal itself during a fight would be the line:

%damage% %self% -100000



Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 728
    • View Profile
    • Email
10. OBJECT TRANSFORM
« Reply #10 on: October 29, 2013, 06:22:36 pm »

10. OBJECT TRANSFORM

This can be used to make it appear as if an object breaks when it is

dropped, or to magically change into something new when you wear it

or remove it.



EXAMPLES:

1. Wear trigger:

if %self.vnum% == 23603

%send% %actor% You put a spider on your nose!

%echoaround% %actor% puts a spider on their nose. YUK!

%echo% The Spider spins its web over its new home!

otransform 23604

end

-----



2. Rem trigger:

if %self.vnum% ==23604

return 0

%send% %actor% You struggle but just cannot get the sticky web off your

face.

%echoaround% %actor% struggles but just cannot get the sticky web off their

face.

otransform 23603

end

-----



Drop trigger, object 230:

if %self.vnum% == 230

wait 1

%echo% As the vial hits the floor, it shatters into tiny fragments.

%echo% A pool of red fluid spreads on the floor.

%transform% 231

end

----

(231 is a pool of liquid with glass shards, with no take flag)



When an object transforms to a new vnum, the scripts set on the

original object will follow over to the new vnum. To avoid this, and

to make sure that the right scripts are attached to the new object,

you use the commands dg_attach and dg_detach:

dg_attach <vnum of trigger> <id of object to attach it to>

dg_detach <vnum of trigger> <id of object to remove it from>



Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 728
    • View Profile
    • Email
11. ROOM SWITCH
« Reply #11 on: October 29, 2013, 06:23:43 pm »
11. ROOM SWITCH

This is a neat trick, a player with a certain flag is taken to a different

room than everybody else when he enters a certain room. The new room can

have an identical desc, but contain a reward, or perhaps an entrance to a

part of the zone that you cannot get to without the flag. Since there are

no messages it's hard for the players to figure out what happens.



Make two different rooms and use an Enter trigger:



if %actor.varexists(whatever)%

 eval r %actor.room%

 %door% %r% %direction% door <vnum of second room>

 wait 1

 %door% %r% %direction% door <vnum of first room>

end



EXAMPLE

if %actor.varexits(NewRoom)%

 eval r %actor.room%

 %door% %r% east door 1220

 wait 1

 %door% %r% east door 1221

end


Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 728
    • View Profile
    • Email
12. ENTER RESTRICTION
« Reply #12 on: October 29, 2013, 06:24:28 pm »
12. ENTER RESTRICTION

This simple loop on an Enter script can stop the actor from entering the

room, unless he's got a certain flag. You can put in a message, but it is

even more frustrating without. The exit east is there, but nothing happens

when you type east.



EXAMPLE:

if !%actor.varexists(whatever)%

 return 0

 %send% %actor% Alas, you cannot go that way...

end


Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 728
    • View Profile
    • Email
13. RANDOM LOAD MOBS
« Reply #13 on: October 29, 2013, 06:25:19 pm »

13. RANDOM LOAD MOBS

Sometimes it can be useful to make a mob load in random rooms,

when the zone resets. If nothing else it makes for more variation

and makes the mob a bit harder to find. (The mob only appears in

a new room if it is killed before the zone resets).



For: mobiles

type:load

narg: 100

commands:

set num1 <first.room.in.zone.vnum>

eval room (%num1%+%random.<total.number.of.rooms.in.zone>%)

if (%room.name%!=0)||("%room.name%"!="")

*this makes sure the room exists

mgoto %room%

end


Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 728
    • View Profile
    • Email
14. RANDOM LOAD OBJECTS
« Reply #14 on: October 29, 2013, 06:26:15 pm »
14. RANDOM LOAD OBJECTS

Making objects load in random rooms is a bit trickier. You have

to make a mob that teleports around and drops them. Make the mob

purge itself after it dropped the object, if you want a new object

to appear every time the zone resets. Otherwise the object only

appears if the mob is killed before the reset. Both principles

can be equally useful.

The script below will make the mob drop a given number of the

item randomly in any of the rooms of the zone each time he is

loaded after a reboot or getting killed.



for: mobiles

type: load

narg: 100

arg:

commands:

set num1 <first.room.of.zone.vnum>

set total <total.amount.of.items.to.be.randomly.distributed>

set what <vnum.of.item.to.be.distributed>

set count 0

while (%count%<%total%)

eval count (%count+1)

%load% obj %what%

eval room (%num1%+%random.<total.number.of.rooms.in.zone>%)

mat %room% drop <name.of.the.item>

done