16
General Discussions / Re: 4D
« on: December 22, 2015, 03:25:08 pm »
probably
This forum is very active and we are here to help.
Click here to get back to the main website: http://4dimensions.org
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
[ Room 76xx :: wdamage: bad syntax ]
has been fixed.helper_voucher_1: 1
helper_voucher_2: 1
helper_voucher_3: 1
helper_voucher_4: 1
helper_voucher_5: 1
helper_voucher: found found not_found found not_found
or helper_voucher: 1 0 1 1 0
crete_zone: not_killed_minotaur killed_theseus bullgirl_not_done
andcrete_zone: killed_minotaur killed_theseus bullgirl_done
set speecha1 thank you for the diamonds
set speechb1 blah blah love you
if %traded_item% != 0
*Great, no rejected items. Now to find which one
wait 1
mjunk %object%
say thank you!
wait 1
* Reward goes here, corresponding to the traded_item
set tp_reward %tp_reward_vec.wordat(%traded_item%)%
nop %actor.trade(%tp_reward%)%
eval d %actor.level%*%exp_reward_vec.wordat(%traded_item%)%
nop %actor.exp(%d%)%
* Halt this script if we have successfully traded!
halt
endif
set speecha1 thank you for the diamonds
set speechb1 blah blah love you
set speechc1 laa
if you wanted the mob to say three lines, for example. if %traded_item% != 0
*Great, no rejected items. Now to find which one
wait 1
mjunk %object%
say thank you!
wait 1
* Reward goes here, corresponding to the traded_item
set tp_reward %tp_reward_vec.wordat(%traded_item%)%
nop %actor.trade(%tp_reward%)%
eval d %actor.level%*%exp_reward_vec.wordat(%traded_item%)%
nop %actor.exp(%d%)%
if %traded_item% == 4
%echo% This is a special item! Do special stuff here
endif
* Halt this script if we have successfully traded!
halt
endif
set item1 111 112 113 114 120
set item2 200 201 214 206
set item3 300 301 333 399
set item4 400 420 490
set item5 500
set item6 666 669
set speecha1 thank you for the diamonds
set speechb1 blah blah love you
set tp_reward_vec 1 4 3 2 4 9
set exp_reward_vec 1000 3000 1000 1000 4000 4000
if %traded_item% != 0
*Great, no rejected items. Now to find which one
wait 1
mjunk %object%
* evals the correct speech corresponding to the traded item
eval tosaypartone %%speecha%traded_item%%%
eval tosayparttwo %%speechb%traded_item%%%
say %tosaypartone%
say %tosayparttwo%
wait 1
* Reward goes here, corresponding to the traded_item
set tp_reward %tp_reward_vec.wordat(%traded_item%)%
nop %actor.trade(%tp_reward%)%
eval d %actor.level%*%exp_reward_vec.wordat(%traded_item%)%
nop %actor.exp(%d%)%
* Halt this script if we have successfully traded!
halt
endif
eval tosaypartone %%speecha%traded_item%%%
eval tosayparttwo %%speechb%traded_item%%%
set tp_reward %tp_reward_vec.wordat(%traded_item%)%
nop %actor.trade(%tp_reward%)%
eval d %actor.level%*%exp_reward_vec.wordat(%traded_item%)%
nop %actor.exp(%d%)%
if %traded_item% != 0
*Great, no rejected items. Now to find which one
wait 1
mjunk %object%
* evals the correct speech corresponding to the traded item
eval tosaypartone %%speecha%traded_item%%%
eval tosayparttwo %%speechb%traded_item%%%
say %tosaypartone%
say %tosayparttwo%
wait 1
* Reward goes here, corresponding to the traded_item
set tp_reward %tp_reward_vec.wordat(%traded_item%)%
nop %actor.trade(%tp_reward%)%
eval d %actor.level%*%exp_reward_vec.wordat(%traded_item%)%
nop %actor.exp(%d%)%
* Halt this script if we have successfully traded!
halt
endif
set item2 200 201 214 206
and 206 is inside.if 2 != 0
*Great, no rejected items. Now to find which one
wait 1
mjunk %object%
* evals the correct speech corresponding to the traded item
eval tosaypartone %%speecha2%%
eval tosayparttwo %%speechb2%%
say %tosaypartone%
say %tosayparttwo%
wait 1
* Reward goes here, corresponding to the traded_item
set tp_reward %tp_reward_vec.wordat(2)%
nop %actor.trade(%tp_reward%)%
eval d %actor.level%*%exp_reward_vec.wordat(2)%
nop %actor.exp(%d%)%
* Halt this script if we have successfully traded!
halt
endif
if 2 != 0
*Great, no rejected items. Now to find which one
wait 1
mjunk %object%
* evals the correct speech corresponding to the traded item
eval tosaypartone thank you for the rubies
eval tosayparttwo blah blah love you
say %tosaypartone%
say %tosayparttwo%
wait 1
* Reward goes here, corresponding to the traded_item
* because 4 was the word at 2 for the tp_reward_vec
set tp_reward 4
nop %actor.trade(%tp_reward%)%
* because 3000 was the word at 2 for the exp_reward_vec
eval d %actor.level%*3000
nop %actor.exp(%d%)%
* Halt this script if we have successfully traded!
halt
endif
while %i% <= %max_items%
* look at first itemvec
* Need to eval this!
eval item_to_check %%item%i%%%
set j 1
while %j% != 0
extract curr_item %j% %item_to_check%
if !%curr_item%
* Loop will stop
set j 0
else
if %curr_item% == %currvnum%
set traded_item %i%
break
endif
eval j %j% + 1
endif
done
if %traded_item% != 0
eval i %max_items% + 1
endif
eval i %i% + 1
done
.contains
.wordat()
.strlen
replace_word
etc, because we don't know how to "script" the equivalent in DG. But we still use them anyway. For example, replace_word as a DG function is easy to understandset sentence This is a dog and it is barking
replace_word boy 4 %sentence%
will give This is a boy and it is barking. But not many of us will be able to script the equivalent in DG.set sentence This is a dog and it is barking
* want to replace boy in word 4
set word_to_replace boy
set num_at_replace 4
* After setting sentence, word_to_replace, num_at_replace, then:
* Find the maximum length of this sentence
set len 0
while %len%
eval len %len% + 1
extract tmp %len% %sentence%
if !%tmp%
break
endif
done
eval len %len% - 1
*len is now the length of the sentence (ie number of words)
extract newsentence 1 %sentence%
set i 2
while %i% < %num_at_replace%
extract nextword %i% %sentence%
set newsentence %newsentence% %nextword%
eval i %i% + 1
done
set newsentence %newsentence% %word_to_replace%
eval i %i% + 1
while %i% <= %len%
extract nextword %i% %sentence%
set newsentence %newsentence% %nextword%
eval i %i% + 1
done
set sentence This is a dog and it is barking
* want to replace that in word 1
set word_to_replace that
set num_at_replace 1
* After setting sentence, word_to_replace, num_at_replace, then:
* Find the maximum length of this sentence
set len 0
while %len%
eval len %len% + 1
extract tmp %len% %sentence%
if !%tmp%
break
endif
done
eval len %len% - 1
*len is now the length of the sentence (ie number of words)
if %num_at_replace% == 1
set newsentence %word_to_replace%
set i 2
else
extract newsentence 1 %sentence%
set i 2
while %i% < %num_at_replace%
extract nextword %i% %sentence%
set newsentence %newsentence% %nextword%
eval i %i% + 1
done
set newsentence %newsentence% %word_to_replace%
eval i %i% + 1
endif
while %i% <= %len%
extract nextword %i% %sentence%
set newsentence %newsentence% %nextword%
eval i %i% + 1
done
replace_word
replace_word
while %i% <= %max_items%
* look at first itemvec
* Need to eval this!
eval item_to_check %%item%i%%%
set j 1
while %j% != 0
extract curr_item %j% %item_to_check%
if !%curr_item%
* Loop will stop
set j 0
else
if %curr_item% == %currvnum%
set traded_item %i%
break
endif
eval j %j% + 1
endif
done
if %traded_item% != 0
eval i %max_items% + 1
endif
eval i %i% + 1
done
?replace_word blah 4 sentence
And you can read this as: "We are going to replace the 4th word of sentence by the word blah"blackboxloop 12345 item1 item2 item3
?blackboxloop 12345 item1 item2 item3 item4 item5 item6 item7 item8 item9 item10
?blackboxloop 12345 item2 item1 item3
, would it still return the right number? So maybe it's better if the loop was in DG instead of a function...
set item1 111 112 113 114 120
set speecha1 thank you for the diamonds
set speechb1 blah blah love you
set item2 200 201 214 206
set speecha2 thank you for the rubies
set speechb2 blah blah love you
set item3 300 301 333 399
set speecha3 thank you for the garnets
set speechb3 blah blah love you
set item4 400 420 490
set speecha4 thank you for the sapphires
set speechb4 blah blah love you
set item5 500
set speecha5 thank you for the quartz
set speechb5 blah blah love you
set item6 666 669
set speecha6 thank you for the topaz
set speechb6 blah blah love you
set max_items 6
set tp_reward_vec 1 4 3 2 4 9
set exp_reward_vec 1000 3000 1000 1000 4000 4000
set rej_item1 1000 1005 1110
set rej_speech1 I don't want fool's gold.
set rej_item2 2000 2222
set rej_speech2 I don't want iron pyrite.
set rej_max_items 2
set currvnum %object.vnum%
* Loop for traded_item function
function 122
if %traded_item% != 0
*Great, no rejected items. Now to find which one
wait 1
mjunk %object%
* evals the correct speech corresponding to the traded item
eval tosaypartone %%speecha%traded_item%%%
eval tosayparttwo %%speechb%traded_item%%%
say %tosaypartone%
say %tosayparttwo%
wait 1
* Reward goes here, corresponding to the traded_item
set tp_reward %tp_reward_vec.wordat(%traded_item%)%
nop %actor.trade(%tp_reward%)%
eval d %actor.level%*%exp_reward_vec.wordat(%traded_item%)%
nop %actor.exp(%d%)%
* Halt this script if we have successfully traded!
halt
endif
* If traded_item is zero, then it's a rejected item
return 0
wait 1
emote makes a refusing gesture.
* Loop for rejected items
function 125
if %rej_traded_item% != 0
eval tosay %%rej_speech%rej_traded_item%%%
say %tosay%
halt
else
say This is a generic statement saying I don't like your item.
endif
if %item.vnum% == 100 || %item.vnum% == 101
%send% %actor% Thank you for trading item number 100 or item 101!
%send% %actor% Let me give you a reward
elseif %item.vnum% == 103
%send% %actor% Thank you for trading item number 103!
%send% %actor% Let me give you a reward
elseif %item.vnum% == 105
%send% %actor% Thank you for trading item number 105!
%send% %actor% Let me give you a reward!
elseif %item.vnum% == 110 || %item.vnum% == 114 || %item.vnum% == 120
%send% %actor% Sorry, I don't take this type of items
%send% %actor% Go away!
endif
if %item.vnum% == "correct vnum"
mob gives some reward for the item
mob says thank you
endif
wait 1s
mjunk %object%
say thank you
give TP reward
give XP reward
10 items would mean 50 lines of duplicated code. This takes up a lot of space. Can we do better? (yes).* First, set the number of items that the mob trades. Suppose the mob is a jeweller, and trades the six items only
* The numbers correspond to the correct vnums
* Speech is optional - could have lots of variables for this, just make sure the last "character" of the speech is the
* same number of the item. But if you want the mob to say the same thing for each item
* then in the loop below, could just "say thank you".
* Item 1 corresponds to diamonds
set item1 111 112 113 114 120
set speecha1 thank you for the diamonds
set speechb1 blah blah love you
* Item 2 corresponds to rubies
set item2 200 201 214 206
set speecha2 thank you for the rubies
set speechb2 blah blah love you
* Item 3 corresponds to garnets
set item3 300 301 333 399
set speecha3 thank you for the garnets
set speechb3 blah blah love you
* Item 4 corresponds to sapphires
set item4 400 420 490
set speecha4 thank you for the sapphires
set speechb4 blah blah love you
* Item 5 corresponds to quartz
set item5 500
set speecha5 thank you for the quartz
set speechb5 blah blah love you
* Item 6 corresponds to topaz
set item6 666 669
set speecha6 thank you for the topaz
set speechb6 blah blah love you
* Set the maximum items the mob trades, in this case 6
set max_items 6
* Set the rewards for each of them. So item 1 (diamonds) would get 1 TP and 1000 xp, and item 6 (topaz)
* would get 9 TP and 4000 xp
set tp_reward_vec 1 4 3 2 4 9
set exp_reward_vec 1000 3000 1000 1000 4000 4000
* You can set rejected items as well, for example, suppose the mob rejects fool's gold and iron pyrite
* rej_item 1 corresponds to fool's gold
set rej_item1 1000 1005 1110
set rej_speech1 I don't want fool's gold.
* rej_item 2 corresponds to iron pyrite
set rej_item2 2000 2222
set rej_speech2 I don't want iron pyrite.
* Set maximum number of rej items. In this case, 2
set rej_max_items 2
* Now comes the main part
set currvnum %object.vnum%
* We want to find which item it is, so we loop through all items (in item1 to item 6)
set traded_item 0
set i 1
while %i% <= %max_items%
* look at first itemvec
* Need to eval this!
eval item_to_check %%item%i%%%
set j 1
while %j% != 0
extract curr_item %j% %item_to_check%
if !%curr_item%
* Loop will stop
set j 0
else
if %curr_item% == %currvnum%
set traded_item %i%
break
endif
eval j %j% + 1
endif
done
if %traded_item% != 0
eval i %max_items% + 1
endif
eval i %i% + 1
done
* This will create a variable traded_item which will tell you what item it is
* For example, if traded_item is 4, then the player gave sapphires
* If the traded_item was 0, means it was none of the 6 possible items
if %traded_item% != 0
*Great, no rejected items. Now to find which one
wait 1
mjunk %object%
* evals the correct speech corresponding to the traded item
eval tosaypartone %%speecha%traded_item%%%
eval tosayparttwo %%speechb%traded_item%%%
say %tosaypartone%
say %tosayparttwo%
wait 1
* Reward goes here, corresponding to the traded_item
set tp_reward %tp_reward_vec.wordat(%traded_item%)%
nop %actor.trade(%tp_reward%)%
eval d %actor.level%*%exp_reward_vec.wordat(%traded_item%)%
nop %actor.exp(%d%)%
* Halt this script if we have successfully traded!
halt
endif
* If traded_item is zero, then it's a rejected item
return 0
wait 1
emote makes a refusing gesture.
* Check if it was either fool's gold or iron pyrite, same loop as above
set rej_traded_item 0
set i 1
while %i% <= %rej_max_items%
* look at first itemvec
* Need to eval this!
eval item_to_check %%rej_item%i%%%
set j 1
while %j% != 0
extract curr_item %j% %item_to_check%
if !%curr_item%
* Loop will stop
set j 0
else
if %curr_item% == %currvnum%
set rej_traded_item %i%
break
endif
eval j %j% + 1
endif
done
if %rej_traded_item% != 0
eval i %rej_max_items% + 1
endif
eval i %i% + 1
done
* same thing
if %rej_traded_item% != 0
eval tosay %%rej_speech%rej_traded_item%%%
say %tosay%
halt
else
say This is a generic statement saying I don't like your item.
endif
if %object.vnum% == 1000 || %object.vnum% == 1001 || %object.vnum == 1002
for every item. For example, did you notice in the code above, I left out a % in %object.vnum == 1002? Hard to spot such errors! However, with the above script, all a builder needs to do is to edit the first few lines. Fewer chances of mistakes.if !%actor.varexists(my_quest)%
set my_quest no_captain no_voucher no_rescue no_prog not_done
remote my_quest %actor.id%
endif
myquest: no_captain no_voucher no_rescue no_prog not_done
no_captain no_voucher no_rescue no_prog not_done var1 var2 var3
if !%actor.varexists(my_quest)%
set my_quest no_captain no_voucher no_rescue no_prog not_done var1 var2 var3
remote my_quest %actor.id%
elseif %actor.varexists(my_quest)%
* Basically, check to see if variables 6, 7, and 8 exist. If they don't exist,
* then wordat 6 and wordat 7 would be "null"
* Equivalently, could check the strlen.
set my_quest %actor.my_quest%
if %my_quest.wordat(6)% == %my_quest.wordat(7)%
*means old questflag, so let's rebuild
insert_word var1 6 my_quest
insert_word var2 7 my_quest
insert_word var3 8 my_quest
remote my_quest %actor.id%
endif
endif
if !%actor.varexists(my_quest)%
set my_quest no_captain no_voucher no_rescue no_prog not_done
remote my_quest %actor.id%
endif
my_quest: no_captain no_voucher no_rescue no_prog not_done
function 1
%echo% The room says: I will give you a quest.
set my_quest %actor.my_quest%
replace_word in_prog 4 my_quest
function 1
%echo% The room says: I will give you a quest.
set my_quest %actor.my_quest%
if %my_quest.wordat(4)% != in_prog
replace_word in_prog 4 my_quest
remote my_quest %actor.id%
endif
function 2
* If the actor did not have the variable, he has it now
set my_quest %actor.my_quest%
* replaces killed_captain with the first word in my_quest
replace_word killed_captain 1 my_quest
remote my_quest %actor.id%
function 2
* If the actor did not have the variable, he has it now
set my_quest %actor.my_quest%
if %my_quest.wordat(1)% != killed_captain
* replaces killed_captain with the first word in my_quest
replace_word killed_captain 1 my_quest
remote my_quest %actor.id%
endif
function 2
* If the actor did not have the variable, he has it now
set my_quest %actor.my_quest%
* Only sets the flag if actor started the quest - else killing the captain won't register, muahahahaha
if %my_quest.wordat(4)% == in_prog
* replaces killed_captain with the first word in my_quest
replace_word killed_captain 1 my_quest
remote my_quest %actor.id%
endif
function 2
set my_quest %actor.my_quest%
if %my_quest.wordat(1)% == killed_captain && %my_quest.wordat(2)% == got_voucher && %my_quest.wordat(3)% == rescued_dog
* yay, let's check
if %my_quest.wordat(5)% != done
* first time doing this quest
* %echo% great job, have this big reward
replace_word done 5 my_quest
else
%echo% You have done this before, so here's this small reward
endif
* now, reset all questflags (in practice, good to have this as a function as well)
replace_word 1 no_captain my_quest
replace_word 2 no_voucher my_quest
replace_word 3 no_rescue my_quest
replace_word 4 no_prog my_quest
remote my_quest %actor.id%
endif
set my_quest no_captain no_voucher no_rescue no_prog done
remote my_quest %actor.id%
but - be careful if you store other variables on this flag (eg, maybe whether a person has a zoneflag or not. Then it gets messy - so replace_word is the better option)