Author Topic: Trigger of the .... something  (Read 48259 times)

0 Members and 1 Guest are viewing this topic.

Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 729
    • View Profile
    • Email
Re: Trigger of the .... something
« Reply #30 on: February 23, 2014, 10:45:57 am »
I found this over at TBA and thought it was useful.  We probably have the help file in 4D as well, but I'm too lazy to look right now and I know I've needed this info before.  So, for everyone else:

Text Variable Fields

   These fields pertain to any variable that contains a string of text. These
are often the variables, such as %speech%, which are provided to a trigger, but
can also be variables that have been created by the trigger, such as
%room.north%

When using field - The variable returns
 
strlen     - Returns the number of characters in the string.
trim       - Returns the string without any leading or trailing whitespace.
             This is used to trim extra spaces from the beginning or end of a
             string.
car        - Returns the first word of the string. For %text%="this is the
             string"; %text.car% will yield "this".
cdr        - Returns all but the first word of the string, trimmed. For %text%=
             "this is the string"; %text.cdr% will yield "is the string".
contains() - Used to check if a string contains the subfield text.
mudcommand - Returns the mud command the string is shorthand for. Used to make
             sure the command you react to is the one you want: For %text%="o"
             %text.mudcommand% will yield "open".
charat     - set new variable %text/var.charat(index)% i.e. set phrase testing,
             set var1 %phrase.charat(2)% now %var1% == e

Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 729
    • View Profile
    • Email
Re: Trigger of the .... something
« Reply #31 on: March 01, 2014, 11:01:39 am »
Name: 'Napalm bomb - 317',  VNum: [  337], RNum: [  258]
Trigger Intended Assignment: Objects
Trigger Type: Command , Numeric Arg: 2, Arg list: nap
Commands:
if napalm /= %cmd%
  if %actor.fighting% && !%arg%
    set arg %actor.fighting%
  end
  if !%arg%
    %send% %actor% Throw it at Who?
    halt
  end
  if %arg.room% != %actor.room%
    %send% %actor% Throw it at who?
    halt
  end
  %send% %actor% You throw the napalm at %arg.name%, it strikes %arg.himher% and shatters, exploding into a ball of fire consuming %arg.himher% completely.
  %echoaround% %actor% %actor.name% throws the napalm at %arg.name%. It shatters and explodes into a ball of fire consuming %arg.himher%.
%asound% A large explosion is heard close by.
  set stunned %arg.hitp%
  %damage% %arg% %stunned%
  wait 5 sec
  %echoaround% %arg% %arg.name% collapses to the ground as the flames die down. %arg.heshe% seems to still be alive, but barely.
End

** I found this script interesting for a couple of reasons.  First, the ability to set an arg when it isn't explicitly given and the fact you can find out the himher on that arg.  Also, who doesn't like a Napalm bomb? **

Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 729
    • View Profile
    • Email
Re: Trigger of the .... something
« Reply #32 on: March 01, 2014, 11:08:30 am »
Name: 'Mob Act - 98 Teleporter Give',  VNum: [  398], RNum: [  265]
Trigger Intended Assignment: Mobiles
Trigger Type: Act , Numeric Arg: 0, Arg list: has entered the game.
Commands:
if !(%actor.inventory(82)%)
  wait 1s
  say You are not prepared to travel these realms to their fullest.
  wait 1s
  say Maybe I can help you.
  %load% obj 82
  give teleporter %actor.name%
*could actor carry the weight?
  if !%actor.inventory(82)%
  drop teleporter
  end
  wait 2s
  say With this you may teleport to areas that may not be accessible in
any other way.
  wait 2 sec
  say HELP AREAS
end

** I chose this script because I've always wondered what an ACT script actually was – since there never seems to be much detail behind any of them anywhere.  Looking at the Arg list, I can then assume that this script reacts to any time it sees “has entered the game”

Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 729
    • View Profile
    • Email
Re: Trigger of the .... something
« Reply #33 on: March 03, 2014, 08:02:35 pm »
Just a short trigger to keep this up as often as possible.

Name: 'Mob Greet direction',  VNum: [  302], RNum: [  223]
Trigger Intended Assignment: Mobiles
Trigger Type: Greet , Numeric Arg: 20, Arg list: None
Commands:
* By Rumble of The Builder Academy    tbamud.com 9091
if %actor.is_pc%
  wait 1 sec
  if %direction% == none
    * if the character popped in (word of recall) this will be hit
    say Where did YOU come from, %actor.name%?
  else
    say Hello, %actor.name%, how are things to the %direction%?
  end
end

Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 729
    • View Profile
    • Email
Re: Trigger of the .... something
« Reply #34 on: March 06, 2014, 07:18:06 pm »
Name: 'Panning for gold',  VNum: [  700], RNum: [  280]
Trigger Intended Assignment: Rooms
Trigger Type: Command , Numeric Arg: 100, Arg list: p
Commands:
* Don't let someone spam the trigger to make money Take some movement points away every round and stop when they get to 10
if %actor.move% <= 10
  %send% %actor% You are too exhausted to continue.
  halt
