Jass Vault WC3Jass.com
"The Jass Vault"
 
 FAQ   Search   Memberlist   Usergroups   Register 
 Profile   Log in to check your private messages   Log in  
 Forum   Scripts   Files   Chat   Pastebin   Function finder  
Affiliates
The HIVE Workshop Games Modding
The Hubb Wc3Campaigns
WC3-Mapping.net

UnitGuardUnitAI2

 
Post new topic   Reply to topic    Jass Vault -> AI
View previous script :: View next script  

Script code
function HandleToUnit takes handle h returns unit
    return h
endfunction

//**********************************************************************************************
//*                                                                                            *
//*  UnitGuardUnitAI function and subfunctions                                                 *
//*                                                                                            *
//**********************************************************************************************

//==============================================================================================
//  Unit Guard AI Configuration: (Added this section so you can easily customize the ai without
//  ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ  Messing with the functions, just replace the numbers)
//
constant function UnitGuardUnitAI_maxdelay takes nothing returns real
    return 2.5 //* The max delay betwen orders issued to the summon
endfunction

constant function UnitGuardUnitAI_mindelay takes nothing returns real
    return 1.00 //* The min delay betwen orders issued to the summon
endfunction

constant function UnitGuardUnitAI_maxdistance takes nothing returns real
    return 1000.0 //* If the distance betwen the summon and the master is greater than this value,
                  //  The summon will move to the position of the master instead of attack move
endfunction

constant function UnitGuardUnitAI_cometomaxdist takes nothing returns real
    return 500.0 //* Max distance for issued orders to approach the master
endfunction

constant function UnitGuardUnitAI_cometomindist takes nothing returns real
    return 100.0 //* Min distance for issued orders to approach the master
endfunction

//==============================================================================================
function GuardUnitOrder takes unit summon, unit master returns nothing
 local integer o=GetUnitCurrentOrder(summon)
 local real tx=GetUnitX(master)
 local real ty=GetUnitY(master)
 local real angle
 local real dist

    set dist=SquareRoot(Pow(tx-GetUnitX(summon),2) + Pow(ty-GetUnitY(summon),2))
    if (dist > UnitGuardUnitAI_maxdistance() )  and (o == 0 or o == OrderId("attack") or o == OrderId("move") or o == OrderId("stop") or o==851971) then
        call IssuePointOrder(summon, "move", tx,ty)
    elseif dist >= UnitGuardUnitAI_cometomindist() and (o == 0 or o == 851971) then
        set angle = GetRandomReal( GetUnitFacing(master)-80, GetUnitFacing(master)+80) * IntegerTertiaryOp( ModuloInteger( GetUnitPointValue(summon), 2) == 0,1,-1)
        set dist = GetRandomReal(UnitGuardUnitAI_cometomindist(), UnitGuardUnitAI_cometomaxdist() )
        if not IssuePointOrder(summon, "attack", tx+dist*CosBJ(angle), ty+dist*SinBJ(angle) ) then
            call IssuePointOrder(summon, "move", tx+dist*CosBJ(angle), ty+dist*SinBJ(angle) )
        endif
    endif
 set summon=null
 set master=null
endfunction

function UnitGuardUnitAI_Smart_Order_Actions takes nothing returns nothing
 local location target
 local real angle
 local real dist
 local unit summon
 local unit master

    if GetIssuedOrderId() != 851971 then
        return
    endif
    set summon=GetTriggerUnit()
    set master=HandleToUnit( GetHandleHandle(summon, "master") )
    loop
        exitwhen GetUnitCurrentOrder(summon) != 851971
        call GuardUnitOrder( summon, master)
        call TriggerSleepAction(0)
    endloop

 set master=null
 set summon=null
endfunction

function UnitGuardUnitAI_loop takes nothing returns nothing
// Executed in another thread
 local unit summon=bj_ghoul[0]
 local unit master=HandleToUnit( GetHandleHandle(summon, "master") )
 local trigger smart=CreateTrigger()
 local integer n=0

    call TriggerAddAction( smart, function UnitGuardUnitAI_Smart_Order_Actions)
    call TriggerRegisterUnitEvent( smart, summon, EVENT_UNIT_ISSUED_TARGET_ORDER )
    call TriggerRegisterUnitEvent( smart, summon, EVENT_UNIT_ISSUED_POINT_ORDER )
    loop
        exitwhen IsUnitDeadBJ(summon)
        call GuardUnitOrder( summon, master)
        call PolledWait( GetRandomReal( UnitGuardUnitAI_mindelay(), UnitGuardUnitAI_maxdelay() ))
    endloop
    call FlushHandleLocals(summon)
    call DestroyTrigger(smart)

 set summon=null
 set master=null
 set smart=null
endfunction

function UnitGuardUnitAI takes unit summon, unit master returns nothing
 local trigger ailoop=CreateTrigger()
 local unit a=bj_ghoul[0]

    call SetHandleHandle( summon, "master", master)
    call TriggerAddAction(ailoop, function UnitGuardUnitAI_loop) //*Make UnitGuardUnitAI_loop to be executed in another thread
    set bj_ghoul[0]=summon
    call TriggerExecute(ailoop)
    set bj_ghoul[0]=a

 call DestroyTrigger(ailoop)
 set a=null
 set master=null
 set summon=null
 set ailoop=null
endfunction
Script info
Description
Like the already submitted Grater's [UnitGuardUnitAI] function but:

- It doesn't stop the thread
- Blocks smart orders given to the summoned units ( So you can also use ward classiffication instead of Aloc + Chaos Morph skill)
- Unit with odd point values will be considered support and units with even point values will be considered tanks
- It won't give orders to the units if they are casting some spells
- Summon will avoid to lose targets

Author
Defynt
Guest



Back to top
Message
CommentPosted: Sat Jun 25, 2005 7:09 pm    Post subject: Reply with quote

Vex , How would i Mod this to make a Computer controlled Player have a hero follow my unit? how do i specify what unit is the master and what is the summon?

Author
Nantuko_Husk


Joined: 24 Apr 2005
Comments: 159
Back to top
Message
CommentPosted: Sun Jul 03, 2005 11:31 am    Post subject: Reply with quote

with triggers.

Events
UnitSPawns a summoned unit

Actions
Custom Script : call UnitGuardUnitAI2(GetSummoningUnit(),GetSummonedUnit())

where GetSUmmoningUnit is the summoner,and GetSummoned Unit,it's obvious.

You can put any unit into the place of summoning and summoned,it shouldnt cause problems.
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Author
Zatan13th


Joined: 18 Jul 2006
Comments: 1
Back to top
Message
CommentPosted: Tue Jul 18, 2006 7:39 pm    Post subject: Reply with quote

Oh Sir! I've 1 question.

How to stop unit from guarding (err.. stop the function eh)?

I mean, I'd put unit to guarding group later I want to stop this unit from guading as I which. How to do could tell me please?

thnx
View user's profile Send private message

Author
Vexorian


Joined: 07 Apr 2005
Comments: 293
Back to top
Message
CommentPosted: Sat Jul 22, 2006 12:40 pm    Post subject: Reply with quote

The version at http://www.wc3campaigns.net/showthread.php?t=83384 can do so
View user's profile Send private message

Display posts from previous:   
Post new topic   Reply to topic    Jass Vault -> AI All times are GMT
Page 1 of 1

 
Jump to:  
You can submit new scripts in this section
You can comment on scripts in this section
You cannot edit your scripts in this section
You cannot delete your scripts in this forum



FSDark by SkaidonDesigns
Powered by phpBB © 2001, 2002 phpBB Group