Thursday, May 9, 2013

Tearing Apart Triggers - DG Scripts 2

I'm going to take this entire thing apart, line by line, to see if I understand everything that's going on here. PC stands for Player Character throughout this. This trigger was provided by Rumble of tbaMUD, and more like it can be found at tbaMUD.com! :D

Also, I apologize for the mess. The line wraps make this kind of difficult to read. :(


Name: 'Horse Petshop - 203',  VNum: [  338], RNum: [  259]
Trigger Intended Assignment: Mobiles
Trigger Type: Command , Numeric Arg: 100, Arg list: *
(This is saying that the trigger affects a mobile, issues a command (or multiple) to that mobile, fires 100% of the time, and queries all commands sent (the * for Arg list).)
Commands:
if %cmd.mudcommand% == list
  *
  %send% %actor%
  %send% %actor%  ##   Pet                       Cost
  %send% %actor% ------------------------------------
  %send% %actor%   1)  a horse                   1500
  %send% %actor%   2)  a fine mare               1800
  %send% %actor%   3)  a stallion                3000
  (For this section, If the command entered into the MUD matches "list" exactly, send the PC these lines of text, designed to mimic a true shop.)
   *
elseif %cmd.mudcommand% == buy
(If the command is buy, instead of list...)
  if %actor.gold% < 1500
  (First, check if the PC has less than 1500 coins)
    tell %actor.name% You have no money, go beg somewhere else.
    halt
    (If they do have less than 1500 coins, send this line, and stop the trigger.)
  elseif %actor.follower% && !%follower.is_pc%
   (This line is meant to keep the PC from having more than 1 pet. If the PC has more than 1500 coins, has someone following them, and that follower is NOT a PC (exclamation point is negation.))
    tell %actor.name% You already have someone following you.
    halt
    (Send the PC this message and stop the trigger)
  end
  (Ends the If statement that determines if the PC is too poor to purchase a horse. If both of the above statements are true (the PC has over 1500 coins AND the PC does not have an NPC follower), the trigger is allowed to continue.)
  if horse /= %arg% || %arg% == 1
  (Here is where it gets fun. This checks if "horse"OR 1 are substrings of the argument/command. The argument has to begin with "buy" or the trigger won't execute this section.)
    set pet_name horse
    set pet_vnum 202
    set pet_cost 1500
    (If either of the above two are true (argument is "buy horse" or "buy 1"), set the following variables: pet_name = horse, pet_vnum = 202, pet_cost = 1500)
  elseif fine /= %arg% || mare /= %arg% || %arg% == 2
  (If the command does not include horse or 1: then check if "mare" is a substring of the argument/command OR if the argument/command is 2)
    set pet_name mare
    set pet_vnum 204
    set pet_cost 1800
    (If it is, set the following variables: pet_name = mare, pet_vnum = 204, pet_cost = 1800)
  elseif stallion /= %arg% || %arg% == 3
  (If the command does not include horse, mare, 1, or 2: then check if "stallion" is a substring of the argument/command OR if the argument/command is 3)
    set pet_name stallion
    set pet_vnum 205
    set pet_cost 3000
    (If it is set the following variables: pet_name = stallion, pet_vnum = 205, pet_cost = 3000)
  else
  (If the argument has anything in it other than those three things (horse, mare, stallion; 1, 2, 3))
    tell %actor.name% What? I don't have that.
    halt
    (Send this message and stop the trigger)
  end
  (End the if statement determining what item is being bought)
  *
  if %actor.gold% < %pet_cost%
  (Check if the PC's total amount of coins is less than the cost of the horse)
   tell %actor.name% You don't have enough gold for that.
   (If the PC has less coins than is needed to buy the horse, send this line of text)
  else
    %load% mob %pet_vnum%
    %force% %pet_name% mfollow %actor%
    dg_affect %pet_name% charm on 999
  (If the PC DOES have enough coins to buy the horse, the "transaction" begins by loading the proper horse's vnum (which is determined by the variables set a few lines ago), and then forcing the horse to follow the PC. Then, a charm effect is cast upon the horse, so that it will obey the PC's commands) (This is actually where I'm having trouble. The follow command doesn't seem to work... That's my project, today...)
    emote opens the stable door and returns leading your horse by its reins.
    (This makes it LOOK like the stablemaster is opening a door and leading the horse to you. This only fires after the mob is loaded.)
    tell %actor.name% Here you go. Treat'em well.
    nop %actor.gold(-%pet_cost%)%
    (Finalize the transaction by having the mob take the PC's coins. This is a simple expression of x-y, where x is how much gold the PC has total, and y is the cost of the pet, which tells the nop command what quantity of gold the PC has left)
  end
  (Finally ends the if statement that controls what to do if the command is "buy")
elseif %cmd.mudcommand% == sell
  tell %actor.name% Does it look like I buy things?
  (If the command is not "list" or "buy", send this line of text)
else
  return 0
  (If the command is none of these things, return 0, which allows any other command sent and not stopped by the trigger. It's kind of hard for me to explain.)
end
(End the entire trigger. Phew!)

No comments:

Post a Comment