wc3edit.net
https://forum.wc3edit.net/

making a new function
http://forum.wc3edit.net/deprotection-cheating-f64/making-a-new-function-t30662.html
Page 1 of 1

Author:  Apple [ January 20th, 2016, 2:40 pm ]
Post subject:  making a new function

I am making a function for my own CP, but I am going nowhere. :/
It is used for detecting hero and ping the person hero location (I find it kinda useful for dota)
if I were to use this, it can return me some neutral units as well
Code:
    return GetOwningPlayer(GetEnumUnit()) != Player(12)
    return GetOwningPlayer(GetEnumUnit()) != Player(15)
    return IsUnitType(GetEnumUnit(), UNIT_TYPE_HERO) == true
    return IsUnitEnemy(GetEnumUnit(), GetTriggerPlayer()) == true


How do i make sure only hero units are targeted?

also, i can't decide with getfilterunit() or getenumunit(), nor could I tell the difference between those

Author:  JustANewbie [ January 20th, 2016, 5:58 pm ]
Post subject:  Re: making a new function

Code:
local location HeroLoc
if IsUnitType(GetEnumUnit(), UNIT_TYPE_HERO) == true then
set HeroLoc=GetUnitLoc(GetEnumUnit())
call PingMinimap(GetLocationX(HeroLoc),GetLocationY(HeroLoc),5.)
call RemoveLocation(HeroLoc)
endif


I believe this works, and for GetFilterUnit(), I believe it is as below

Code:
function condition takes nothing returns boolean
return IsUnitType(GetFilterUnit(),UNIT_TYPE_HERO)!=null
endfunction

function ABC takes nothing returns nothing
local location HeroLoc=GetUnitLoc(GetEnumUnit())
call PingMinimap(GetLocationX(HeroLoc),GetLocationY(HeroLoc),5.)
call RemoveLocation(HeroLoc)                               
endfunction     
           
function CBA takes nothing returns nothing
call ForGroup(GetUnitsOfPlayerMatching(GetTriggerPlayer(),Condition(function condition)),function ABC)
endfunction

Author:  haxorico [ January 20th, 2016, 8:33 pm ]
Post subject:  Re: making a new function

I assume you already have the command setup and only need the.. HOW TO do the action itself. Here is what I got.. Not sure if it is working as I didnt try, been while since I tried to JASS, was refreshing and fun.
Code:
function pingHeroes takes nothing returns nothing
    local unit u
    local group g=CreateGroup()
    call GroupEnumUnitsInRect(g,GetPlayableMapRect(),null)
    loop
        set u=FirstOfGroup(g)
        exitwhen u==null
        if IsUnitType(u,UNIT_TYPE_HERO) then
            //action
        endif
        call GroupRemoveUnit(g,u)
    endloop
    call DestroyGroup(g)
endfunction

there are ways to optimize this code. As every time it checks all the units on the map and then going 1 by 1 to find a HERO and ping it (you need to input the "ping code" yourself tough).
If it is a game like DOTA you can just make a new group called HEROES or somthing and just place all the heroes there the same way I did on top, then everytime it will run real smooth.
Lemme know if you need help

Author:  Apple [ January 21st, 2016, 2:09 am ]
Post subject:  Re: making a new function

I always fix leak after I made it, like a quality control kind of thing rather than quality assurance. lol.
I've already made it yesterday,(just didn't want to reveal it publicly) it seem to work, and i havent set it to be able to ON/OFF
for fixing leak i always set to null instead of removing the rect, loc. Am I doing it right?
Spoiler:
Code:
function Func_Ping_Boolean takes nothing returns boolean
return IsUnitType(GetEnumUnit(), UNIT_TYPE_HERO) == true 
endfunction

function Func_Ping_Action takes nothing returns nothing
local unit pingunit= GetEnumUnit()
local location loc = GetUnitLoc(pingunit)   
local trigger t=GetTriggeringTrigger()   
call PingMinimapLocForPlayer(Player(0), GetUnitLoc(pingunit), 1 )
call DisableTrigger(t)   
set pingunit = null
set loc=null
set t=null
call RemoveLocation(loc)
endfunction                          //all good

function Init_Ping_Actions takes nothing returns nothing
local group g = CreateGroup()
local player p = GetTriggerPlayer()
set g = GetUnitsInRectAll(GetEntireMapRect())
call ForGroup(g, function Func_Ping_Action)                   
set p = null
set g = null
endfunction
function AC_Ping_Generator_Actions takes nothing returns nothing
local timer m = CreateTimer()
call Init_Ping_Actions()
call TimerStart(m,2,true,function Init_Ping_Actions)
set m = null
endfunction

function AC_Ping_Generator takes nothing returns nothing
set AC_TRIG_Ping_Generator=CreateTrigger()
call TriggerRegisterTimerEvent(AC_TRIG_Ping_Generator,0,true) 
call TriggerAddCondition(AC_TRIG_Ping_Generator,Condition(function AC_Global_Condition))
call TriggerAddCondition(AC_TRIG_Ping_Generator,Condition(function Func_Ping_Boolean) )
call TriggerAddAction(AC_TRIG_Ping_Generator, function AC_Ping_Generator_Actions)
endfunction


@newbie when I add an if statement it leaks like mad. lol.

Author:  haxorico [ January 21st, 2016, 3:34 am ]
Post subject:  Re: making a new function

I myself avoid using conditions as it makes the code jump all over the place, I prefer just using an IF statement. Seems more clean-coded to me. And if it is working I am kinda surprised.

a) you didnt show function AC_Global_Condition, only showed it is being called.
b) on function - Func_Ping_Boolean - I fail to see what unit this boolean is working for as the event has no unit in it. What is the result of GetEnumUnit()?
c) the function - AC_Ping_Generator_Actions - always gets called after every tick of the timer (so is the event, by a timer) - So it always creates another timer. In that it calls the function - Init_Ping_Actions() - once by itself (call Init_Ping_Actions()) and then again in the next line.
d) in function - Func_Ping_Action - why did you create a local trigger (t) and never used it?

I might be wrong on many things here, I am reading it on a website and didn't post it on jasscraft, and been a while since I used JASS, but I just don't see this code working...

Author:  Apple [ January 21st, 2016, 8:28 am ]
Post subject:  Re: making a new function

I didn't show u the entire code
the condition basically works if you're a cheater, it is a triggeraddcondition in every command function. (I didn't use the if statement because once I add if statement in the code, leak will get real and wc3 will stop working due to high memory usage)
Thanks for spotting though.

for c & d
tested without both, 1 at a time.
Removing any of them makes the entire map freezes.(overloaded memory usage)

If untouched the ping every 2 second works perfectly when cheater is triggered.
bad thing is I cannot remember why I need to disable triggeringtrigger so that it does not leak.

I don't really know about jass natives, so I don't know what getenumunit() and getfilterunit() does, and somehow getenumunit() works all the time. :lol:

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/