Recent Posts

Pages: 1 ... 6 7 [8] 9 10
71
Scripting Board / Re: Trigger of the .... something
« Last post by erwin 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

72
Scripting Board / Re: Card Game Functions
« Last post by erwin on October 24, 2015, 12:47:34 am »
Hmm..is there still the 8-10 page limit for triggers? I'd wager scripting complicated card games would take a lot more pages without using functions :(
73
Scripting Board / Re: Card Game Functions
« Last post by rynald on October 23, 2015, 03:10:07 pm »
An other way would be to use a command trigger for every game. You can put them on a dealer mob or on the room.
If the game is a global:

Code: [Select]
eval game poker
global game

then each trigger can check if the game is equal to the one they handle:

Code: [Select]
if %self.game% == poker
  if %cmd% == bid
    ...
  elseif %cmd% == fold
    ...
  else
    return 0
else
  return 0

A card can be a two character string: 2C, AS, 1D (10 of diamonds). You can check for the suit and number with dg_letter:

Code: [Select]
eval card 3S
dg_letter num 1 %card%
dg_letter suit 2 %card%

It's probably best to let a function check whether the number of one card is higher than another.

The dealer starts with a deck of 52 cards, that can be made when a player asks to start a game:

"start poker bob mary james"

Code: [Select]
eval numcards 52
eval card1 2H
eval card2 3H
...
eval card52 AS
eval i 1
while %i% < 53
  global card%i%
  eval i %i% + 1
done

The dealer's cards are in context 0, the player cards can be put in their own context when they are dealt at random:

Code: [Select]
eval player 1
while %player% <= 3
  eval i 1
  while %i% <= 5
    # pick random card
    eval c %%random.%numcards%%%
    eval card %%card%c%%%
    # add card to player
    context %player%
    eval numcards %self.numcards% + 1
    global numcards
    eval card%numcards% %card%
    global card%numcards%
    # remove card from dealer
    context 0
    eval card%c% %%card%self.numcards%%%
    global card%c%
    eval numcards %numcards% - 1
    global numcards
    eval i %i% + 1
  done
  eval player %player% + 1
done

I'm not sure about using context, but it makes sense in this case so you can use the same names.
74
Scripting Board / Re: Card Game Functions
« Last post by erwin on October 18, 2015, 04:26:39 pm »
Function 14: Checking if player has these cards

Takes in an input of the player, and checks if he/she has that card in his / her hand, given either the inputs:

Code: [Select]
ArrangedBySuitSuits
ArrangedBySuitNums

or

Code: [Select]
ArrangedByNumSuits
ArrangedByNumNums

and the input

Code: [Select]
maxnum
Using "place" as the command word, possible inputs would be:

place 4D 4H 4H
place 4D 4H
place 4D 8H JS AS
place 4D 7H AA BB

Function will check if the player has these cards (note duplicates, invalid cards, and card placement more than maxnum must not be allowed), and returns an output (string) either yes/no.

Function 15: An extension of Function 14, to REMOVE the valid cards in a player's hand, and returns a smaller Array of cards.

75
Scripting Board / Card Game Functions
« Last post by erwin on October 18, 2015, 04:00:34 pm »
There's been talk about scripting card games (here, a standard deck of 52 cards), and I think it would be nice to consolidate all functions we would need for all possible card games. This means reusable functions for games (not just limited to Poker).

Since there are two main types of games (suit taking games - easier to script), and hand winning games (pairs, two pairs, straights, etc - harder to script), here's what I propose for functions in order to build such games. Feel free to add / suggest better functions, with the idea that "using these functions will allow anyone to script any kind of card game - not just limited to poker / hearts"

1. A shuffle function

with two inputs. These inputs are two (variables) arrays, corresponding to

Code: [Select]
SuitArray:  2 3 4 5 6 7 8 9 10 J K Q A 2 3 4 5 ....
NumArray: C C C ... C D  .. D S .. S  H .. H

The function SHUFFLES these cards, and gives the shuffled output as two arrays:

Code: [Select]
ShuffledSuitArray:  ....
ShuffledNumArray: ....

The purpose of this function is to shuffle cards randomly. Scripts can be used to "divide" the shuffled cards up according to player.

2. An "arrangement" function.

