Advertisement
RaZgRiZ

Flag CMD 1.0 SVN

Apr 7th, 2012
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. // Function that allows you to loop through a given string's characters like
  2. // looplist does for an item's list, usage: /loopchar <var> [action]
  3. loopchar = [
  4.     loop $arg1 (strlen $arg2) [
  5.         @arg1 = (substr $arg2 $[@arg1] 1)
  6.         @arg3
  7.     ]
  8. ]
  9.  
  10. // Function to add 1 to given value and alias it back, usage: /++ <var>
  11. "++" = [$arg1 = (+ (getalias $arg1) 1)]
  12.  
  13.  
  14. // Conditional function that operates based on flags, and their order before executing given content.
  15. // usage: cmd <flags> [content]
  16. // example: cmd cmp [say hi] -- would say "hi" when you are connected, have master rights, and are playing.
  17. // note 1: each flag that comes back negative stops the script, to avoid notification spam.
  18. // note 2: the order the flags are used plays an important role in determining which error comes first.
  19. // note 3: all flags must be tested positive before the content is executed.
  20.  
  21. cmd = [
  22.     local tmp
  23.     tmp = 0
  24.     loopchar f $arg1 [
  25.         if (> $tmp -1) [
  26.             cases $f "m" [
  27.                 if (ismaster (getclientnum)) [++ tmp] [
  28.                     error "^f3You do not have master rights!"
  29.                     tmp = -1
  30.                 ]
  31.             ] "a" [
  32.                 if (isadmin (getclientnum)) [++ tmp] [
  33.                     error "^f3You do not have admin rights!"
  34.                     tmp = -1
  35.                 ]
  36.             ] "s" [
  37.                 if (isspectator (getclientnum)) [++ tmp] [
  38.                     error "^f3You can only do this while spectating!"
  39.                     tmp = -1
  40.                 ]
  41.             ] "p" [
  42.                 if (! (|| (isspectator (getclientnum)) $editing)) [++ tmp] [
  43.                     error "^f3You can only do this while playing!"
  44.                     tmp = -1
  45.                 ]
  46.             ] "c" [
  47.                 if (isconnected) [++ tmp] [
  48.                     error "^f3You can only do this while online"
  49.                     tmp = -1
  50.                 ]
  51.             ] "o" [
  52.                 if (! (isconnected)) [++ tmp] [
  53.                     error "^f3You can only do this while offline"
  54.                     tmp = -1
  55.                 ]
  56.             ] "e" [
  57.                 if $editing [++ tmp] [
  58.                     error "^f3You can only do this while in editmode!"
  59.                     tmp = -1
  60.                 ]
  61.             ] "r" [
  62.                 if (movierecording) [++ tmp] [
  63.                     error "^f3You can only do this while recording a movie!"
  64.                     tmp = -1
  65.                 ]
  66.             ] () [error "^f3Invalid command flag:" $f]
  67.         ]
  68.     ]
  69.     if (= $tmp (strlen $arg1)) arg2
  70. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement