游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2100|回复: 2

[讨论] 谁会用we里的jass编辑脚本!可否提供些案例看下

[复制链接]

9

主题

76

帖子

76

积分

注册会员

Rank: 2

积分
76
发表于 2006-8-12 12:16:00 | 显示全部楼层 |阅读模式
谁会用we里的jass编辑脚本!可否提供些案例看下,光看教程没太多营养。



41

主题

305

帖子

413

积分

中级会员

Rank: 3Rank: 3

积分
413
QQ
发表于 2006-8-12 21:16:00 | 显示全部楼层

Re:谁会用we里的jass编辑脚本!可否提供些案例看下

well,这是我以前写的一些脚本,可以作下参考。

  1. //===========================================================================
  2. function InitTrig_Base takes nothing returns nothing
  3. endfunction//===========================================================================
  4. // Trigger: Data conversion
  5. //
  6. // // 跳过某种字节数据
  7. // function ScanByte takes string sSrc, string byMatchs, integer iStart returns integer
  8. // // 反向跳过某种字节数据
  9. // function ScanByteRev takes string sSrc, string byMatchs, integer iStart returns integer
  10. // // 去掉首尾的某些字节
  11. // function StrTrim takes string sSrc, string byTrims, boolean bTrimStart, boolean bTrimEnd returns string
  12. // //任意进制转换
  13. // function ConvRadix takes integer v, integer iRadix returns string
  14. // //将任意进制字符串转为整数
  15. // function DecodeRadix takes string s, integer iRadix returns integer
  16. //===========================================================================
  17. // 跳过某种字节数据
  18. function ScanByte takes string sSrc, string byMatchs, integer iStart returns integer
  19.     local integer cbSrc = StringLength(sSrc)
  20.     local integer cbMatchs = StringLength(byMatchs)
  21.     local string  byCur
  22.     local integer I
  23.     local integer J
  24.     if cbSrc <= 0 then
  25.         return 0
  26.     endif
  27.     if iStart < 0 then
  28.         set iStart = 0
  29.     endif
  30.     if cbMatchs <= 0 then
  31.         return iStart
  32.     endif
  33.     set I = iStart
  34.     loop
  35.         exitwhen I >= cbSrc
  36.         set byCur = SubString(sSrc, I, I + 1)
  37.         set J = 0
  38.         loop
  39.             exitwhen J >= cbMatchs
  40.             exitwhen SubString(byMatchs, J, J + 1) == byCur
  41.             set J = J + 1
  42.         endloop
  43.         exitwhen J >= cbMatchs
  44.         set I = I + 1
  45.     endloop
  46.     return I
  47. endfunction

  48. // 反向跳过某种字节数据
  49. function ScanByteRev takes string sSrc, string byMatchs, integer iStart returns integer
  50.     local integer cbSrc = StringLength(sSrc)
  51.     local integer cbMatchs = StringLength(byMatchs)
  52.     local string  byCur
  53.     local integer I
  54.     local integer J
  55.     if cbSrc <= 0 then
  56.         return -1
  57.     endif
  58.     if iStart >= cbSrc then
  59.         set iStart = cbSrc - 1
  60.     endif
  61.     if cbMatchs <= 0 then
  62.         return iStart
  63.     endif
  64.     set I = iStart
  65.     loop
  66.         exitwhen I < 0
  67.         set byCur = SubString(sSrc, I, I + 1)
  68.         set J = 0
  69.         loop
  70.             exitwhen J >= cbMatchs
  71.             exitwhen SubString(byMatchs, J, J + 1) == byCur
  72.             set J = J + 1
  73.         endloop
  74.         exitwhen J >= cbMatchs
  75.         set I = I - 1
  76.     endloop
  77.     return I
  78. endfunction

  79. // 去掉首尾的某些字节
  80. function StrTrim takes string sSrc, string byTrims, boolean bTrimStart, boolean bTrimEnd returns string
  81.     local integer cbSrc = StringLength(sSrc)
  82.     local string sRet
  83.     local integer I
  84.     // Check: do nothing
  85.     if (cbSrc <= 0) or (StringLength(byTrims) <= 0) or ((false == bTrimStart) and (false == bTrimEnd)) then
  86.         return sSrc
  87.     endif
  88.     // Start
  89.     set sRet = sSrc
  90.     // Trim Start
  91.     if bTrimStart then
  92.         set I = ScanByte(sRet, byTrims, 0)
  93.         set sRet = SubString(sRet, I, cbSrc)
  94.     endif
  95.     // Trim End
  96.     if bTrimEnd then
  97.         set I = ScanByteRev(sRet, byTrims, StringLength(sRet))
  98.         set sRet = SubString(sRet, 0, I + 1)
  99.     endif
  100.     return sRet
  101. endfunction

  102. //任意进制转换
  103. function ConvRadix takes integer v, integer iRadix returns string
  104.     local string chSample = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZcefgjklmnorstuvyz!@#$&*()_+<>?=~,.:;[]{}"
  105.     local integer cbSample = StringLength(chSample)
  106.     local string sRet = ""
  107.     local boolean bSign = false
  108.     local integer n
  109.     local integer m
  110.     if (iRadix < 2) and (iRadix > cbSample) then
  111.         return ""
  112.     endif
  113.     if 0x80000000 == v then
  114.         return ""
  115.     endif
  116.     if v < 0 then
  117.         set v = - v
  118.         set bSign = true
  119.     endif
  120.     loop
  121.         set n = v / iRadix
  122.         set m = v - n * iRadix
  123.         set v = n
  124.         set sRet = SubString(chSample, m, m + 1) + sRet
  125.         exitwhen 0 == v
  126.     endloop
  127.     if bSign then
  128.         set sRet = "-" + sRet
  129.     endif
  130.     return sRet
  131. endfunction

  132. //将任意进制字符串转为整数
  133. function DecodeRadix takes string s, integer iRadix returns integer
  134.     local string  chSample = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZcefgjklmnorstuvyz!@#$&*()_+<>?=~,.:;[]{}"
  135.     local integer cbSample = StringLength(chSample)
  136.     local string  sSrc = StrTrim(s, " \t", true, false)
  137.     local integer cbSrc = StringLength(sSrc)
  138.     local integer iRet = 0
  139.     local string  byCur
  140.     local boolean bSign = false
  141.     local integer m = 0
  142.     local integer I
  143.     local integer J
  144.     if (iRadix < 2) and (iRadix > cbSample) then
  145.         return 0
  146.     endif
  147.     set I = 0
  148.     loop
  149.         exitwhen I >= cbSrc
  150.         set byCur = SubString(sSrc, I, I + 1)
  151.         set J = 0
  152.         loop
  153.             exitwhen J >= iRadix
  154.             exitwhen SubString(chSample, J, J + 1) == byCur
  155.             set J = J + 1
  156.         endloop
  157.         if J < iRadix then
  158.             set m = iRet * iRadix + J
  159.             exitwhen m < 0 // Overflow
  160.             set iRet = m
  161.         else
  162.             if (false == bSign) and ("-" == byCur) then
  163.                 set bSign = true
  164.             else
  165.                 exitwhen true
  166.             endif
  167.         endif
  168.         set I = I + 1
  169.     endloop
  170.     if bSign then
  171.         set iRet = -iRet
  172.     endif
  173.     return iRet
  174. endfunction











  175. //===========================================================================
  176. function InitTrig_Data_conversion takes nothing returns nothing
  177. endfunction

  178. //===========================================================================
  179. // Trigger: String
  180. //===========================================================================
  181. //将单个ASCII字符转为数字
  182. function AsciiCharToInteger takes string char returns integer
  183.     local string u = SubString(char, 0, 1)
  184.     local string c
  185.     local integer i = 0
  186.     if u == "" or u == null then
  187.         return 0
  188.     elseif u == "\b" then // BackSpace?
  189.         return 8
  190.     elseif u == "\t" then // Horizontal Tab?
  191.         return 9
  192.     elseif u == "\n" then // Newline?
  193.         return 10
  194.     elseif u == "\f" then // Form feed?
  195.         return 12
  196.     elseif u == "\r" then // Carriage return
  197.         return 13
  198.     endif
  199.     loop
  200.         set c = SubString(GetCharacterSet(), i, i + 1)
  201.         exitwhen c == ""
  202.         if c == u then
  203.             return i + 32
  204.         endif
  205.         set i = i + 1
  206.     endloop
  207.     return 0
  208. endfunction

  209. //将数字转为ASCII字符
  210. function AsciiIntegerToChar takes integer i returns string
  211.     if i == 0 then
  212.         return null
  213.     elseif i >= 8 and i <= 10 then
  214.         return SubString("\b\t\n", i - 8, i - 7)
  215.     elseif i >= 12 and i <= 13 then
  216.         return SubString("\f\r", i - 12, i - 11)
  217.     elseif i >= 32 and i <= 127 then
  218.         return SubString(GetCharacterSet(), i - 32, i - 31)
  219.     endif
  220.     return ""
  221. endfunction

  222. //获得字符串中某个字符的索引
  223. function IndexOfSubstring takes string text, string searchtext returns integer
  224.     local integer i = 1
  225.     if (StringLength(text) >= StringLength(searchtext)) then
  226.         loop
  227.             exitwhen (i > (StringLength(text) - StringLength(searchtext) + 1))
  228.             if (SubString(text,i-1,i + StringLength(searchtext) - 1) == searchtext) then
  229.                 return i - 1
  230.             endif
  231.             set i = i + 1
  232.         endloop
  233.     endif
  234.     return -1
  235. endfunction

  236. //将数字加密转换为字符串
  237. function Int2Alphanumeric takes integer int, string charmap returns string
  238.     local string alphanumeric = ""
  239.     local integer index = 0
  240.     if ((int < 0) or (int > 0x7FFFFFFF)) then
  241.         return "|cffff0000Invalid parameter passed to function Int2Alphanumeric()!|r"
  242.     endif
  243.     loop
  244.         set index = ModuloInteger(int, StringLength(charmap)) + 1
  245.         set int = int / StringLength(charmap)
  246.         set alphanumeric = SubStringBJ(charmap, index, index) + alphanumeric
  247.         exitwhen (int == 0)
  248.     endloop
  249.     return alphanumeric
  250. endfunction

  251. //将加密的字符串转换为数字
  252. function Alphanumeric2Int takes string str, string charmap returns integer
  253.     local integer int = 0
  254.     local integer index = 1
  255.     loop
  256.         set int = int + ( ( IndexOfSubstring( charmap, SubString(str, StringLength(str) - 1, StringLength(str)) ) ) * index )
  257.         exitwhen StringLength(str) == 1
  258.         set str = SubStringBJ( str, 1, StringLength(str) - 1 )
  259.         set index = index * StringLength(charmap)
  260.     endloop
  261.     return int
  262. endfunction

  263. //增加换行符号
  264. function StringAddNewLine takes string Str, integer index returns string
  265.     local string s = ""
  266.     local integer a = 1
  267.     loop
  268.         exitwhen a > StringLength(Str)
  269.         if ModuloInteger(a,index) == 0 then
  270.             set s = s + "\n"
  271.         endif
  272.         set s = s + SubString(Str,a-1,a)
  273.         set a = a + 1
  274.     endloop
  275.     return s
  276. endfunction

  277. //获得字符串的效检码
  278. function GetPassCodeCheckNumber takes string passcode returns integer
  279.     local integer index = 1
  280.     local integer check = 0
  281.     if passcode == "" and passcode == null then
  282.         return 0
  283.     endif
  284.     loop
  285.         exitwhen index > StringLength(passcode)
  286.        //数学算法,总之怎么乱怎么算老
  287.         set check = check + AsciiCharToInteger(SubString(passcode,index-1,index))/index*(index/2)
  288.         set index = index + 1
  289.     endloop
  290.     if StringLength(I2S(check)) > 3 then
  291.         return S2I(SubString(I2S(check),StringLength(I2S(check))-3,StringLength(I2S(check))))
  292.     endif
  293.     return check
  294. endfunction

  295. //根据效检码效对字符串
  296. function CheckPassCode takes string passcode ,integer checknumber returns boolean
  297.     return GetPassCodeCheckNumber(passcode) == checknumber
  298. endfunction

  299. //将object作为分解符号去分解字符串
  300. function SubStringForChar takes string s, string object,integer p returns string
  301.     local integer a = 1
  302.     local integer b = 1
  303.     local string array phase
  304.     set phase[b] = ""
  305.     loop
  306.         exitwhen a > StringLength(s)
  307.         if SubString(s, a-1, a) == object then
  308.             set b = b + 1
  309.             set phase[b] = ""
  310.         else
  311.             set phase[b] = phase[b]+SubString(s, a-1, a)
  312.         endif
  313.         set a = a + 1
  314.     endloop
  315.     if p > b then
  316.         return null
  317.     endif
  318.     return phase[p]
  319. endfunction

  320. //获得种族的介绍文本
  321. function GetRaceIntro takes integer raceN returns string
  322.     if raceN == 1 then
  323.         return GetElfIntro()
  324.     elseif raceN == 2 then
  325.         return GetHumanIntro()
  326.     elseif raceN == 3 then
  327.         return GetOrcIntro()
  328.     elseif raceN == 4 then
  329.         return GetUndeadIntro()
  330.     endif
  331.     return ""
  332. endfunction

  333. //获得角色的介绍文本
  334. //1-弓手 2-铁手 3-兵士 4-女巫 5-游士 6-战士 7-术士 8-地怪
  335. function GetRoleIntro takes integer RoleN returns string
  336.     if RoleN == 1 then
  337.         return GetGongShouIntro()
  338.     elseif RoleN == 2 then
  339.         return GetTieShouIntro()
  340.     elseif RoleN == 3 then
  341.         return GetBingShiIntro()
  342.     elseif RoleN == 4 then
  343.         return GetNvWuIntro()
  344.     elseif RoleN == 5 then
  345.         return GetYouShiIntro()
  346.     elseif RoleN == 6 then
  347.         return GetZhanShiIntro()
  348.     elseif RoleN == 7 then
  349.         return GetShuShiIntro()
  350.     elseif RoleN == 8 then
  351.         return GetDiGuaiIntro()
  352.     endif
  353.     return ""
  354. endfunction

  355. //判断字符是不是数字
  356. function IsNumber takes string Str returns boolean
  357.     local string number = "0123456789"
  358.     local integer a = 1
  359.     if Str == null or Str == "" then
  360.         return false
  361.     endif
  362.     loop
  363.         exitwhen a > StringLength(number)
  364.         if Str == SubString(number,a-1,a) then
  365.             return true
  366.         endif
  367.         set a = a + 1
  368.     endloop
  369.     return false
  370. endfunction

  371. //判断字符是不是小写
  372. function IsLowercase takes string Str returns boolean
  373.     local string lowercase = "abcdefghijklmnopqrstuvwxyz"
  374.     local integer a = 1
  375.     if Str == null or Str == "" then
  376.         return false
  377.     endif
  378.     loop
  379.         exitwhen a > StringLength(lowercase)
  380.         if Str == SubString(lowercase,a-1,a) then
  381.             return true
  382.         endif
  383.         set a = a + 1
  384.     endloop
  385.     return false   
  386. endfunction

  387. //判断字符是不是大写
  388. function IsCapitaliz takes string Str returns boolean
  389.     local string capitaliz = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  390.     local integer a = 1
  391.     if Str == null or Str == "" then
  392.         return false
  393.     endif
  394.     loop
  395.         exitwhen a > StringLength(capitaliz)
  396.         if Str == SubString(capitaliz,a-1,a) then
  397.             return true
  398.         endif
  399.         set a = a + 1
  400.     endloop
  401.     return false     
  402. endfunction

  403. //判断字符是不是标点
  404. function IsInterpunc takes string Str returns boolean
  405.     local string interpunc = " !\"#$%%&'()*+,-./:;<=>?@[\\]^_`{|}~"
  406.     local integer a = 1
  407.     if Str == null or Str == "" then
  408.         return false
  409.     endif
  410.     loop
  411.         exitwhen a > StringLength(interpunc)
  412.         if Str == SubString(interpunc,a-1,a) then
  413.             return true
  414.         endif
  415.         set a = a + 1
  416.     endloop
  417.     return false         
  418. endfunction
  419. //字符串着色
  420. function BatchStringColor takes string Str returns string
  421.     local integer a = 1
  422.     local string ReturnString =""
  423.     local string Temp = ""
  424.     local string TempNext = ""
  425.     local string TempUp = ""
  426.     loop
  427.         exitwhen a > StringLength(Str)
  428.         set Temp = SubString(Str,a-1,a)
  429.         set TempNext = SubString(Str,a,a+1)
  430.         set TempUp = SubString(Str,a-2,a-1)
  431.         if a == 1 then
  432.             set TempUp = ""
  433.         endif
  434.         //数字?
  435.         if IsNumber(TempUp)==false and IsNumber(Temp)==true then
  436.             set ReturnString = ReturnString+"|cff87ceeb"
  437.         //小写?
  438.         elseif IsLowercase(TempUp)==false and IsLowercase(Temp)==true then
  439.             set ReturnString = ReturnString+"|c009D9D9D"
  440.         //大写?
  441.         elseif IsCapitaliz(TempUp)==false and IsCapitaliz(Temp)==true then
  442.             set ReturnString = ReturnString+"|r"
  443.         //标点?
  444.         elseif IsInterpunc(TempUp)==false and IsInterpunc(Temp)==true then
  445.             set ReturnString = ReturnString+"|c00FF2828"
  446.         endif
  447.         set ReturnString = ReturnString+SubString(Str,a-1,a)
  448.         set a = a + 1
  449.     endloop
  450.     return ReturnString
  451. endfunction
复制代码

0

主题

30

帖子

40

积分

注册会员

Rank: 2

积分
40
发表于 2006-8-13 14:12:00 | 显示全部楼层

Re:谁会用we里的jass编辑脚本!可否提供些案例看下

楼主要什么案例?从现成地图中提一段出来?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2024-5-17 11:17

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表