[ Новые сообщения · Участники · Правила форума · Поиск · RSS ]
  • Страница 1 из 1
  • 1
Модератор форума: ZLОY  
Форум карты Жизнь на Арене » Картостроение » Творцы миров » [Jass]Полезные функции(наработки) (Код, код и еще раз код...)
[Jass]Полезные функции(наработки)
FLESHNIKДата: Четверг, 09.06.2011, 12:07 | Сообщение # 1
xeno != Bloody// :B
Группа: Проверенные
Сообщений: 3638
Репутация: 30
Статус: Offline
Наработки от perimetral'a:
  • DamageGroup - бьет группу g уроном dmg. ranged - дальняя ли атака.
    call DamageGroup(g, dmg, ranged)
    [cut=Код]
    Code
    function DamageGroup takes group g, real dmg, boolean ranged returns nothing
                                local unit u
                                local group og = g
                                loop
                         set u = FirstOfGroup(og)
                         call UnitDamageTarget(u, u, dmg, true, ranged, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
                         call GroupRemoveUnit(og, u)
                                exitwhen u == null
                                endloop
                                call DestroyGroup(og)
                                set og = null
                                set u = null
    endfunction
    [/cut]

  • DamageCircleLoc - бьет всех в радиусе r от точки c уроном dmg. ranged - дальняя ли атака. Требует предыдущую функцию.
    call DamageCircleLoc(c, r, dmg, ranged)
    [cut=Код]
    Code
    function DamageCircleLoc takes location c, real r, real dmg, boolean ranged returns nothing
                                local group g = CreateGroup()
                                local real X = GetLocationX(c)
                                local real Y = GetLocationY(c)
                                call GroupEnumUnitsInRange(g, X, Y, r, null)
                                call DamageGroup(g, dmg, ranged)
                                call DestroyGroup(g)
                                set g = null
    endfunction
    [/cut]

  • DamageCircleXY - бьет всех в радиусе r от точки с координатами X; Y уроном dmg. ranged - дальняя ли атака. Требует 1ю функцию.
    call DamageCircleXY(X, Y, r, dmg, ranged)
    [cut=Код]
    Code
    function DamageCircleXY takes real X, real Y, real r, real dmg, boolean ranged returns nothing
                                local group g = CreateGroup()
                                call GroupEnumUnitsInRange(g, X, Y, r, null)
                                call DamageGroup(g, dmg, ranged)
                                call DestroyGroup(g)
                                set g = null
    endfunction
    [/cut]

  • DamageLine - бьет всех на линии шириной в w с началом в точке a и концом в точке b уроном dmg. ranged - дальняя ли атака. Требует 1ю и 3ю функции.
    call DamageLine(a, b, w, dmg, ranged)
    [cut=Код]
    Code
    function DamageLine takes location a, location b, real w, real dmg, boolean ranged returns nothing
                                local integer i = 0
                                local real aX = GetLocationX(a)
                                local real bX = GetLocationX(b)
                                local real aY = GetLocationY(a)
                                local real bY = GetLocationY(b)
                                local real dist = SquareRoot((bX - aX) * (bX - aX) + (bY - aY) * (bY - aY))
                                local real angle = (180.0/3.14159) * Atan2(bY - aY, bX - aX)
                                loop
                                exitwhen i > dist/w
                          call DamageCircleXY(aX, aY, w/2, dmg, ranged)
                          set aX = aX + w * Cos(angle * (3.14159/180.0))
                          set aY = aY + w * Sin(angle * (3.14159/180.0))
                          set i = i + 1
                                endloop
    endfunction
    [/cut]

  • DamageLineAlt - альтернатива функции DamageLine из первопоста. Отличается в 2 раза большей точностью подсчета областей (менее кривая линия), но меньшей производительностью.
    call DamageLineAlt(a, b, w, dmg, ranged)
    [cut=Код]
    Code
    function DamageLineAlt takes location a, location b, real w, real dmg, boolean ranged returns nothing
                              local integer i = 0
                              local real aX = GetLocationX(a)
                              local real bX = GetLocationX(b)
                              local real aY = GetLocationY(a)
                              local real bY = GetLocationY(b)
                              local real dist = SquareRoot((bX - aX) * (bX - aX) + (bY - aY) * (bY - aY))
                              local real angle = (180.0/3.14159) * Atan2(bY - aY, bX - aX)
                              local group g = CreateGroup()
                              local group tg = CreateGroup()
                              local unit u
                              loop
                              exitwhen i > 2*dist/w
                        call GroupEnumUnitsInRange(g, aX, aY, w, null)
                        loop
                            set u = FirstOfGroup(g)
                            if (IsUnitInGroup(u, tg) == false) then
                                call UnitDamageTarget(u, u, dmg, true, ranged, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
                            endif
                            call GroupAddUnit(tg, u)
                            call GroupRemoveUnit(g, u)
                        exitwhen u == null
                        endloop
                        set aX = aX + w/2 * Cos(angle * (3.14159/180.0))
                        set aY = aY + w/2 * Sin(angle * (3.14159/180.0))
                        set i = i + 1
                              endloop
                              call DestroyGroup(g)
                              call DestroyGroup(tg)
                              set g = null
                              set tg = null
                              set u = null
    endfunction
    [/cut]




  • IsUnitInvulnerable - определяет, неуязвим ли юнит u
    local boolean b = IsUnitInvulnerable(u)
    [cut=Код]
    Code
    function IsUnitInvulnerable takes unit u returns boolean
                                local real hc = GetWidgetLife(u)
                                local real mc = GetUnitState(u,UNIT_STATE_MANA)
                                local boolean ch
                                call SetWidgetLife(u,hc + 0.001)                            
                                if hc != GetWidgetLife(u) then
                          call UnitDamageTarget(u,u,0.001,false,true,null,null,null)
                          set ch = (GetWidgetLife(u) == hc + 0.001)
                                else
                          call UnitDamageTarget(u,u,0.001,false,true,null,null,null)
                          set ch = (GetWidgetLife(u) == hc)
                          call SetWidgetLife(u,hc)
                                endif
                              //  if ch then
                              //      return not (GetUnitState(u,UNIT_STATE_MANA) != mc)
                              //  endif
                              // в оригинале закоменченные ф-и включены, но имхо с ними ничего не будет работать
                                return ch
    endfunction
    [/cut]




  • IsItemInInventory - определяет, есть ли у юнита u предмет типа it.
    local boolean b = IsItemInInventory(u, it)
    [cut=Код]
    Code
    function IsItemInInventory takes unit u, integer it returns boolean
                               local integer i = 0
                               local item ti
                               loop
                         set ti = UnitItemInSlot(u, i)
                         exitwhen i > 5 or GetItemTypeId(ti) == it
                         set i = i + 1
                               endloop
                               set ti = null
                               return i < 6
    endfunction
    [/cut]

  • CountItemInInventory - подсчитывает количество предметов типа it у юнита u.
    local integer i = CountItemInInventory(u, it)
    [cut=Код]
    Code
    function CountItemInInventory takes unit u, integer it returns integer
                          local integer i = 0
                          local integer count = 0
                          local item ti
                          loop
                          exitwhen i > 5
                              set ti = UnitItemInSlot(u, i)                             
                              if(GetItemTypeId(ti) == it)then
                        set count = count + 1
                              endif
                              set i = i + 1
                          endloop
                          set ti = null
                          return count
    endfunction
    [/cut]

  • RemoveItemFromInventory - удаляет первый попавшийся предмет типа it из инвентаря юнита u. Если, конечно, предмет у него есть.
    call RemoveItemFromInventory(u, it)
    [cut=Код]
    Code
    function RemoveItemFromInventory takes unit u, integer it returns nothing
                         local integer i = 0
                         local item ti
                         loop
                             set ti = UnitItemInSlot(u, i)
                             exitwhen i > 5 or GetItemTypeId(ti) == it
                             set i = i + 1
                         endloop
                         set ti = UnitItemInSlot(u, i)
                         if (i < 6) then
                             call RemoveItem(ti)
                         endif
                         set ti = null                       
    endfunction
    [/cut]

  • RemoveAllItemFromInventory - удаляет из инвентаря юнита u все предметы типа it.
    call RemoveAllItemFromInventory(u, it)
    [cut=Код]
    Code
    function RemoveAllItemFromInventory takes unit u, integer it returns nothing
                                 local integer i = 0
                                 local item ti
                                 loop
                           exitwhen i > 5
                           set ti = UnitItemInSlot(u, i)                          
                           if(GetItemTypeId(ti) == it)then
                               call RemoveItem(ti)
                           endif
                           set i = i + 1
                                 endloop
                                 set ti = null
    endfunction
    [/cut]




  • AddSpecialEffectZ - создает еффект e в координатах x; y на высоте z.
    call AddSpecialEffectZ(s, x, y, z)
    [cut=Код]
    Code
    function AddSpecialEffectZ takes string s, real x, real y, real z returns effect
                                local destructable d = CreateDestructableZ( 'OTip', x, y, z, 0.00, 1, 0 )
                                local effect e = AddSpecialEffect(s,x,y)
                                call RemoveDestructable(d)
                                set d = null
                                return e
    endfunction
    [/cut]




    Наработки от FLESHNIK'a:
  • Складывание зарядов предметов
    [cut=Открыть]
    Code
    function Sbor takes nothing returns nothing                  
      local integer i = 0                 
      local integer i2 = 0                  
      local intem it  = GetManipulatedItem()
      local integer i3 = GetItemCharges(it)
      local integer itt = GetItemTypeId(it)
      local unit u = GetManipulatingUnit()                     
      local item it2
    if GetItemCharges(it)>0 then  
      loop                  
       exitwhen i > 6 or i2 != 0                  
      if GetItemTypeId(UnitItemInSlot(u,i)) == itt  and UnitItemInSlot(u,i)!=it then                
         set i2 = 1
         set it2 = UnitItemInSlot(u,i)                   
         call SetItemCharges(it2,GetItemCharges(it2) + i3 )                  
         call RemoveItem(it)                   
    endif                  
        set i = i + 1                    
       endloop                  
    endif                
    set u=null
    set it = null
    set it2 = null                  
    endfunction
                          
    function InitTrig_Sbor takes nothing returns nothing                  
                              local integer i = 0                  
                           set gg_trg_Combine = CreateTrigger()                  
                           loop                  
                           exitwhen i == 11                  
                               call TriggerRegisterPlayerUnitEvent(gg_trg_Sbor,Player(i),EVENT_PLAYER_UNIT_PICKUP_ITEM,null)                  
                               set index=index+1                  
                           endloop                  
                           call TriggerAddAction(gg_trg_Sbor,function Sbor)                  
    endfunction
    [/cut]

  • Отдаление\приближение камеры(сбивается колёсиком) "-cam (число меньше 800)":
    [cut=Открыть]
    Code
    function cam_numb takes string s returns boolean
              local integer i = 0
               loop
               exitwhen i > 9
                if s == I2S(i) then
                 return true
                endif
    set  i = i + 1
               endloop
                return false
              endfunction

    function Trig_cam_Actions takes nothing returns nothing
              local player p = GetTriggerPlayer()
              local string s = GetEventPlayerChatString()
              local integer i = 0
              local integer i2 = 6
              local integer i3 = 0
              local integer si = 5          
              local string s2
              local integer si2
              local integer num
    //////////////////////////////////
               loop
               exitwhen i == 4 or i3 == 1
               set s2 = (SubStringBJ(s, 6 + i, 6 + i))
                if s2 == "0" or s2 == " " then
               set   si = si + 1
                  else
               set   i3 = 1          
                 endif
               set  i = i + 1
                endloop
              if si == 5 then
              set si = si + 1
               endif
              //////////////////////////////////
              set i = 0
    set  si2 = si
              //////////////////////////////////
               loop
               exitwhen s2 == " " or s2 == ""
               set s2 = (SubStringBJ(s, si + i, si + i))
                if cam_numb(s2) then
               set  si2 = si2 + 1
                endif
              set  i = i + 1
               endloop
              set num = S2I(SubStringBJ(s, si, si2 - 1))
                if num <= 800 then
                 call PanCameraToTimedLocWithZForPlayer( p, GetCameraEyePositionLoc(),num , 0.5 )
                 else
                 if num != null then
               call  DisplayTextToPlayer(p, 0., 0.,"|cffFF0202Неверное значение|r" )
                 endif
                 endif
              set  p = null
              set  s = null
              set  s2 = null
    endfunction

    //===========================================================================
    function InitTrig_Cam takes nothing returns nothing
                local integer i = 0
               set   gg_trg_Cam = CreateTrigger(  )
                 loop
                exitwhen i > 8          
                 call TriggerRegisterPlayerChatEvent( gg_trg_Cam, Player(i), "-cam", false )
                set  i = i + 1
                 endloop
                 call TriggerAddAction( gg_trg_Cam, function Trig_cam_Actions )
    endfunction
    [/cut]
  • [v/cJass]Движение по параболе move(u, x1, y1, x2, y2). Параметры настройки полёта вынесены вверх библиотеки.
    [cut=Открыть]
    Code
    library ParabolicMovement
    /////////////
        define    
         speed_par = 8. // скорость по ХY(за 1 промежуток времени)
          high_par = 1.5// длинна\high_par = высота пика параболы
          par_ekv = 6 // После столкновения еквивалент падения(снижение высоты за промежуток времени)
          debug_dis = 35. // Отталкивание в момент приземления во избежание застревания в текстурах.
        enddefine
    function Z takes real y0, real y1, real h, real d, real x returns real
         return (4 * h / d) * (d - x) * (x / d)
    endfunction

         function move_par_end takes nothing returns nothing
          timer t = GetExpiredTimer()
          integer tID = GetHandleId(t)
          unit u = LoadUnitHandle(udg_hash, tID, 1)
          real fly = LoadReal(udg_hash, tID, 2)
          real fly2 = LoadReal(udg_hash, tID, 3)
          integer ek_max = LoadInteger(udg_hash, tID, 4)
          integer ek = LoadInteger(udg_hash, tID, 5)
          timer t2
          integer t2ID
          if GetWidgetLife(u) > 0 and ek < ek_max then
         t2 = CreateTimer()
         t2ID = GetHandleId(t2)
           SetUnitFlyHeight(u, fly2 - ek*par_ekv, 2000.)
           SaveUnitHandle(udg_hash, t2ID, 1, u)
          SaveReal(udg_hash, t2ID, 2, fly)
          SaveReal(udg_hash, t2ID, 3, fly2)
          SaveInteger(udg_hash, t2ID, 4, ek_max)
          SaveInteger(udg_hash, t2ID, 5, ek + 1)
          TimerStart(t2, 0.2, false, function move_par_end)
          else
           SetUnitFlyHeight(u, fly, 2000.)
           PauseUnit(u, false)
           PauseUnit(u, true)
           PauseUnit(u, false)
           SetUnitPathing(u, true)
          endif
          FlushChildHashtable(udg_hash, tID)
          DestroyTimer(t)
          u = null
          t = null
          t2 = null
         endfunction    
            
         function move_start takes nothing returns nothing
          timer t = GetExpiredTimer()
          integer tID = GetHandleId(t)
          unit u = LoadUnitHandle(udg_hash, tID, 1)
          real y1 = LoadReal(udg_hash, tID, 2)
          real y2 = LoadReal(udg_hash, tID, 3)
          real x1 = LoadReal(udg_hash, tID, 4)
          real ang = LoadReal(udg_hash, tID, 5)
          real h = LoadReal(udg_hash, tID, 6)
          real d = LoadReal(udg_hash, tID, 7)
          integer l_max = LoadInteger(udg_hash, tID, 8)
          integer l = LoadInteger(udg_hash, tID, 9)
          real fly = LoadReal(udg_hash, tID, 10)
          real fly2 = GetUnitFlyHeight(u)
          integer ek_max
          real x
          real y
          real f
          timer t3
          integer t3ID
          location loc
          real fxy
          timer t2
          integer t2ID
          /////////////////////////////
          if GetWidgetLife(u) > 0 and l < l_max then
          x = GetUnitX(u) + speed_par * Cos(ang * bj_DEGTORAD)
          y = GetUnitY(u) + speed_par * Sin(ang * bj_DEGTORAD)
          loc = Location(x,y)
          fxy = GetLocationZ(loc)
        f = Z(y1, y2, h, d, speed_par*l)    
          if GetLocationZ(loc) > -256.0 then
          f = f -( GetLocationZ(loc) + 256)
          endif
          if x < GetRectMaxX(GetPlayableMapRect()) and y < GetRectMaxY(GetPlayableMapRect()) then
          if x > GetRectMinX(GetPlayableMapRect()) and y > GetRectMinY(GetPlayableMapRect()) then
          SetUnitX(u, x)
          SetUnitY(u, y)
          SetUnitFlyHeight(u, f, 2000.)
          t2 = CreateTimer()
          t2ID = GetHandleId(t2)
          SaveUnitHandle(udg_hash, t2ID, 1, u)
           SaveReal(udg_hash, t2ID, 2, y1)
           SaveReal(udg_hash, t2ID, 3, y2)
           SaveReal(udg_hash, t2ID, 4, x1)
           SaveReal(udg_hash, t2ID, 5, ang)
           SaveReal(udg_hash, t2ID, 6, h)
           SaveReal(udg_hash, t2ID, 7, d)
           SaveInteger(udg_hash, t2ID, 8, l_max)
           SaveInteger(udg_hash, t2ID, 9, l + 1)
           SaveReal(udg_hash, t2ID, 10, fly)
           TimerStart(t2, 0.01, false, function move_start)
           else
           SetUnitX(u, -1543.)
           SetUnitY(u, 1607.)
           SetUnitFlyHeight(u, fly, 2000.)
           PauseUnit(u, false)
           SetUnitPathing( u, true )
           set l = l_max + 1
           endif
              endif
         else
         if GetUnitFlyHeight(u) > 50 then
          SetUnitX(u, GetUnitX(u) + debug_dis * Cos((ang - 180.) * bj_DEGTORAD))
          SetUnitY(u, GetUnitY(u) + debug_dis * Sin((ang - 180.) * bj_DEGTORAD))
          ek_max = R2I((fly2 - fly)/par_ekv)
          if ek_max == 0 then
           ek_max = ek_max + 2
           endif
           t3 = GetExpiredTimer()
           t3ID = GetHandleId(t)
          SaveUnitHandle(udg_hash, t3ID, 1, u)
          SaveReal(udg_hash, t3ID, 2, fly)
          SaveReal(udg_hash, t3ID, 3, fly2)
          SaveInteger(udg_hash, t3ID, 4, ek_max)
          SaveInteger(udg_hash, t3ID, 5, 1)
          TimerStart(t3, 0., false, function move_par_end)
          else
          PauseUnit(u, false)
           SetUnitPathing( u, true )
           SetUnitFlyHeight(u, fly, 2000.)
          endif
          endif
          /////////////////////////////
    FlushChildHashtable(udg_hash, tID)      
    RemoveLocation(loc)
    DestroyTimer(t)
    loc = null
    u = null
    t = null
    t2 = null      
         endfunction
            
         function move takes unit u, real y1, real y2, real x1, real x2 returns nothing
         timer t = CreateTimer()
         integer tID = GetHandleId(t)
         real dx = x2 - x1
         real dy = y2 - y1    
         real d = SquareRoot(dx * dx + dy * dy)
         integer l_max = R2I(d/speed_par)
         real ang = bj_RADTODEG * Atan2(y2 - y1, x2 - x1)
         real fly = GetUnitFlyHeight(u)
         real h = d/high_par
          PauseUnit(u, true)
          UnitAddAbility(u,'Aave')
          UnitRemoveAbility(u,'Aave')
          SetUnitPathing( u, false )
           SaveUnitHandle(udg_hash, tID, 1, u)
           SaveReal(udg_hash, tID, 2, y1)
           SaveReal(udg_hash, tID, 3, y2)
           SaveReal(udg_hash, tID, 4, x1)
           SaveReal(udg_hash, tID, 5, ang)
           SaveReal(udg_hash, tID, 6, h)
           SaveReal(udg_hash, tID, 7, d)
           SaveInteger(udg_hash, tID, 8, l_max)
           SaveInteger(udg_hash, tID, 9, 1)
           SaveReal(udg_hash, tID, 10, fly)
          TimerStart(t, 0., false, function move_start)
          t = null
        endfunction
    ///////////    
    endlibrary
    [/cut]


    FLESHNIK, PWFresh, JIoMuK
  •  
    FLESHNIKДата: Пятница, 15.07.2011, 17:44 | Сообщение # 2
    xeno != Bloody// :B
    Группа: Проверенные
    Сообщений: 3638
    Репутация: 30
    Статус: Offline
  • Часть системы принадлежности предмета герою
    [cut=Открыть]
    Code
    function Trig_sobstvennost_Actions takes nothing returns nothing
    local item it = GetManipulatedItem()
    local integer ib = 1
    local integer id = 0
    local integer ic = GetItemUserData(it)
    local unit u = GetManipulatingUnit()
    local player p = GetOwningPlayer(GetManipulatingUnit())
    local real x = GetItemX(it)
    local real y = GetItemY(it)
    loop
    exitwhen id > 12
    if p == Player(id) then
    set ib = id + 1
    endif
    set id = id + 1
    endloop
    if ic == ib then
    else
    if ic < 1 or ic > 8 then
    call SetItemUserData(it, ib)
    else
    call SetItemPosition( it, x, y)
    call DisplayTextToPlayer(GetLocalPlayer(), 0., 0., GetPlayerName(Player(ib - 1)) + " |cff1FBF00пытался взять предмет|r " + GetPlayerName(Player(ic - 1)) + "|cff1FBF00'а(ы)|r")
    endif
    endif
    set p = null
    set u = null
    set it = null
    endfunction

    //===========================================================================
    function InitTrig_VLADELEC takes nothing returns nothing
    set gg_trg_VLADELEC = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_VLADELEC, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddCondition( gg_trg_VLADELEC, Condition( function Trig_sobstvennost_Conditions ) )
    call TriggerAddAction( gg_trg_VLADELEC, function Trig_sobstvennost_Actions )
    endfunction
    [/cut]
  • Простая функция для создания юнита с разными модельками для разных игроков. Нужно в РО сначала создать 2 почти одинаковых юнитов...отличия только визуальные.
    [cut=Открыть]
    Code
    function CreateLocalUnit takes integer id1, integer id2, player p, real x, real y returns unit
    local integer i = 0
    local integer id = id1
        loop
        exitwhen i > 8
    if GetLocalPlayer() == udg_plr[i] then
        if udg_loc[i] == 1 then
         set  id = id2
    endif
    endif
    set i = i + 1
    endloop    
    return CreateUnit(p, id, x, y, 180.)
    endfunction
    [/cut]
  • Проверка на забитость инвентаря.
    [cut=Открыть]
    Code
    function inv takes unit u returns boolean
       local integer i = 0
       local integer i2 = 0
       loop
       exitwhen i > 5
       if GetItemTypeId(UnitItemInSlot(u, i)) != 0 then
        set i2 = i2 + 1
        endif
        set i = i + 1
       endloop
       if i2 == 6 then
        return true
        endif
        return false
        endfunction
    [/cut]


    FLESHNIK, PWFresh, JIoMuK
  •  
    Форум карты Жизнь на Арене » Картостроение » Творцы миров » [Jass]Полезные функции(наработки) (Код, код и еще раз код...)
    • Страница 1 из 1
    • 1
    Поиск: