Advertisement
RaZgRiZ

Flag CMD 1.0 Justice

Apr 7th, 2012
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 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 (getalias [@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.     _cmd_tmp = 0
  23.     loopchar f $arg1 [
  24.         if (> $tmp -1) [
  25.             cases $f "m" [
  26.                 if (ismaster (getclientnum)) [++ _cmd_tmp] [
  27.                     error "^f3You do not have master rights!"
  28.                     _cmd_tmp = -1
  29.                 ]
  30.             ] "a" [
  31.                 if (isadmin (getclientnum)) [++ _cmd_tmp] [
  32.                     error "^f3You do not have admin rights!"
  33.                     _cmd_tmp = -1
  34.                 ]
  35.             ] "s" [
  36.                 if (isspectator (getclientnum)) [++ _cmd_tmp] [
  37.                     error "^f3You can only do this while spectating!"
  38.                     _cmd_tmp = -1
  39.                 ]
  40.             ] "p" [
  41.                 if (! (|| (isspectator (getclientnum)) $editing)) [++ _cmd_tmp] [
  42.                     error "^f3You can only do this while playing!"
  43.                     _cmd_tmp = -1
  44.                 ]
  45.             ] "c" [
  46.                 if (isconnected) [++ _cmd_tmp] [
  47.                     error "^f3You can only do this while online"
  48.                     _cmd_tmp = -1
  49.                 ]
  50.             ] "o" [
  51.                 if (! (isconnected)) [++ _cmd_tmp] [
  52.                     error "^f3You can only do this while offline"
  53.                     _cmd_tmp = -1
  54.                 ]
  55.             ] "e" [
  56.                 if $editing [++ _cmd_tmp] [
  57.                     error "^f3You can only do this while in editmode!"
  58.                     _cmd_tmp = -1
  59.                 ]
  60.             ] () [error "^f3Invalid command flag:" $f]
  61.         ]
  62.     ]
  63.     if (= $_cmd_tmp (strlen $arg1)) arg2
  64. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement