Building & Scripting > Scripting Board

General Scripting Suggestions

<< < (2/5) > >>

Mordecai:

--- Code: ---if (IS_SET(SCRIPT_TYPES(sc), WTRIG_RANDOM) &&
          (!is_empty(world[IN_ROOM(ch)].zone) ||
           IS_SET(SCRIPT_TYPES(sc), WTRIG_GLOBAL)))
        random_mtrigger(ch);
    }
--- End code ---

That is the TBA mud code.

So yeah, checks the whole zone, not just the room.

Fizban:
*Fizban starts editing TBA's helpfiles.*

Fizban:
Seems people seem to repeat large chunks of script as well, mind the example below is an old script I believe, but it's certainly not the only of its kind, it's just one I noticed earlier and did rewrite and figured looking at the before and after might help others make their scripts shorter and easier to follow as well:

Before:


--- Code: ---wait 3
emote examines the item.
if (%object.vnum% == 4951)
  if (%object.count(4936)% == 8)
    wait 1
    mjunk %object%
    wait 1 s
    say Thank you, %actor.name%.
    say A pleasure to do business with you.
    emote hands over 2 tradepoints.
    nop %actor.trade(2)%
    if (%actor.level% < 10)
      eval a 10
    elseif %actor.level% > 45
      eval a 45
    else
      eval a %actor.level%
    endif
    eval b 0
    eval d 0
    while %b% < %a%
      set %actor.exp(4000)%
      eval d %d%+4000
      eval b %b%+1
      global b
      global d
    done
    %send% %actor% You have just gained %d% exp!
  else
    wait 1 s
    say I can only take full containers! This is wholesale, not retail.
    say All vegetables in it have to be of the right kind too!
    wait 2 s
    give %object% %actor.name%
    drop %object%
    say You go and get it right, and then come back again.
    give %object% %actor.name%
    drop %object%
    say You go and get it right, and then come back again.
  endif
elseif (%object.vnum% == 4952)
  if (%object.count(4937)% == 8)
    wait 1
    mjunk %object%
    wait 1 s
    say Thank you, %actor.name%.
    say A pleasure to do business with you.
    emote hands over 2 tradepoints.
    nop %actor.trade(2)%
    if (%actor.level% < 10)
      eval a 10
    elseif %actor.level% > 45
      eval a 45
    else
      eval a %actor.level%
    endif
    eval b 0
    eval d 0
    while %b% < %a%
      set %actor.exp(4000)%
      eval d %d%+4000
      eval b %b%+1
      global b
      global d
    done
    %send% %actor% You have just gained %d% exp!
  else
    wait 1 s
    say I can only take full containers! This is wholesale, not retail.
    say All vegetables in it have to be of the right kind too!
    wait 2 s
    give %object% %actor.name%
    drop %object%
    say You go and get it right, and then come back again.
    give %object% %actor.name%
    drop %object%
    say You go and get it right, and then come back again.
  endif
elseif (%object.vnum% == 4953)
  if (%object.count(4938)% == 8)
    wait 1
    mjunk %object%
    wait 1 s
    say Thank you, %actor.name%.
    say A pleasure to do business with you.
    emote hands over 2 tradepoints.
    nop %actor.trade(2)%
    if (%actor.level% < 10)
      eval a 10
    elseif %actor.level% > 45
      eval a 45
    else
      eval a %actor.level%
    endif
    eval b 0
    eval d 0
    while %b% < %a%
      set %actor.exp(4000)%
      eval d %d%+4000
      eval b %b%+1
      global b
      global d
    done
    %send% %actor% You have just gained %d% exp!
  else
    wait 1 s
    say I can only take full containers! This is wholesale, not retail.
    say All vegetables in it have to be of the right kind too!
    wait 2 s
    give %object% %actor.name%
    drop %object%
    say You go and get it right, and then come back again.
    give %object% %actor.name%
    drop %object%
    say You go and get it right, and then come back again.
  endif
elseif (%object.vnum% == 4954)
  if (%object.count(4939)% == 8)
    wait 1
    mjunk %object%
    wait 1 s
    say Thank you, %actor.name%.
    say A pleasure to do business with you.
    emote hands over 2 tradepoints.
    nop %actor.trade(2)%
    if (%actor.level% < 10)
      eval a 10
    elseif %actor.level% > 45
      eval a 45
    else
      eval a %actor.level%
    endif
    eval b 0
    eval d 0
    while %b% < %a%
      set %actor.exp(4000)%
      eval d %d%+4000
      eval b %b%+1
      global b
      global d
    done
    %send% %actor% You have just gained %d% exp!
  else
    wait 1 s
    say I can only take full containers! This is wholesale, not retail.
    say All vegetables in it have to be of the right kind too!
    wait 2 s
    give %object% %actor.name%
    drop %object%
    say You go and get it right, and then come back again.
    give %object% %actor.name%
    drop %object%
    say You go and get it right, and then come back again.
  endif
