making a new function

General talk about editing, cheating, and deprotecting maps.

Moderator: Cheaters

Apple
Forum Staff
Posts: 1470
Joined: November 3rd, 2010, 10:48 am
Title: Best Player
Location: Singapore

making a new function

Post by Apple »

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: Select all

    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
Request a map? Follow the rulesHERE
Request templateHERE
Please, do not PM me.
On the side note, I'm still playing vampirism speed on malaysia room, occasionally in Garena. Bcuz too lazy to find out where else I can play them.
JustANewbie
Forum Spammer
Posts: 510
Joined: August 18th, 2012, 2:32 am

Re: making a new function

Post by JustANewbie »

Code: Select all

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: Select all

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
User avatar
haxorico
Super Moderator
Posts: 3196
Joined: February 24th, 2009, 1:31 pm
Location: JEW LAND
Been thanked: 1 time

Re: making a new function

Post by haxorico »

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: Select all

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
Image
Spoiler:
(02:24:09)

Code: Select all

ChatBot: FatherSpace logs into the Chat.
(02:24:28) Lanaya: Gtfo ken.
(02:24:33) ChatBot: FatherSpace logs out of the Chat.
(02:24:40) Lanaya: Thought so. bitch.
(02:24:44) ChatBot: FatherSpace logs into the Chat.
(02:24:48) FatherSpace: Can I come back yet?
(02:24:51) Lanaya: What'd i say earlier.
(02:24:51) Lanaya: No.
(02:24:58) FatherSpace: Let's try this...
(02:25:01) ChatBot: Lanaya has been logged out (Kicked).

Code: Select all


(14:33:51) 2Pac: Do you know what'S so funny?
(14:34:01) Lanaya: No, please show me.
(14:34:07) 2Pac: This.
(14:34:09) ChatBot: Lanaya has been logged out (Kicked).
(14:34:10) 2Pac: 

Code: Select all

(14:35:59) haxorico: No one will belive me if I say "I got this song from 2pac on MSN" lolz ^^
(14:36:02) Lanaya: lolz.
(14:36:16) 2Pac: I AIN'T DEAD FFS.
(14:36:26) 2Pac: I'm a living legend, y'now.
(14:37:17) haxorico: why is 2Pac a legend?
(14:37:28) Lanaya: He's the worse rapper evar.

Code: Select all

(15:42:51) Lanaya: can i suck , . . .

Code: Select all

(13:55:21) ChatBot: 2Pac rolls 1d100 and gets 1.
(13:55:21) ChatBot: haxorico rolls 1d2 and gets 2.
(13:55:27) haxorico: owned?

Code: Select all

GeorgeMots: xplain what happens in SP. Why cant you save?
dast.-:i need play with 2 players

Code: Select all

(21:53:08) (673237): plzplzplz, im sorry about before.
(21:53:26) FatherSpace: I'm sorry you were born.
(21:53:31) ChatBot: (673237) has been logged out (Kicked).

Code: Select all

(10:08:02) Bartimaeus: you do know run I youtube channel for my favorite music, right?
Apple
Forum Staff
Posts: 1470
Joined: November 3rd, 2010, 10:48 am
Title: Best Player
Location: Singapore

Re: making a new function

Post by Apple »

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: Select all

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.
Request a map? Follow the rulesHERE
Request templateHERE
Please, do not PM me.
On the side note, I'm still playing vampirism speed on malaysia room, occasionally in Garena. Bcuz too lazy to find out where else I can play them.
User avatar
haxorico
Super Moderator
Posts: 3196
Joined: February 24th, 2009, 1:31 pm
Location: JEW LAND
Been thanked: 1 time

Re: making a new function

Post by haxorico »

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...
Image
Spoiler:
(02:24:09)

Code: Select all

ChatBot: FatherSpace logs into the Chat.
(02:24:28) Lanaya: Gtfo ken.
(02:24:33) ChatBot: FatherSpace logs out of the Chat.
(02:24:40) Lanaya: Thought so. bitch.
(02:24:44) ChatBot: FatherSpace logs into the Chat.
(02:24:48) FatherSpace: Can I come back yet?
(02:24:51) Lanaya: What'd i say earlier.
(02:24:51) Lanaya: No.
(02:24:58) FatherSpace: Let's try this...
(02:25:01) ChatBot: Lanaya has been logged out (Kicked).

Code: Select all


(14:33:51) 2Pac: Do you know what'S so funny?
(14:34:01) Lanaya: No, please show me.
(14:34:07) 2Pac: This.
(14:34:09) ChatBot: Lanaya has been logged out (Kicked).
(14:34:10) 2Pac: 

Code: Select all

(14:35:59) haxorico: No one will belive me if I say "I got this song from 2pac on MSN" lolz ^^
(14:36:02) Lanaya: lolz.
(14:36:16) 2Pac: I AIN'T DEAD FFS.
(14:36:26) 2Pac: I'm a living legend, y'now.
(14:37:17) haxorico: why is 2Pac a legend?
(14:37:28) Lanaya: He's the worse rapper evar.

Code: Select all

(15:42:51) Lanaya: can i suck , . . .

Code: Select all

(13:55:21) ChatBot: 2Pac rolls 1d100 and gets 1.
(13:55:21) ChatBot: haxorico rolls 1d2 and gets 2.
(13:55:27) haxorico: owned?

Code: Select all

GeorgeMots: xplain what happens in SP. Why cant you save?
dast.-:i need play with 2 players

Code: Select all

(21:53:08) (673237): plzplzplz, im sorry about before.
(21:53:26) FatherSpace: I'm sorry you were born.
(21:53:31) ChatBot: (673237) has been logged out (Kicked).

Code: Select all

(10:08:02) Bartimaeus: you do know run I youtube channel for my favorite music, right?
Apple
Forum Staff
Posts: 1470
Joined: November 3rd, 2010, 10:48 am
Title: Best Player
Location: Singapore

Re: making a new function

Post by Apple »

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:
Request a map? Follow the rulesHERE
Request templateHERE
Please, do not PM me.
On the side note, I'm still playing vampirism speed on malaysia room, occasionally in Garena. Bcuz too lazy to find out where else I can play them.