end
* Fire on pan gold or abbreviations of each word
if %cmd% /= pan && %arg% /= gold
  eval heldobj %actor.eq(hold)%
  * Make sure they picked up the gold pan in room 703 and are holding it
  if %heldobj.vnum% == 717
    %send% %actor% You dip your pan into the river and scoop up some of the river bed and begin swirling it in the water.
    %echoaround% %actor% %actor.name% dips a pan into the river and begins panning for gold.
    * Take 10 movement points away, wait 3 seconds and give a 1 in 10 chance of success.
    nop %actor.move(-10)%
    wait 3 sec
    if %random.10% == 1
      %send% %actor% You find a small gold nugget in the bottom of your pan.
      %echoaround% %actor% %actor.name% picks something out of %actor.hisher% pan.
      * Give them a nugget
      %load% obj 718 %actor% inv
    else
      %send% %actor% You find nothing of value.
    end
  else
    %send% %actor% You need a pan for that.
  end
end

** This would be an interesting script for an area in the Old West – if we don't already have it **

Offline Molly

  • Administrator
  • Hero Member
  • *****
  • Posts: 690
    • View Profile
Re: Trigger of the .... something
« Reply #35 on: March 07, 2014, 02:04:01 am »
** This would be an interesting script for an area in the Old West – if we don't already have it **

Well, we do, of course. Who said we didn't have pirates - I mean everything? :)

There is goldpanning in one of the Sutter zones, I forgot which one.
Probably set up in a different way, but still goldpanning.

Offline Molly

  • Administrator
  • Hero Member
  • *****
  • Posts: 690
    • View Profile
Re: Trigger of the .... something
« Reply #36 on: March 07, 2014, 02:14:26 am »
Here it is:
(There is a mob somewhere to teach the subskill softmining, of course)

Name: 'dip pan water',  VNum: [30973], RNum: [ 6335]
Trigger Intended Assignment: Rooms
Trigger Type: Command, Numeric Arg: 100, Arg list: dip
Commands:
if !%actor.is_pc%
  halt
end
set sa %send% %actor%
set se %echoaround% %actor%
set object %actor.inventory(30911)%
if !%object%
  %sa% With What??!?
  halt
end
if (!%actor.subskill(softmining)%)
  %sa% You don't know how to do that!
  halt
end
if %object.vnum(30911)%
  if %actor.varexists(ilana_muffs)%
    wait 5s
    %sa% You dip a tin pan into the water, scraping it along the bottom of the bed.
    wait 5s
    %se% %actor.name% dips a tin pan into the water, scraping it along the bottom of the bed.
    wait 5s
    %sa% You begin to swish the pan as Old Jack demonstrated, slopping some water over the sides.
    wait 5s
    if (%actor.subskill(softmining)% >= %random.700%)
      %sa% Pretty soon, all that remains is a bit of silt and a few pieces of shiny flakes on the bottom of the pan.
      wait 2s
      %force% %actor% whistle
      %load% obj 30992 %actor%
      eval am (%actor.level%*(%actor.subskill(softmining)%+1500+%random.200%))
      nop %actor.exp(%am%)%
      wait 1s
      %sa% You've successfully collected a few flakes of an undetermined substance!
    else
      %sa% Pretty soon, all that remains is a bit of silt on the bottom of the pan.
      wait 2s
      %force% %actor% frown
      wait 1s
      %sa% You look and look in the bottom of the pan, but nary a fleck of gold can be seen!
      wait 2s
      %sa% You were unsuccessful! Try again!
    end
  else
    %sa% You don't know what you are doing!
  end
else
  %sa% You can't do it with that!
end

Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 729
    • View Profile
    • Email
Re: Trigger of the .... something
« Reply #37 on: March 31, 2014, 08:48:40 am »
It has been a while since I posted so, here's another one.  I grabbed it a little too late for Valentines day, but it would have rocked if I'd seen it earlier.  Maybe next year.  Hope I haven't posted this yet.  I'm too lazy to go through all the old posts to see.

Name: 'Eat, look, read, candy',  VNum: [ 1309], RNum: [  382]
Trigger Intended Assignment: Objects
Trigger Type: Command , Numeric Arg: 2, Arg list: *
Commands:
if look /= %cmd.mudcommand% && heart /= %arg% && %arg% || read /= %cmd.mudcommand% && heart /= %arg% && %arg% || read /= %cmd.mudcommand% && candy /= %arg% && %arg% || look /= %cmd.mudcommand% && candy /= %arg% && %arg%
*
eval color %random.3%
set col[1] \
set col[2] \
set col[3] \
*
eval colors %%col[%color%]%%
*
eval heart %random.15%
set love[1] Be Mine
set love[2] I Love You
set love[3] I Wuv You
set love[4] Kiss Me
set love[5] Hug Me
set love[6] Be My Valentine
set love[7] Will You Be Mine
set love[8] You Are The Only One For Me
set love[9] I'm yours
set love[10] You're Special To Me
set love[11] I Really Like You
set love[12] I Luv U
set love[13] U R Mine
set love[14] With All My Heart
set love[15] Cutie Pie
eval candy %%love[%heart%]%%
*
%send% %actor% Written on the candy is:
%send% %actor% %colors% %candy% \
*
elseif eat /= %cmd.mudcommand% && heart /= %arg% && %arg% ||  eat /= %cmd.mudcommand% && candy /= %arg% && %arg%
*
eval message %random.10%
set word[1] It warms the cockles of your heart!
set word[2] It tastes wonderful!
set word[3] It melts in your mouth.
set word[4] It slowly disolves in your mouth.
set word[5] It tastes sweet and a little chalky.
set word[6] Mmmmm!
set word[7] You can feel the love!
set word[8] You feel warmer already!
set word[9] Mmm hearty goodness!
set word[10] Sweet like candy!
eval msg %%word[%message%]%%
*
%send% %actor% You eat %self.shortdesc%.
%echoaround% %actor% %actor.name% eats %self.shortdesc%.
%send% %actor% %msg%
%purge% self
*
else
return 0
end


Offline Calypso

  • Administrator
  • Full Member
  • *****
  • Posts: 133
    • View Profile
    • Email
Re: Trigger of the .... something
« Reply #38 on: March 31, 2014, 09:54:13 am »
I may snag this and work on it in bp soon so it is ready when we need it next time. Thanks for the great idea!! :)
I get my energy from my Inner G.

Offline erwin

  • Sr. Member
  • ****
  • Posts: 314
    • View Profile
Re: Trigger of the .... something
« Reply #39 on: June 23, 2014, 10:09:26 pm »
Trigger of the Day:

A sliding puzzle, which can be modified for any m*n grid, and for any tile description. It also has a visually impaired toggle. I think this is interesting because it:

1. shows how to extract the first and second words the player types after entering a command and
2. shows what %%var%% and %%%var%%% do

Set up: Here's (part of) what the player sees when he looks at the object.

"puzzle board" - See the current layout of the board
"puzzle move up" - Move a tile up into the empty space.
"puzzle move down" - Move a tile down into the empty space.
"puzzle move left" - Move a tile left into the empty space.
"puzzle move right" - Move a tile right into the empty space.
"puzzle rules" - See the rules of this puzzle.
"puzzle toggle" - Toggle for visually impaired.

and below is the trigger! If anyone has any suggestions on how to improve this, it's much appreciated :)

Code: [Select]
Trigger Intended Assignment: Objects
Trigger Type: Command, Numeric Arg: 3, Arg list: puzzle
Commands:

extract firstphrase 1 %arg%
extract secondphrase 2 %arg%

if !%coordinatex%
  set coordinatex 4
  remote coordinatex %self.id%
endif

if !%coordinatey%
  set coordinatey 4
  remote coordinatey %self.id%
endif

if !%Cord11%
  set Cord11 01
  remote Cord11 %self.id%
endif

if !%Cord12%
  set Cord12 02
  remote Cord12 %self.id%
endif

if !%Cord13%
  set Cord13 03
  remote Cord13 %self.id%
endif

if !%Cord14%
  set Cord14 04
  remote Cord14 %self.id%
endif

if !%Cord21%
  set Cord21 05
  remote Cord21 %self.id%
endif

if !%Cord22%
  set Cord22 06
  remote Cord22 %self.id%
endif

if !%Cord23%
  set Cord23 07
  remote Cord23 %self.id%
endif

if !%Cord24%
  set Cord24 08
  remote Cord24 %self.id%
endif

if !%Cord31%
  set Cord31 09
  remote Cord31 %self.id%
endif

if !%Cord32%
  set Cord32 10
  remote Cord32 %self.id%
endif

if !%Cord33%
  set Cord33 11
  remote Cord33 %self.id%
endif

if !%Cord34%
  set Cord34 12
  remote Cord34 %self.id%
endif

if !%Cord41%
  set Cord41 13
  remote Cord41 %self.id%
endif

if !%Cord42%
  set Cord42 14
  remote Cord42 %self.id%
endif

if !%Cord43%
  set Cord43 15
  remote Cord43 %self.id%
endif

if !%Cord44%
  set Cord44 EE
  remote Cord44 %self.id%
endif

if %firstphrase% == toggle && !%secondphrase%

  if !%visimp% || %visimp% == 0
    set visimp 1
    %send% %actor% You are toggling this puzzle to cater to the visually impaired.
    remote visimp %self.id%
  elseif %visimp% == 1
    set visimp 0
    %send% %actor% You are toggling this puzzle to cater to the non visually impaired.
    remote visimp %self.id%
  endif