elseif (%object.vnum% == 4955)
  if (%object.count(4940)% == 8)
    wait 1
    mjunk %object%
    wait 1 s
    say Thank you, %actor.name%.
    say A pleasure to do business with you.
    emote hands over 2 tradepoints.
    nop %actor.trade(2)%
    if (%actor.level% < 10)
      eval a 10
    elseif %actor.level% > 45
      eval a 45
    else
      eval a %actor.level%
    endif
    eval b 0
    eval d 0
    while %b% < %a%
      set %actor.exp(4000)%
      eval d %d%+4000
      eval b %b%+1
      global b
      global d
    done
    %send% %actor% You have just gained %d% exp!
  else
    wait 1 s
    say I can only take full containers! This is wholesale, not retail.
    say All vegetables in it have to be of the right kind too!
    wait 2 s
    give %object% %actor.name%
    drop %object%
    say You go and get it right, and then come back again.
    give %object% %actor.name%
    drop %object%
    say You go and get it right, and then come back again.
  endif
elseif (%object.vnum%==4956||%object.vnum% == 4957||%object.vnum% == 4958||%object.vnum% == 4959)
  return 0 
  wait 1 s
  emote shakes his head, refusing to receive the item.
  say Talk to my colleage, Mrs DelAngelo, my hands are full right now.
  give %object% %actor.name%
  drop %object%
else
  wait 1
  say I do not trade in items like this.
  say I am only interested in freshly grown vegetables.
  say And they have to be delivered in the Official 4D Containers as well.
  give %object% %actor.name%
  drop %object%
endif
--- End code ---

After:


--- Code: ---wait 3
emote examines the item.
if %object.vnum% == 4951 || %object.vnum% == 4952 || %object.vnum% == 4953 || %object.vnum% == 4954 || %object.vnum% == 4955
  eval num %object.vnum% - 15
  if %object.count(%num%)% == 8
    wait 1
    mjunk %object%
    wait 1 s
    say Thank you, %actor.name%.
    say A pleasure to do business with you.
    emote hands over 2 tradepoints.
    nop %actor.trade(2)%
    if %actor.level% < 10
      eval exp 10 * 4000
    elseif %actor.level% > 45
      eval exp 45 * 4000
    else
      set exp %actor.level%
    end
    nop %actor.exp(%exp%)%
    %send% %actor% You have just gained %exp% exp!
  else
    wait 1 s
    say I can only take full containers! This is wholesale, not retail.
    say All vegetables in it have to be of the right kind too!
    wait 2 s
    give %object.name% %actor.name%
    drop %object.name%
    say You go and get it right, and then come back again.
    give %object.name% %actor.name%
    drop %object.name%
    say You go and get it right, and then come back again.
  end
elseif %object.vnum%==4956 || %object.vnum% == 4957 || %object.vnum% == 4958 || %object.vnum% == 4959
  return 0 
  wait 1 s
  emote shakes his head, refusing to receive the item.
  say Talk to my colleague, Mrs DelAngelo, my hands are full right now.
else
  return 0
  wait 1
  say I do not trade in items like this.
  say I am only interested in freshly grown vegetables.
  say And they have to be delivered in the Official 4D Containers as well.
end
--- End code ---

Mordecai:

--- Code: ---  else
    wait 1 s
    say I can only take full containers! This is wholesale, not retail.
    say All vegetables in it have to be of the right kind too!
    wait 2 s
    give %object.name% %actor.name%
    drop %object.name%
    say You go and get it right, and then come back again.
    give %object.name% %actor.name%
    drop %object.name%
    say You go and get it right, and then come back again.
  end
--- End code ---

    give %object.name% %actor.name%
    drop %object.name%
    say You go and get it right, and then come back again.

Has that segment too that can be removed while refactoring.

%object.name% normally has multiple arguments, such as, 'small sword rusty'
So the script would actually be doing this:
give %object.name% %actor.name%
would be
give small sword rusty mordecai

So, it needs the keyword TO added in.

give %object.name% to %actor.name%

Since when you use the keyword TO it handles multiple arguments on either side.

IE:
Give fluffy kitten to black spider

Leonardo:
I'd also replace the %actor.name% var with %actor%
Since the actor may be having a clone following, or a mob with his same name in the room.
give %object.name% to %actor% would be the perfect solution.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version