91
Scripting Board / Re: Trigger of the .... something
« 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.
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:
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.
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:
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