Topic đóng góp Snippet và System

  • Thread starter Thread starter dh-g
  • Ngày gửi Ngày gửi

dh-g

Fire in the hole!
Lão Làng GVN
Nội quy topic! SnippetSystem

- Topic dùng để chia sẻ Snippet và System hữu ích!


Bạn được phép:

  • Tự do chia sẻ Snippet và System hữu ích! hoặc do chính bạn tạo ra!
  • Request những Snippet hoặc System sẵn có nhưng chưa post
  • Chuyển đổi system từ vjass cjass > GUI hoặc GUI qua vjass jass (phải ghi credit cho người sáng tạo hoặc cung cấp ý tưởng)

Và:

  • Snippet hoặc System phải bao gồm trình bàyhướng dẫn hoặc kèm thêm map demo để mọi người biết cách dùng!
  • Không khuyến nghị chuyển đổi system với tác dụng không chính đáng (ví dụ: cách thức hoạt động của TimerUltis(vjass) là thích hợp với jass. nhưng nếu chuyển TimerUltis qua GUI sẽ không được chấp nhận! vì GUI là đơn giản và không có xài cách thức của TimerUltis bên jass vì là không cần thiết!)
  • Snippet và System được phép sử dụng GUI,jass,vjass,cjass

Nếu:

  • Snippet và System đã được post tại topic này và được post thêm lần nữa sẽ coi như SPAM!!!
  • Snippet hoặc System lấy từ source của người khác mà edit chút xíu(type author) sẽ không được chấp nhận!
  • Bạn là người viết ra system đó! nếu nhờ ý tưởng một ai đó! xin hãy cung cấp tên (Credit) vào system hoặc snippet! (hãy làm một người văn minh)
- về sau tớ sẽ tổng hợp danh sách system hoặc snippet tại topic này!



  1. -
  2. RepeatData 32
    +
  3. RepeatData 32
  4. IndexMB
  5. Local Weather
  6. Calculate Position Func
  7. BlockDamageAPI
  8. GroupLable
  9. SystemKnockBack
  10. Local I/O for Single
  11. ProgressCastingBar
  12. Fade Unit Color
  13. Fade Lightning
  14. Reality System
  15. IsUnitMoving
 
Chỉnh sửa cuối:
chắc chắn mấy bạn mới vào 'nghề' thì xài multiboard không biết làm sao cho nó có thể rút ngắn line khi đang chơi Player ít,vì vậy tớ xin first blood topic này bằng Snippet này,là một cách giúp bạn tạo được multiboard có Index như LeaderBoard vậy

multiboard.png
nhưng đó dễ dàng hơn leaderboard và cách này áp dụng cho Multiboard chỉ cần set func là xong :)


Mã:
library IndexMB initializer Int// v1.00 (Snippet)
/*---------------------------------------------------------------------------------------------------
by Dhguardianes:

nay co the giup ban tao. 1 multiboard ma` tuy theo player dang' co' tuc' la` vi du co 3 player
thi multiboard cua ban chi co 4 line ma thoi! trong khi multiboard classic thi se co la 12 line!(tuy nguoi)
va no' rat huu~ ich'

no' co the tao. multiboard tuy` theo so' player co san~

3 func nay su dung de biet' vi. tri' Index player do'! nam` trong multiboard co' 3 cach de lay Index MB!!!
I2Row(integer) - su dung player id de lay so index ra!
P2Row(player) - su dung player do' de lay so index ra!
U2Row(unit) - su dung unit do' de lay so index ra!

MB_Index() su dung de tao. rows ban co the dat index tai day!
Multiboard - Create a multiboard with 4 columns and (MB_Index()) rows, titled test


de pick all player thi ban co the set loop tu 1-12 va` lam nhu the la duoc!
Loop - Actions
Multiboard - Set the text for (Last created multiboard) item in column 2, row (I2Row(udg_TempInt)) to 10)


---------------------------------------------------------------------------------------------------*/ 
globals
private integer Index = 1 //su dung de danh Index trong MB!
private constant hashtable Hashtable = InitHashtable() //neu co hash san~ hãy xoa' dong nay`!
private constant integer key = 0x63746264//day la ma~ hex cho hashtable tranh trung` hash!
endglobals

private function SetIndex takes integer PlayerID returns nothing
call SaveInteger(Hashtable, key, GetHandleId(Player(PlayerID - 1)), Index)
endfunction

//! textmacro Row takes key type this code
function $key$2Row takes $type$ $this$ returns integer
local integer r = LoadInteger(Hashtable, key, GetHandleId($code$))
if r < 1 then
return 999//debug code! khi ra so 0 thi` se thanh` all loop cua multiboard ben GUI!
endif
return r
endfunction
//! endtextmacro

//! runtextmacro Row("I","integer","PlayerID","Player(PlayerID-1)")
//! runtextmacro Row("P","player","WhichPlayer","WhichPlayer")
//! runtextmacro Row("U","unit","WhichUnit","GetOwningPlayer(WhichUnit)")

function MB_Index takes nothing returns integer//tra so' index cho ban biet' da~ co bao nhieu line!
return Index
endfunction

private function Init takes nothing returns nothing
local integer i = 1
call DestroyTimer(GetExpiredTimer())
loop
exitwhen i > 12
if (GetPlayerSlotState(Player(i - 1)) == PLAYER_SLOT_STATE_PLAYING) then
set Index = Index + 1
call SetIndex(i)
endif
set i = i + 1
endloop
endfunction
//===========================================================================
private function Int takes nothing returns nothing
call TimerStart(CreateTimer(), 0, false, function Init)
endfunction
endlibrary

đây là map demo! bạn có thể vào đây tìm hiểu ;)
http://www.mediafire.com/?90dsct9g22ki31x
 
Chỉnh sửa cuối:
đây là Local weather có thể thay đổi weather tùy theo player gõ lệnh!

Mã:
library LocalWeather initializer Init// v1.00 (Snippet)
/*---------------------------------------------------------------------------------------------------
by Dhguardianes:

day la LocalWeather!! chac ban choi dota se thay -weather moonlight v.v.. se co thay doi weather theo player
ban co the su dung -weather bao gom`

-weather off
-weather snow
-weather rain
-weather wind
-weather light
-weather random
-weather moonlight
---------------------------------------------------------------------------------------------------*/
globals
private constant integer Moon = 'LRma'
private constant integer Rain = 'RAlr'
private constant integer Snow = 'SNls'
private constant integer Light = 'LRaa'
private constant integer Wind = 'WNcw'
private constant string Info = "Thay doi thoi tiet bang cach go lenh -weather, ma lenh -weather duoc su dung truong hop sau day; off,random,rain,snow,moonlight,light,wind."
private constant integer array random
private weathereffect weather = null
private player TempPlayer
endglobals
//===========================================================================
//! textmacro LocalWeatherFunc takes thistype,code
if ( ( GetEventPlayerChatString() == "$thistype$" ) ) then

if GetLocalPlayer()==TempPlayer then
call RemoveWeatherEffect( weather )
set weather = AddWeatherEffect(bj_mapInitialPlayableArea, $code$)
call EnableWeatherEffect( weather, true )
endif
return
endif
//! endtextmacro

private function f takes nothing returns nothing
set TempPlayer = GetTriggerPlayer()
//! runtextmacro LocalWeatherFunc("-weather random","random[GetRandomInt(1, 5)]")
//! runtextmacro LocalWeatherFunc("-weather moonlight","Moon")
//! runtextmacro LocalWeatherFunc("-weather light","Light")
//! runtextmacro LocalWeatherFunc("-weather wind","Wind")
//! runtextmacro LocalWeatherFunc("-weather snow","Snow")
//! runtextmacro LocalWeatherFunc("-weather rain","Rain")
if ( ( GetEventPlayerChatString() == "-weather off" ) ) then
if GetLocalPlayer()==TempPlayer then
call RemoveWeatherEffect( weather )
endif
return
endif
if (not ( GetEventPlayerChatString() == "-weather random" ) or ( GetEventPlayerChatString() == "-weather off" ) or ( GetEventPlayerChatString() == "-weather moonlight" ) or ( GetEventPlayerChatString() == "-weather light" ) or ( GetEventPlayerChatString() == "-weather wind" ) or ( GetEventPlayerChatString() == "-weather snow" ) or ( GetEventPlayerChatString() == "-weather rain" ) )then
call DisplayTextToPlayer(TempPlayer,0,0, Info)
endif
endfunction
//===========================================================================
private function Init takes nothing returns nothing
local trigger t = CreateTrigger( )
local integer i = 1
set random [1] = Moon
set random [2] = Rain
set random [3] = Snow
set random [4] = Light
set random [5] = Wind
loop
exitwhen i > 12
call TriggerRegisterPlayerChatEvent( t, Player(i - 1), "-weather", false )
set i = i + 1
endloop
call TriggerAddAction( t, function f )
endfunction
endlibrary
 
Chỉnh sửa cuối:
Vấn đề là mỗi map cần code theo 1 cách khác nhau nên cái vụ snipet thì của ai người đó dùng chứ post lên đây cũng có ai dùng đâu
Mà nói thiệt là bị phán là còn quá ư may mắn. Chỉ sợ ko có ai đọc mà phán ấy chứ. Thôi thì ta cũng góp vui lấy 1 cái snipet mà tự thấy là map nào dùng jass cũng cần....
Snipet này hỗ tính toán với tọa độ X và Y thay vì tính toán với location
PHP:
//   =============================
// ==== Calculate Position Func
//   =============================
function GetPPX takes real x, real dist, real angle returns real
    return x + dist * Cos(angle * bj_DEGTORAD)
endfunction

function GetPPY takes real y, real dist, real angle returns real
    return y + dist * Sin(angle * bj_DEGTORAD)
endfunction
function AngleLocXY takes real x1, real y1, real x2, real y2 returns real
    return bj_RADTODEG * Atan2(y2 - y1, x2 - x1)
endfunction

function DistanceLocXY takes real x1, real y1, real x2, real y2 returns real
    return SquareRoot( (x2-x1) * (x2-x1) + (y2-y1) * (y2-y1))
endfunction
và 1 cái snipet giúp tạo effect mà sẽ tự destroy sau 1 khoảng thời gian
PHP:
function CreateEffectDur takes string path, real x, real y, real duration returns nothing
    local effect fx = AddSpecialEffect(path, x, y)
    call TriggerSleepAction(duration)
    call DestroyEffect(fx)
    set fx = null
endfunction

function CreateEffectXY takes string path, real x, real y, real duration returns nothing
    call CreateEffectDur.execute(path, x, y, duration)
endfunction

function CreateEffectUnitDur takes widget u, string path, string attachpoint, real duration returns nothing
    local effect fx = AddSpecialEffectTarget(path, u, attachpoint)
    call TriggerSleepAction(duration)
    call DestroyEffect(fx)
    set fx = null
endfunction

function CreateEffectUnit takes widget u, string path, string attachpoint, real duration returns nothing
    call CreateEffectDur.execute(path, u, attachpoint, duration)
endfunction
Loại này chỉ dùng CreateEffectUnit CreateEffectXY đừng dùng 2 function kia @@ và yêu cầu các bạn có jasshelper 1.24+

System thì xem mấy cái dưới chữ kí của tớ có cái nào cậu cần thì dùng ....
 
Chỉnh sửa cuối:
Request: Một system save/load =jass hoặc vjass (không tích hợp sử dụng quá 6 trigger bổ trợ => Nói chung là dễ xài:5cool_bad_smelly:) :9cool_too_sad:
 
Vấn đề là mỗi map cần code theo 1 cách khác nhau nên cái vụ snipet thì của ai người đó dùng chứ post lên đây cũng có ai dùng đâu
chuẩn 8-} ý tớ cũng là thế

Request: Một system save/load =jass hoặc vjass (không tích hợp sử dụng quá 6 trigger bổ trợ => Nói chung là dễ xài:5cool_bad_smelly:) :9cool_too_sad:

save/load dạng gì? dạng ra file txt hay ra 1 đám code rồi viết lại?
 
thế daric add cái Y!M tớ đi: pro_hydra, khi nào làm xong send qua cho :) tại nó chỉ phục vụ cho map tớ nên phải hướng dẫn
 
lần đầu tiên viết 1 system k phụ thuộc vào các system khác của map mình :))
tuy nhiên vẫn cần TimerUtils nhé @-)
Mã:
library SystemKnockBack requires TimerUtils
//---made by Meepolisk, neu co dung thi credits nhe :D
//---cach su dung:
//-------call KnockBack (<location>, <unit> , <range knockback>, <thoi gian>)
//---> lam <unit> bi knockback vang ra xa <range knockback>
//tu huong <location> trong <thoi gian> giay.
    globals
         private constant real interval = 0.03
    endglobals
    private struct KBdata
        real time
        real timemax
        real angle
        unit u
        real move
        real rangemax
    endstruct
    
    private function KnockBackEnd takes nothing returns nothing
        local KBdata this = GetTimerData(GetExpiredTimer())
        local real fly = (this.rangemax/3)*Sin(this.time/this.timemax * 180 * bj_DEGTORAD)
        local location loc1 = GetUnitLoc(this.u)
        local location loc2 = PolarProjectionBJ(loc1, this.move, this.angle)
        set this.time = this.time - interval
        if this.time > 0 then
            call SetUnitFlyHeight(this.u, fly, 0.00)
            call SetUnitPositionLoc(this.u, loc2)
        else
            call UnitRemoveAbility(this.u,'Amrf')
            call SetUnitFlyHeight(this.u, GetUnitDefaultFlyHeight(this.u), 0.00)
            call ReleaseTimer(GetExpiredTimer())
            call PauseUnit(this.u, false)
            call this.destroy()
        endif
        call RemoveLocation(loc1)
        call RemoveLocation(loc2)
        set loc1 = null
        set loc2 = null
    endfunction
    
    function KnockBack takes location loc, unit u, real range, real time returns nothing
        local KBdata this = KBdata.create()
        local timer t = NewTimer()
        set this.u = u
        set this.timemax = time
        set this.time = time
        set this.angle = bj_RADTODEG * Atan2(GetUnitY(u) - GetLocationY(loc), GetUnitX(u) - GetLocationX(loc))
        set this.rangemax = range
        set this.move = this.rangemax/(this.timemax/interval)
        call SetTimerData(t, this)
        call PauseUnit(u, true)
        call UnitAddAbility(u,'Amrf')
        call TimerStart(t, interval, true, function KnockBackEnd)
    endfunction
endlibrary

Đây là system KnockBack có độ cao, nghĩa là knockback ra sẽ làm văng các chú khác lên trời (gần như toss)
Cách dùng rõ hơn (cụ thể là skill thunder clap)
Mã:
    Events
        Unit - A unit Starts the effect of an ability
    Conditions
        (Ability being cast) Equal to Thunder Clap
    Actions
        Set AALoc1 = (Position of (Triggering unit))
        Unit Group - Pick every unit in (Units within 300.00 of AALoc1 matching (((Matching unit) belongs to an enemy of (Owner of (Triggering unit))) Equal to True)) and do (Actions)
            Loop - Actions
                Custom script:   call KnockBack (udg_AALoc1, GetEnumUnit(), 500, 1)
 
^
viết cái diễn giải lại yk a. isLoop ở đâu đây?
Cái I/O chỉ dành cho Single thôi àk? thế thì LAN tính sao? :1cool_choler:
 
Chỉnh sửa cuối:
đây là Local weather có thể thay đổi weather tùy theo player gõ lệnh!

Mã:
library LocalWeather initializer Init// v1.00 (Snippet)
/*---------------------------------------------------------------------------------------------------
    by Dhguardianes:
    
    day la LocalWeather!! chac ban choi dota se thay -weather moonlight v.v.. se co thay doi weather theo player
    ban co the su dung -weather bao gom`
    
-weather off
    -weather snow
        -weather rain
            -weather wind
                -weather light
                    -weather random
                        -weather moonlight
---------------------------------------------------------------------------------------------------*/
    globals
        private constant integer Moon = 'LRma'
        private constant integer Rain = 'RAlr'
        private constant integer Snow = 'SNls'
        private constant integer Light = 'LRaa'
        private constant integer Wind = 'WNcw'
        private constant string Info = "Thay doi thoi tiet bang cach go lenh -weather, ma lenh -weather duoc su dung truong hop sau day; off,random,rain,snow,moonlight,light,wind."
        private constant integer array random
        private weathereffect weather = null
        private player TempPlayer
    endglobals
//===========================================================================
//! textmacro LocalWeatherFunc takes thistype,code
    if ( ( GetEventPlayerChatString() == "$thistype$" ) ) then

        if GetLocalPlayer()==TempPlayer then
            call RemoveWeatherEffect( weather )
            set weather = AddWeatherEffect(bj_mapInitialPlayableArea, $code$)
            call EnableWeatherEffect( weather, true )
        endif
        return
    endif
//! endtextmacro

    private function f takes nothing returns nothing
        set TempPlayer = GetTriggerPlayer()
//! runtextmacro LocalWeatherFunc("-weather random","random[GetRandomInt(1, 5)]")
//! runtextmacro LocalWeatherFunc("-weather moonlight","Moon")
//! runtextmacro LocalWeatherFunc("-weather light","Light")
//! runtextmacro LocalWeatherFunc("-weather wind","Wind")
//! runtextmacro LocalWeatherFunc("-weather snow","Snow")
//! runtextmacro LocalWeatherFunc("-weather rain","Rain")
        if ( ( GetEventPlayerChatString() == "-weather off" ) ) then
            if GetLocalPlayer()==TempPlayer then
                call RemoveWeatherEffect( weather )
            endif
            return
        endif
        if (not ( GetEventPlayerChatString() == "-weather random" ) or ( GetEventPlayerChatString() == "-weather off" ) or ( GetEventPlayerChatString() == "-weather moonlight" ) or ( GetEventPlayerChatString() == "-weather light" ) or ( GetEventPlayerChatString() == "-weather wind" ) or ( GetEventPlayerChatString() == "-weather snow" ) or ( GetEventPlayerChatString() == "-weather rain" ) )then
            call DisplayTextToPlayer(TempPlayer,0,0, Info)
        endif
    endfunction
//===========================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger( )
        local integer i = 1
        set random [1] = Moon
        set random [2] = Rain
        set random [3] = Snow
        set random [4] = Light
        set random [5] = Wind
        loop
            exitwhen i > 12
            call TriggerRegisterPlayerChatEvent( t, Player(i - 1), "-weather", false )
            set i = i + 1
        endloop
        call TriggerAddAction( t, function f )
    endfunction
endlibrary


Mình thử add vào thì nó báo:
Line 75: parse error
line 75, 2577,2652 báo undeclared variable LocalWeather__random
 
à fix rồi vì quên coi lại các comment :-ss
mà cái I/O thật ra chỉ ra I/O thôi :-j còn vụ multi thì phải cần 1 sync integer system khác :P cái này tìm trên web là có ngay thôi :-? tại tớ có ý định attach vào vì gặp 1 vài vấn đề khó giải :|

Bí cái gì thì hỏi a Vương của em ấy :3cool_angry:
màk thôi khỏi, chắc ko làm RPG nữa đâu nên ko cần nữa :-<
 
Back
Top