Takes two inputs SuitArray and NumArray (both must be of the same length, but not necessarily 52. These would correspond to cards in a 2 player game (26 each)  4 player game (13 each), poker (5 each), etc).

Gives four outputs, namely:

Code: [Select]
ArrangedBySuitSuits:  C C C D D
ArrangedBySuitNums: 4 5 6 2 8
ArrangedByNumSuits: 2 4 5 6 8
ArrangedByNumNums: D C C C D


The purpose of this function is to cater for different type of games, where arranging by numbers / arranging by suits would be more convenient.

3. A "presentation" function for the above arrangement. Basically, the function takes in any of the above four inputs, and presents the cards to the players in a readable way. This will probably differ based on the type of game


Functions 4-12

With the above three functions, we can now customize our functions. For hand winning games, I suggest scripting the nine functions which correspond to the nine poker hands - Straight Flush, etc ... with the following four inputs - note that this function is NOT restricted to 5 elements in an array. Obviously with checks, eg, can't get a Flush if you had only 3 cards to compare, etc:

Code: [Select]
FirstPlayerSuit   H H H S S
FirstPlayerNum  2 5 6  3 6
SecondPlayerSuit:  D D D D D
SecondPlayerNum: 4 5 6 7 8

These functions would compare the hands of two players, and output a string with the player which has a higher hand. If neither player has a hand of that type, output null (or NA). Furthermore, make these 9 functions in running order - hopefully for some vnum xxx01 to xxx09 (for games which rely on placing a same poker hand, or one with higher value) - so if a person placed a hand of type 05, we can loop through for 06-09.


With the above 12 functions, we can script most games. For example, if we wanted to script a Poker Game, then we write a comparison function, eg below.

13. A comparison function. Given the arrays of X number of players, and an array PlayerName, eg:

Code: [Select]
XerxesSuit   H H H S S
XerxesNum  2 5 6  3 6
TorSuit:  D D D D D
TorNum: 4 5 6 7 8
ErwinSuit: C D H S C
ErwinNum: A 2 3 4 5

PlayerName: Xerxes Tor Erwin


run this function together with the previous 9 functions in order to see which player wins.

The logic would be: Run these functions from highest poker hand to lowest poker hand, until one poker hand is found. Compare with all other players to see who has the highest hand. Output the player name.


Any other functions do you think we need?









76
Scripting Board / Some very advanced scripts
« Last post by erwin on October 15, 2015, 09:54:21 am »
Some very advanced scripts.

I'm trying to create a document which details {more} advanced scripts, and with proper syntax as well - hopefully to give people ideas on what scripts can do. Any suggestions / ideas for scripts welcome. Particularly if you also provide the script :)
77
Scripting Board / Re: Scripted Quest Rewards you would like to see
« Last post by erwin on October 09, 2015, 02:51:24 pm »
thanks!
78
Scripting Board / Re: Scripted Quest Rewards you would like to see
« Last post by rynald on October 09, 2015, 02:46:39 pm »
When you have the id of something you can control it with makeuid:

Code: [Select]
makeuid mob %id%
%force% %mob% sit
%echo% %mob.room%
79
Scripting Board / Re: Scripted Quest Rewards you would like to see
« Last post by erwin on October 08, 2015, 06:20:22 pm »
Great, thanks :)

One more question: What would be needed if I wanted a pointer to a mob, in order to get the mob to do stuff?

Say for example, I created a mob (not necessarily a unique name), with unique ID 12345, and then:

Code: [Select]
set mobPointer %self.id%
remote mobPointer %actor.id%

The variable 12345 is stored on the player. However, if I wanted to do the following:

a) Force the mob to do something
b) Find the room the mob is in

what would the appropriate syntax be? At the moment, I've tried

Code: [Select]
%force% %mobPointer% jump
%echo% %%mobPointer%.room%

which admittedly doesn't work, since the number stored in mobPointer could represent a string / object / room / anything else instead - so I'm not even sure if I'm storing the right variable.

So yeah, what would I need to do to get this to work? Thanks again!



80
Scripting Board / Re: Scripted Quest Rewards you would like to see
« Last post by rynald on October 08, 2015, 01:03:13 pm »
The pages are online after all: http://old.tbamud.com/Oasis_DG_pages/.

There have been changes to scripting, but most of it still applies to our scripts.
Pages: 1 ... 6 7 [8] 9 10