elseif %firstphrase% == rules && !%secondphrase%
  %send% %actor% This is a sliding puzzle game, and you want to get the following layout in the end.
  if !%visimp% || %visimp% == 0
    %send% %actor% -------------------------
    %send% %actor% |     |     |     |     |
    %send% %actor% | 01  | 02  | 03  | 04  |
    %send% %actor% |     |     |     |     |
    %send% %actor% -------------------------
    %send% %actor% |     |     |     |     |
    %send% %actor% | 05  | 06  | 07  | 08  |
    %send% %actor% |     |     |     |     |
    %send% %actor% -------------------------
    %send% %actor% |     |     |     |     |
    %send% %actor% | 09  | 10  | 11  | 12  |
    %send% %actor% |     |     |     |     |
    %send% %actor% -------------------------
    %send% %actor% |     |     |     |     |
    %send% %actor% | 13  | 14  | 15  | EE  |
    %send% %actor% |     |     |     |     |
    %send% %actor% -------------------------
    %send% %actor%
    %send% %actor% EE denotes the empty space.
  elseif %visimp% == 1
    %send% %actor% 01, 02, 03, 04
    %send% %actor% 05, 06, 07, 08
    %send% %actor% 09, 10, 11, 12
    %send% %actor% 13, 14, 15, EE
    %send% %actor%
    %send% %actor% EE denotes the empty space.
  endif

elseif %firstphrase% == board && !%secondphrase%
  %send% %actor% This is the current board layout.
  if !%visimp% || %visimp% == 0
    set border -------------------------
    set inbet |     |     |     |     |
    %send% %actor% %border%
    %send% %actor% %inbet%
    %send% %actor% | %Cord11%  | %Cord12%  | %Cord13%  | %Cord14%  |
    %send% %actor% %inbet%
    %send% %actor% %border%
    %send% %actor% %inbet%
    %send% %actor% | %Cord21%  | %Cord22%  | %Cord23%  | %Cord24%  |
    %send% %actor% %inbet%
    %send% %actor% %border%
    %send% %actor% %inbet%
    %send% %actor% | %Cord31%  | %Cord32%  | %Cord33%  | %Cord34%  |
    %send% %actor% %inbet%
    %send% %actor% %border%
    %send% %actor% %inbet%
    %send% %actor% | %Cord41%  | %Cord42%  | %Cord43%  | %Cord44%  |
    %send% %actor% %inbet%
    %send% %actor% %border%
  elseif %visimp% == 1
    %send% %actor% %Cord11%, %Cord12%, %Cord13%, %Cord14%
    %send% %actor% %Cord21%, %Cord22%, %Cord23%, %Cord24%
    %send% %actor% %Cord31%, %Cord32%, %Cord33%, %Cord34%
    %send% %actor% %Cord41%, %Cord42%, %Cord43%, %Cord44%
  endif

elseif %firstphrase% == move

  if %secondphrase% == down
    *let's check if we can move anything down into the empty square
    if %coordinatex% == 1
      %send% %actor% You cannot move anything down into the empty space!
    else
      *let's see what tile should be moved down
      eval newx %coordinatex% -1
      eval tiletomove Cord%newx%%coordinatey%
    endif

  elseif %secondphrase% == up
    *let's check if we can move anything up into the empty square
    if %coordinatex% == 4
      %send% %actor% You cannot move anything up into the empty space!
    else
      eval newx %coordinatex% + 1
      eval tiletomove Cord%newx%%coordinatey%
    endif

  elseif %secondphrase% == right
    *let's check if we can move anything right into the empty square
    if %coordinatey% == 1
      %send% %actor% You cannot move anything right into the empty space!
    else
      eval newy %coordinatey% - 1
      eval tiletomove Cord%coordinatex%%newy%
    endif

  elseif %secondphrase% == left
    *let's check if we can move anything left into the empty square
    if %coordinatey% == 4
      %send% %actor% You cannot move anything left into the empty space!
    else
      eval newy %coordinatey% + 1
      eval tiletomove Cord%coordinatex%%newy%
    endif

  else
    %send% %actor% This is not a valid move command. As a reminder, the board looks like this.
  endif

  *Check if previously we had a valid move. Means variable %tiletomove% must exist

  if %tiletomove%
    eval emptytile Cord%coordinatex%%coordinatey%
    eval tmp1 %%%tiletomove%%%
    eval tmp2 %%tiletomove%%
    eval tmp3 %%emptytile%%

    *update coordinates respectively
    if %newx%
      set coordinatex %newx%
    elseif %newy%
      set coordinatey %newy%
    endif

    set %tmp2% EE
    set %tmp3% %tmp1%

    remote coordinatex %self.id%
    remote coordinatey %self.id%

    *Here, we are actually updating the variable cordXY
    remote %tmp2% %self.id%
    remote %tmp3% %self.id%
  endif

  if !%visimp% || %visimp% == 0
    set border -------------------------
    set inbet |     |     |     |     |
    %send% %actor% %border%
    %send% %actor% %inbet%
    %send% %actor% | %Cord11%  | %Cord12%  | %Cord13%  | %Cord14%  |
    %send% %actor% %inbet%
    %send% %actor% %border%
    %send% %actor% %inbet%
    %send% %actor% | %Cord21%  | %Cord22%  | %Cord23%  | %Cord24%  |
    %send% %actor% %inbet%
    %send% %actor% %border%
    %send% %actor% %inbet%
    %send% %actor% | %Cord31%  | %Cord32%  | %Cord33%  | %Cord34%  |
    %send% %actor% %inbet%
    %send% %actor% %border%
    %send% %actor% %inbet%
    %send% %actor% | %Cord41%  | %Cord42%  | %Cord43%  | %Cord44%  |
    %send% %actor% %inbet%
    %send% %actor% %border%
  elseif %visimp% == 1
    %send% %actor% %Cord11%, %Cord12%, %Cord13%, %Cord14%
    %send% %actor% %Cord21%, %Cord22%, %Cord23%, %Cord24%
    %send% %actor% %Cord31%, %Cord32%, %Cord33%, %Cord34%
    %send% %actor% %Cord41%, %Cord42%, %Cord43%, %Cord44%
  endif
else
  %send% %actor% This is not a valid puzzle command.
  return 1
end

Offline erwin

  • Sr. Member
  • ****
  • Posts: 314
    • View Profile
Trigger of the .... something
« Reply #40 on: July 02, 2014, 12:07:47 pm »
This will be a post out of three posts, introducing functions, in order to achieve the goal of replacing characters of a sentence.

For example, given a string (of words, not sausages):

It was the best of times, it was the worst of times

and you want to replace the second letter of the tenth word by a u, eg to

It was the best of times, it was the wurst of times

how can you do so?

While this doesn't seem very useful from the sound of it, inventive scripters can script games (eg a game of battleship), by doing something like:

set grid .......... .......... .......... .......... .......... .......... .......... .......... .......... ..........

and if they want to fire at a position, and denote the fired position as an *, then the challenge is to convert 

.......... .......... .......... .......... .......... .......... .......... .......... .......... ..........

into

.......... .......... .......... .......... .......... .......... ...*...... .......... .......... ..........

for example.

Also, the best part about functions is that they can be reused again and again, and they just need to be called in the script. One idea is to have a zone full of (useful) functions, so all builders can call them (without taking up trigger vnums in their own zone), plus it gives some kind of signal to coders :P about which functions are useful to be added into the dg code.

As an aside, functions are very useful for doing the same things over and over again. If you have a main quest in a zone where the quest reward is only given when six side quests are done, you don't want to write the same script six times - to check if the main quest reward should be given when any of the six side quests have been completed.

So today's trigger of the day will focus on counting the number of "objects / words / items" in a variable. We will use this function in the next two posts to achieve our goal.

Input: findnumwords
Output: num

findnumwords will be the variable we are interested in finding the number of words of, and num the number of words.

Here is the function.

Code: [Select]
Name: 'function to check num words',  VNum: [33785], RNum: [ 2182]
Trigger Intended Assignment: Objects
Trigger Type: FUNCTION, Numeric Arg: 100, Arg list: None
Commands:
if !%findnumwords%
  %echo% We do not have any inputs!
  %echo% The input variable should be named findnumwords
  halt
endif
set stopping_criteria 1
set start 1
while %stopping_criteria% != stop
  extract num %start% %findnumwords%
  if !%num%
    eval num %start% - 1
    set stopping_criteria stop
  endif
  eval start %start% + 1
done

So to use the function, we just need to do this:

Code: [Select]
set findnumwords I want to be a pirate
function 33785
%echo% We have %num% of words

Of course, we can always do

Code: [Select]
set findnumwords %actor.thisvariable%
etc

The next post will be functions on replacing words in a sentence, and replacing characters in a word, before building up to the final post!
« Last Edit: July 02, 2014, 12:09:40 pm by erwin »

Offline erwin

  • Sr. Member
  • ****
  • Posts: 314
    • View Profile
Re: Trigger of the .... something
« Reply #41 on: July 03, 2014, 11:17:59 am »
Here is part 2, and it will be on function triggers to replace a word in a sentence, as well as to replace a character in a word.

Both function triggers are similar in execution, so hopefully it counts as one trigger of the day.

Some possibilities of these triggers (along with some modifications):

1. Make a mob rhyme with you (could replace / add on characters to the last word you say)
2. Dynamic passwords to go through a zone: (eg the second word of the password is always the day of the week)
3. Script a lot of (multi-player) games which rely on grids.

Anyway, here are these triggers!

The first trigger replaces a word in a sentence, as shown below.

Code: [Select]
Name: 'Replace word in sentence',  VNum: [33783], RNum: [ 2181]
Trigger Intended Assignment: Objects
Trigger Type: FUNCTION, Numeric Arg: 100, Arg list: None
Commands:
if !%sentence%
  %echo% Need a sentence to replace words.
  halt
endif

If !%word%
  %echo% Need a word to replace a word in the sentence.
  halt
endif

if !%replacenum%
  %echo% Need the position of the word to replace
  halt
endif

*First, find out how long the sentence is
*Recall our previous function took in the input findnumwords

set findnumwords %sentence%
function 33785

*We now have %num%, which is the length of the sentence
*Now we build up the sentence from the original sentence

if %replacenum% > 1
  extract newsentence 1 %sentence%
  set h 2
  while %h% < %replacenum%
    extract buildsentence %h% %sentence%
    set newsentence %newsentence% %buildsentence%
    eval h %h% + 1
  done
  set newsentence %newsentence% %word%
  eval h %h% + 1
elseif %replacenum% == 1
  set newsentence %word%
  set h 2
endif
while %h% <= %num%
  extract buildsentence %h% %sentence%
  set newsentence %newsentence% %buildsentence%
  eval h %h% + 1
done

This trigger takes in the inputs: sentence, replacenum, word.

sentence - Should be set to the sentence you are looking at
replacenum - The position number of the word you want to replace
word - The new word

The trigger gives the output: newsentence

So for example, suppose you have the phrase:

I am at the bottom of the world

and you want to replace the fifth word with the word top.

Then, you would do something like:

Code: [Select]
set sentence I am at the bottom of the world.
set word top
set replacenum 5
function 33783
%echo% %newsentence%

and you get your new sentence to be: I am at the top of the world

The second trigger replaces a character in a word.

Code: [Select]
Name: 'Replace character in word',  VNum: [33782], RNum: [ 2180]
Trigger Intended Assignment: Objects
Trigger Type: FUNCTION, Numeric Arg: 100, Arg list: None
Commands:

if !%word%
  %echo% Need a word to replace characters.
  halt
endif

If !%character%
  %echo% Need a character to replace a character in the sentence.
  halt
endif

if !%replacenum%
  %echo% Need the position of the word to replace
  halt
endif


set len %word.strlen%

*We now have %len%, which is the length of the word
*Now we build up the word from the original word

if %replacenum% > 1
  dg_letter newword 1 %word%
  set h 2
  while %h% < %replacenum%
    dg_letter buildword %h% %word%
    set newword %newword%%buildword%
    eval h %h% + 1
  done
  set newword %newword%%character%
  eval h %h% + 1
elseif %replacenum% == 1
  set newword %character%
  set h 2
endif
while %h% <= %len%
  dg_letter buildword %h% %word%
  set newword %newword%%buildword%
  eval h %h% + 1
done

This trigger takes in the following inputs: word, replacenum, character.

word - Should be set to the word you are looking at
replacenum - The position number of the character you want to replace
character - The new character

The trigger gives the output: newword

So for example, if you have the word

Candyland

and want something a bit more R rated, you could do the following:

Code: [Select]
set word Candyland
set character R
set replacenum 1
function 33782
%echo% newword
« Last Edit: July 03, 2014, 11:22:44 am by erwin »

Offline Kvetch

  • Administrator
  • Hero Member
  • *****
  • Posts: 729
    • View Profile
    • Email
Re: Trigger of the .... something
« Reply #42 on: August 03, 2014, 01:03:21 pm »
I got this script from a visitor from TBA that was asked to help out on another zone.  I've left in all of her comments on it even before the script because it all sounded like valuable information when dealing with the script.  This should be able to be adapted for any cooking anyone wants to do.  So, from Parnassus:

I've tried this on TBA and it seems to work.  First, you need to decide where to put it.  If you put it on a room, such as a kitchen,  or a mob, such as a cooking teacher, Numeric Arg is 100.  If you put it on something like a pot or a skillet, Numeric Arg is 2 (in inventory)  or a heatsource, such as a stove should be 4 (in the same room).

Next, set the vnums.  Each ingredient and each food needs a vnum.  On TBA, I just used various foods that seemed similar, just for experimenting with.

If it works the way you wanted it, create the items.  I've set up recipes for various dishes with an explanation of the bonus of each dish.  Wisdom is missing since I couldn't think of anything but the dishes I have probably don't seem connected either, such as Mario's mushrooms for a constitutional boost.  I'd have liked a nice dish of brains but I don't think that's an ingredient on 4d.  Of course though, the trigger is extremely expandable by inserting new ingredients in one section and recipes in two sections.

If you need any changes, let me know.  If it isn't what you were looking for at all, let me know that too.  I can think of places to use it so it won't be wasted if you can't use it.  One change might be to add a list of missing ingredients.  I was thinking of that but it would add about 3 to 5 lines to each recipe as well as another 5 to 10 lines in the error section.

If you try to /fi this, it won't format.  I think this is because of the mix of ifs/ends and switches/breaks.  I've tried to pre-format it in sections for easier reading.

1) Name         : Cooking
2) Intended for : Objects
3) Trigger types: Command
4) Numeric Arg  : 2
5) Arguments    : cook
6) Commands:
* Prep work - ingredients
* Insert proper vnums here.
set ing_almonds
set ing_cocoa
set ing_carrots
set ing_cheese
set ing_eggs
set ing_fish
set ing_flour
set ing_garlic
set ing_lemon
set ing_mushroom
set ing_potato
set ing_spinach
set ing_sugar
* Prep work - finished dishes
*Insert proper vnums here.
set dish_quiche
set dish_pancake
set dish_fish
set dish_mushroom
set dish_cake
set dish_fritter
* Prep work - recipes
set quiche _spinach _quiche
if %quiche.contains(_%arg%)%
  set food spinach quiche
  set quan a
end
set pancake _potato _pancakes
if %pancake.contains(_%arg%)%
  set food potato pancakes
  set quan some
end
set fish _fish _almondine
if %fish.contains(_%arg%)%
  set food fish almondine
  set quan some
end
set mushrooms _stuffed _mushrooms
if %mushrooms.contains(_%arg%)%
  set food stuffed mushrooms
  set quan some
end
set cake _chocolate _cake
if %cake.contains(_%arg%)%
  set food chocolate cake
  set quan a
end
set fritter _carrot _fritters
if %fritter.contains(_%arg%)%
  set food carrot fritters
  set quan some
end
** Start of Heatsource check
* If the trigger is on a room or a heatsource, delete this section.
* If the trigger is on an object, verify numeric arg.
* Numeric Arg 2 is in inventory, such as a pot.  Numeric Arg 4 is in the same room, such as a stove.
  set heatsource 0
  eval inroom %self.room%
  eval obj %inroom.contents%
  * find the first object in the room
  while %obj%
    set next_obj %obj.next_in_list%
    set objlist %obj.name%
  if %objlist.contains(fire)% || %objlist.contains(stove)% || %objlist.contains(oven)%
  eval heatsource heatsource + 1
  end
  * find the next object for the while to loop
  set obj %next_obj%
  done
if %heatsource% == 0
%send% %actor% You can't find any heat to cook with.
halt
end
** End of Heatsource check
switch %food%
  case spinach quiche
    * Strength - spinach quiche - eggs spinach cheese
    set ing1 %ing_cheese%
    set ing2 %ing_eggs%
    set ing3 %ing_spinach%
    set dishvnum %dish_quiche%
  break
  case potato pancakes
    * Dexterity - potato pancakes - potato eggs flour
    set ing1 %ing_eggs%
    set ing2 %ing_flour%
    set ing3 %ing_potato%
    set dishvnum %dish_pancake%
  break
  case fish almondine
    * Intelligence - fish almondine - fish almonds lemon
    set ing1 %ing_almonds%
    set ing2 %ing_fish%
    set ing3 %ing_lemon%
    set dishvnum %dish_fish%
  break
  case stuffed mushrooms
    * Constitution - stuffed mushrooms - mushrooms garlic cheese
    set ing1 %ing_cheese%
    set ing2 %ing_garlic%
    set ing3 %ing_mushroom%
    set dishvnum %dish_mushroom%
  break
  case chocolate cake
    * Charisma -  chocolate cake - flour sugar cocao
    set ing1 %ing_cocoa%
    set ing2 %ing_flour%
    set ing3 %ing_sugar%
    set dishvnum %dish_cake%
  break
  case carrot fritters
    * Night vision - carrot fritters - carrots flour eggs
    set ing1 %ing_carrots%
    set ing2 %ing_eggs%
    set ing3 %ing_flour%
    set dishvnum %dish_fritter%
  break
  default
    %send% %actor% You don't seem to know how to cook that.
    halt
  break
done
if %actor.has_item(%ing1%)% && %actor.has_item(%ing2%)% && %actor.has_item(%ing3%)%
  %send% %actor% You cook up %quan% %food%.
  %echoaround% %actor% %actor.name% cooks up %quan% %food%.
  %purge% %actor.inventory(%ing1%)%
  %purge% %actor.inventory(%ing2%)%
  %purge% %actor.inventory(%ing3%)%
  %load% obj %ing1%
  %load% obj %ing2%
  %load% obj %ing3%
  %load% obj %dishvnum% %actor% inv
else
  %send% %actor% You don't have what you need to make %quan% %food%.
  halt
end

Offline erwin

  • Sr. Member
  • ****
  • Posts: 314
    • View Profile
Re: Trigger of the .... something
« Reply #43 on: December 28, 2014, 08:28:09 pm »
A nice way of repeating (mostly) similar stuff. For example, suppose you have a zone that echoes similar stuff like:

The flight to <random country> leaves at Gate <random number>. You could do something like switching cases. But a cooler way would be to do something like

Code: [Select]
set vec1 Heathrow Moscow Edinburgh Frankfurt Dublin Paris Newark LAX Minneapolis Georgia Hell Amsterdam Sydney Salzburg Bratislava Japan Toronto
eval randnum1 %random.20%
eval randnum2 %random.17%
extract place %randnum2% %vec1%  *we're extracting a random city from the above vector
%echo% The flight to %place% leaves from Gate %randnum2%.
Tada! And you don't need to create 17 different cases for a minor change!

Offline erwin

  • Sr. Member
  • ****
  • Posts: 314
    • View Profile
Re: Trigger of the .... something
« Reply #44 on: October 24, 2015, 01:52:46 am »
What happens if we want to script a quest which went like this:

1. Give me grapes from Ancient Greece
2. Give me a laser gun
3. Give me a game

Well, most quests are specific, eg: "Give me grapes from Imbros, give me a 4D laser gun, give me a Battleship game." But what if we wanted to make sure ALL possible items are valid? Well, we could add in if statements. However, this gets tricky when more and more zones are built, and thus more items are valid?

We show how we can do this with one quest array, and how builders can copy and paste the entire script below and adapt it to any such quest.

Let the questarray be an array with 4 variables. First 3 are yes/no variables, and the last denoting whether the quest has been completed before or not.

Here are examples of some arrays

Code: [Select]
* Example of quest not done
myquestvar: no no no incomplete
* Example of quest where first item and third item has been found, but player hasn't completed it
myquestvar: yes no yes incomplete
* Example of quest where player has completed it at least once before, and is trying again and he only gave the second item
myquestvar: no yes no complete

Now, here is the grand script.

Code: [Select]
**** CANDIDATE LIST
**** This quest accepts multiple possible items, so update this list
**** accordingly. For example, if someone typos that another item
**** might fit, then add in the new vnum to the array. This is the only
**** change you need! YEAH!

**** Number of different items needed
set numquests 3   

**** Item 1
set questitem1 12345 4205 14673
set msg1 Thanks for giving me questitem1

**** Item 2
set questitem2 1222 5070 5323 64325
set msg2 Thanks for giving me item 2!
   
**** Item 3
set questitem3 503 703
set msg3 Thanks buddy

*** This is it! Edit the above part when more items get added - the below will do everything for you
*** Msg is optional, could add more stuff, but you get the gist.

** We're going to loop through this

** Note: This is not the most efficient way of doing so, but
** we have relatively few quest items. If you want to re-use this code
** for substantially more vnums, one way is to order the arrays in
** increasing order, and do a binary search for appropriate vnums

if %actor.varexists(myquestvar)%
  set questvars %actor.myquestvar%
  eval statusnum %numquests% + 1
  extract status %statusnum% %questvars%
  set curritem %object.vnum%
 
  *First loop through all arrays. numquests quest items, so numquests arrays
  set arrnum 0
  while %arrnum% < %numquests%
    eval arrnum %arrnum% + 1
    extract itemarray %arrnum% %questvars%
    set item%arrnum% %itemarray%
    * read this array
   
    * Note: We have to eval this, and not set, otherwise it'll be a string
    eval currarray %%questitem%arrnum%%%
   
    * So for example, if arrnum was 1, then
    * currarray would be set to 12345 4205 14673 (value of questitem1)
    * %echo% %currarray%   
    * uncomment above to check!
   
    * Now, find the length of this array
    set stopping_criteria 1
    set start 1
    while %stopping_criteria% != stop
      extract num %start% %currarray%
      if !%num%
        eval num %start% - 1
        set stopping_criteria stop
      endif
      eval start %start% + 1
    done
   
    * We've got the length of the array stored as %num%
    * Now, loop through each item in the array
   
    set j 0
   
    while %j% < %num%
      eval j %j% + 1
      extract itemtocheck %j% %currarray%
     
      * Finally, we check if it's the same item as what we want
      if %curritem% == %itemtocheck%
        wait 1s
        mjunk %object%
        * Perfect, let's set the variable to yes
        set item%arrnum% yes
       
        * Again, eval and not set
        eval currmsg %%msg%arrnum%%%
        say %currmsg%
       
        * Set a variable gotcorrectitem because we want the mob to respond
        * if none of the items were right
        set gotcorrectitem yes   
      endif
     
    done           
  done
 
  * At the end of the loop, we need to do two things
  * If no right item was given, then
 
  if !%gotcorrectitem%
    wait 1
    say No, no, that's all wrong.
    say Try to get it right next time.
    mjunk %object%
    wait 2
    emo waves his hands and what you handed him disappears!
    halt
  endif
 
  * Now, we have to check if all 3 were achieved, and concurrently update
  * the new variable. Create loop to rebuild array, and count how many
  * correct items
 
  * Create new variable resetquest in case player gets all 3
 
  set j 0
  set counter 0
 
  while %j% < %numquests%
    eval j %j% + 1
    eval curritem %%item%j%%%
   
    if %curritem% == yes
      eval counter %counter% + 1
    endif
   
    if %j% == 1
      set myquestvar %curritem%
      set resetquest no
    else
      set myquestvar %myquestvar% %curritem%
      set resetquest %resetquest% no
    endif     
  done
 
 
  if %counter% < %numquests%
    * Can't set status to incomplete, but need to use previous
    * one, because player might have done quest before
    set myquestvar %myquestvar% %status%
  else
    * Note, got to reset quest, but must flag complete
    set myquestvar %resetquest% complete
    * Set complete quest sequence here

    %send% %actor% I reward thee!
  endif
  * Finally, don't forget to remote this
  remote myquestvar %actor.id%
else
  * If no questflag, giving should not do anything
  halt
endif

« Last Edit: October 24, 2015, 02:02:33 am by erwin »