• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Buffs/Auras?

Status
Not open for further replies.

at

at

Level 4
Joined
Aug 18, 2007
Messages
88
I'm creating a custom aura with JASS. Basicly, I need to know how to add a buff to a target when it gets in range, and then remove it when it gets away.
Thank
 

at

at

Level 4
Joined
Aug 18, 2007
Messages
88
Well, I pretty much don't know anything about these dummy abilities. What are they`?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Well, just make Inner Fire or Cripple or something (whichever , make it have no mana cost/bleh (but make it have whatever effect you want it to, so if you want Soul Burn use Soul Burn)), make it have your buff, then when the unit comes in range,

Create a dummy unit

Cause it to cast the dummy ability on the entering unit

kill the dummy
 
Last edited:
Actually if you want to create your own aura, listening to purplepoot's is a very bad idea. Using dummy spells is really bad because they can be dispelled. Use the Abilities Editor to create your own aura. After that create 1 aura buff for each level. Because aura's are different, their buffs will stack in perfection, as long as they have different names and images (unlike dummy ability buffs, if you create 2 spells based of slow, they won't stack on the same unit because they have the same origin name which is "slow". With auras you don't have that problem.).

The aura buffs are your best option. To see if a unit has a buff you can you JASS in perfection or even GUI as well.
 
Level 15
Joined
Feb 15, 2006
Messages
851
LOL, first of all, why trigger to emulate an aura when you can use a custom ability based on any of the aura made by blizzard?? I think you should explain what the aura does and, probably, give you a best solution.

Anyways, if you want to make it triggered, you can use an ability based on Slow aura, change the target to self, and set in the buff you want to that ability.
 

at

at

Level 4
Joined
Aug 18, 2007
Messages
88
Hm. I'm confused. I would like to JASS, even if GUI is easier, cause I'm trying to learn it.
Say this: I want an aura that gives +1 strenght. Could you like screenshot the result in JASS or sumthing?
 

at

at

Level 4
Joined
Aug 18, 2007
Messages
88
Well, sorry, I just said something I thought would be easy :p
+10 hp then? I just want to know how to do, it's not for a special spell.
 
mmm, well there is a way to do that but again, because it has no events it will be difficult. You will need Global vars which are very messy or you will need to use Hanlde Vars Advanced JASS script codes which are probably beyond your capabilities for now.
My advice is: create an aura that is triggered by an event such as : a unit is attacked or a unit casts an ability or a unit dies, etc.

If you want to learn how to make your own custom aura i also suggest you visit this link, as it has the basics of excellent aura creation: http://www.hiveworkshop.com/forums/showthread.php?t=32827
 

at

at

Level 4
Joined
Aug 18, 2007
Messages
88
Well, I'd really like to learn it in JASS. I want to use that as much as possible. Thanks anyway.
EDIT: That makes no sense. That's not quite hard. I just wonder where to make custom spells in the WE :)
EDIT 2: I'm making the spell effect in JASS. How to add life to the unit. Set unit's hp = unit's hp + 10? (with a variable.)
 
Last edited:

at

at

Level 4
Joined
Aug 18, 2007
Messages
88
Found out how to do it, I guess. This is a buff (aura) that gives the player a 25% chance to recover 10 life when they get hit:

JASS:
function aura_condition takes nothing returns boolean
return UnitHasBuffBJ == thebuffid //how to make a condition to check if the user has a buff?
endfunction
//=================================================================================
function aura_actions takes nothing returns nothing
local unit affected = GetTriggerUnit()
local real hp = GetUnitLifePercent(affected)
local integer random = GetRandomInt(1, 100)
    if random > 75 then
        call SetUnitLifeBJ(affected, hp + 10) //Does that work? Couldnt find any "Getunitsmaxlife"
    endif 
endfunction
//=================================================================================
function aura_trig takes nothing returns nothing
set gg_aura_trigger = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_aura_trigger, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(gg_aura_trigger, Condition(function aura_condition))
    call TriggerAddAction(gg_aura_trigger, function aura_actions) 
endfunction

I'm unsure of some things, please correct any errors.
Anyway, I still can't figure out how to add 10 hp to the unit when they have the buff
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Actually if you want to create your own aura, listening to purplepoot's is a very bad idea. Using dummy spells is really bad because they can be dispelled. Use the Abilities Editor to create your own aura. After that create 1 aura buff for each level. Because aura's are different, their buffs will stack in perfection, as long as they have different names and images (unlike dummy ability buffs, if you create 2 spells based of slow, they won't stack on the same unit because they have the same origin name which is "slow". With auras you don't have that problem.).

The aura buffs are your best option. To see if a unit has a buff you can you JASS in perfection or even GUI as well.
The reason you use another dummy ability would be to apply the effect of that ability -.-
 

at

at

Level 4
Joined
Aug 18, 2007
Messages
88
Again, thanks.
Would this work? This is a little script for a spell for my RPG, that's supposed to heal everyone around the caster whenever the caster casts his heal.

JASS:
function Sacred_Instinct_Condition_1 takes nothing returns boolean
    if ( not ( GetUnitAbilityLevelSwapped('A000', GetTriggerUnit()) > 0 ) ) and GetSpellAbilityUnit() == "healid" then
        return false
    else
    return true
    endif
endfunction
//=================================================================================================================
function Sacred_Instinct_Trigger_1 takes nothing returns nothing
set trigger gg_Sacred_Instinct_Trigger_1 = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(gg_Sacred_Instinct_Trigger_1, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(gg_Sacred_Instinct_Trigger_1, Condition (function Sacred_Instinct_Condition_1))
        call TriggerAddAction(gg_Sacred_Instinct_Trigger_1, function Sacred_Instinct_Actions_1)
endfunction
//=================================================================================================================       
function Sacred_Instinct_Actions_1 takes nothing returns nothing
local group healtargets
local unit caster = GetTriggerUnit()
local location casterloc = GetUnitLoc(caster)
local unit temp
call GroupEnumUnitsInRangeOfLoc(healtargets, casterloc, 300, null)
local real number = CountUnitsInGroup(healtargets)
    loop
       set temp = GroupPickRandomUnit(healtargets)
       if IsUnitAlly(temp, GetOwningPlayer(caster)) then  
            call SetUnitLifeBJ (temp, (GetUnitStateSwap(UNIT_STATE_LIFE, temp)) + 25)
       endif
       call GroupRemoveUnit(healtargets, temp)
       set number = number - 1
       exitwhen number == null
    endloop
call DestroyGroup(healtargets)
set healtargets = null
set caster = null
set casterloc = null
set temp = null
set number = null
endfunction

Btw, comment my thread about the spells :p http://www.hiveworkshop.com/forums/showthread.php?t=39376

EDIT: I read somewhere that I'll have to create multiple spells, one for each level of the spell, and then detect which one it is and do the script like that. Do I need to do that, or can I use only one spell?


EDIT2:
Another spell. This one is simply a heal, but when it hits an undead it hurts, and when it hits an ally, it heals. Any idea how to make the Sacred Instinct just react on the ally hit?
Btw, I didnt null anything on the last one. But don't worry, I will do it if I use it :)

JASS:
function Recovery_Condition takes nothing returns boolean
return GetSpellAbilityId() == "spellID"
endfunction

//=======================================================================================

function Recovery_Actions takes nothing returns nothing
if GetSpellTargetUnit() == UNIT_TYPE_UNDEAD then
    local unit target = GetSpellTargetUnit()
    call SetUnitLifeBJ(target, (GetUnitStateSwap(UNIT_STATE_LIFE, target)) - 100)
    set target = null
elseif GetSpellTargetUnit == IsUnitAlly(target, GetOwningPlayer(target)) then
    local unit target = GetSpellTargetUnit()
    call SetUnitLifeBJ(target, (GetUnitStateSwap(UNIT_STATE_LIFE, target)) + 100)
    set target = null
endif
endfunction

//=======================================================================================

function Blessed_Recovery_Trigger takes nothing returns nothing
    set trigger gg_Recovery_Trigger
    call TriggerRegisterAnyUnitEventBJ(gg_Recovery_Trigger, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_Recovery_Trigger, Condition(function Recovery_Condition))
    call TriggerAddAction(gg_Recovery_Trigger, function Recovery_Actions)
endfunction
 
Last edited:
atatat i am very impressed about your project, in deed i would like to join and make some spells if you need.

About your spells, well they do work, but they are 100% NOT efficient with multiple leaks and others ... that is just an GUI converted spell, still i will help you.

By the way your first JASS spell is so messy that it will never work unless some1 fixes it ( i am fixing it now)



Well, here is the correction of the first spell. To make a 3 levels spell you DON'T NEED 3 abilities.
I transformed your not working spell into this JESP standard spell. I will soon post the changes i made, why i made them and soon recommend some good JASS tutorials you will have to read to be a good Jasser.

Anyway, Spell fixed:
JASS:
function SacredInstinct_Conds takes nothing returns boolean  
    return GetSpellAbilityId() == 'A000' //Here you place the RWACODE of the ability  
endfunction 
//================================================================================================================= 
function SacredInstinct_Acts takes nothing returns nothing 
    local group g 
    local unit caster = GetTriggerUnit()
    local unit vic
    local real hp = 50*GetUnitAbilityLevel( caster, 'A000' )
    call GroupEnumUnitsInRange( g, GetUnitX( caster ), GetUnitY( caster ), 300, Filter(null) )
    loop  
        set vic = FirstOfGroup( g )  
        exitwhen vic==null  
        if IsUnitAlly(vic, GetOwningPlayer(caster)) then  
            call SetUnitState(vic, UNIT_STATE_LIFE, GetWidgetLife(vic) + hp)     
        endif  
            call GroupRemoveUnit(g,vic)
    endloop
    call DestroyGroup(g)    
    set g = null 
    set caster = null 
    set vic = null  
endfunction
//============================================================================
function Sacred_Instinct takes nothing returns nothing 
    local trigger SacredInstinct = CreateTrigger()  
    call TriggerRegisterAnyUnitEventBJ(SacredInstinct, EVENT_PLAYER_UNIT_SPELL_EFFECT)  
    call TriggerAddCondition(SacredInstinct, Condition (function SacredInstinct_Conds))  
    call TriggerAddAction(SacredInstinct, function SacredInstinct_Acts) 
    set SacredInstinct = null
endfunction

Well, time to explain.
1 - First, you must obey to the trigger structure which normally is: Condition > Action > Trigger. Condition and action can swap places but the Trigger initialization part must be in the end.
2 - LOCALS always come in the START of the the trigger, before any calls, loops and if's. there are 2 ways of setting a local:
JASS:
local unit u = CreateUnit()
or
JASS:
local unit u 
set u = CreateUnit()
this is very important to JASS correctly.
3 - i also removed a lot of unneeded variables. Variables are good, but they take memory so use them wisely as they CAN cause serious lag. Normally lag is prevented by nullifying variables but when we don't do this we just take memory of the game with trash values that will cause serious lag. When you don't remove a variable, you are leaking. Variables are not the only thing that leaks, locations also do leak, so it is better to use Coordinates like i did, because they don't require a variable and they don't need to be nullified.

(More comming soon)
 
Last edited:

at

at

Level 4
Joined
Aug 18, 2007
Messages
88
Eh, I didn't really think when I did that one :- Didn't event think of making another script for the same spell. I yet have to little experience to think the easy way I guess :)
Thanks for the help.
And thanks for the critisism. About the project, as I said in the other thread, I think I've made the wrong expression. This is not a project, yet. It's an idea for a project, which is quite different. We pretty much practically havent started.
Tho we (me, hrm) are thinking about recruiting others, mostly because 1. Alot of work, and atleast according to me you shouldnt do an RPG if you cant do it better than the average ones. Sure, we could spend some time, but It wouldn't be any gameexperience over the usual. And that's what we want, so we want to put affort in it. 2. Me and Bgutz lives in two whole different time zones. It's very hard to cooperate just me and him.

So, I can't say anything, but probably you could join, either just with a little help on the side, or as a part of the "team" :)
And ye, my spells probably have 100 random problems each. I'm still learning remember. But don't hesitate to point them out. I'm very grateful.
 
Flame_Phoenix said:
Well, time to explain.
1 - First, you must obey to the trigger structure which normally is: Condition > Action > Trigger. Condition and action can swap places but the Trigger initialization part must be in the end.

2 - LOCALS always come in the START of the the trigger, before any calls, loops and if's. there are 2 ways of setting a local:
Code:
local unit u = CreateUnit()
or
Code:
local unit u set u = CreateUnit()
this is very important to JASS correctly.

3 - i also removed a lot of unneeded variables. Variables are good, but they take memory so use them wisely as they CAN cause serious lag. Normally lag is prevented by nullifying variables but when we don't do this we just take memory of the game with trash values that will cause serious lag. When you don't remove a variable, you are leaking. Variables are not the only thing that leaks, locations also do leak, so it is better to use Coordinates like i did, because they don't require a variable and they don't need to be nullified.

Continuing:
4 - When using loops, also end the loop with an "endlopp" and when using if's end them with an "endif"

5 - You are probably wondering what JESP is. Well, JESP is normal JASS but with some rules. JESP was made to be universal so that all people of the world could understand it, it's like a common language everyone share. JESP has some rules. I applied some of them - the rule i applied is making the spell leak free, MUI and constant. As you can see you will heal 50 hp in lv1, 100 hp in lv2 and 150 hp in lv 3, but because it is a constant spell, you can easily go until level 100 without changing the scrip.

6 - When setting triggers do like i did. Create a local trigger and nullify it. This way the trigger will be unreachable by other triggers making it impossible to be any leaks and confusions between triggers.

7 - BJ's. What are BJ's ??? Well like PurplePoot said BJ's are EVIL. Bj's are evil because they make your script much slower . But don't worry about it, you can avoid BJ's by writing their values. Example of a BJ is GetAttackedUnitBJ.
JASS:
function GetAttackedUnitBJ takes nothing returns unit
    return GetTriggerUnit()
endfunction

Confusing ?? Not really, this shows you that you can REPLACE GetAttackedUnitBj with GetTriggerUnit() and there save game memory and improve your scripts speed. How do i know a function is a BJ ?? Well, any time you find a function with BJ on it's name, that function is a BJ. But there are functions that don't have BJ on their name. So BJ's are all functions that are nor native. GetTriggerUnit is not a BJ because it is native.
JASS:
constant native GetTriggerUnit takes nothing returns unit
There are sometimes a few exceptions that BJ's are faster than natives, but those functions are very rare. Keep in mind: Avery time you find a BJ, replace that BJ.
 

at

at

Level 4
Joined
Aug 18, 2007
Messages
88
Thanks again.
Alot of that I knew already, but I'm just to unexperienced to think logical :)
There was some new things too. Thanks for helping, I'll probably keep asking for it in the future, hope it's not to annoying for you guys :p
/at
 
Flame_Phoenix said:
Well, time to explain.
1 - First, you must obey to the trigger structure which normally is: Condition > Action > Trigger. Condition and action can swap places but the Trigger initialization part must be in the end.

2 - LOCALS always come in the START of the the trigger, before any calls, loops and if's. there are 2 ways of setting a local:
Code:
local unit u = CreateUnit()
or
Code:
local unit u set u = CreateUnit()
this is very important to JASS correctly.

3 - i also removed a lot of unneeded variables. Variables are good, but they take memory so use them wisely as they CAN cause serious lag. Normally lag is prevented by nullifying variables but when we don't do this we just take memory of the game with trash values that will cause serious lag. When you don't remove a variable, you are leaking. Variables are not the only thing that leaks, locations also do leak, so it is better to use Coordinates like i did, because they don't require a variable and they don't need to be nullified.

Continuing:
4 - When using loops, also end the loop with an "endlopp" and when using if's end them with an "endif"

5 - You are probably wondering what JESP is. Well, JESP is normal JASS but with some rules. JESP was made to be universal so that all people of the world could understand it, it's like a common language everyone share. JESP has some rules. I applied some of them - the rule i applied is making the spell leak free, MUI and constant. As you can see you will heal 50 hp in lv1, 100 hp in lv2 and 150 hp in lv 3, but because it is a constant spell, you can easily go until level 100 without changing the script.

6 - When setting triggers do like i did. Create a local trigger and nullify it. This way the trigger will be unreachable by other triggers making it impossible to be any leaks and confusions between triggers.

7 - BJ's. What are BJ's ??? Well like PurplePoot said BJ's are EVIL. Bj's are evil because they make your script much slower . But don't worry about it, you can avoid BJ's by writing their values. Example of a BJ is GetAttackedUnitBJ.
JASS:
function GetAttackedUnitBJ takes nothing returns unit
    return GetTriggerUnit()
endfunction

Confusing ?? Not really, this shows you that you can REPLACE GetAttackedUnitBj with GetTriggerUnit() and there save game memory and improve your scripts speed. How do i know a function is a BJ ?? Well, any time you find a function with BJ on it's name, that function is a BJ. But there are functions that don't have BJ on their name. So BJ's are all functions that are nor native. GetTriggerUnit is not a BJ because it is native.
JASS:
constant native GetTriggerUnit takes nothing returns unit
There are sometimes a few exceptions that BJ's are faster than natives, but those functions are very rare. Keep in mind: Every time you find a BJ, replace that BJ.

8 - Use arrays. Arrays are 1 variable that can have multiple variables inside them. I will not explain this to you but i will tell you the tutorials.

9 - Indenting. Every time you start a function you must indent 4 spaces. When you use a loop, indent 4 spaces and when you use an if indent 4 spaces. This very important so people can understand your spells.
The example that is bellow is only to show you how to indent, it is not a JASS functional script.
JASS:
function indent takes nothing returns nothing
    local unit werm = CreateUnit()
    loop
        exitwhen werm = blarg
        call AnyActionIWant
    endloop
    if werm = dead then 
        set blarg = bla bla bla
    endif
    if werm = alive then
        loop
            exitwhen IDunnoWhatIAmDoing = true
            set blarg = 0
        endloop
    endif
endfunction


10 - Use JASS programs like JassCraft that is available in this site.

11 - Nothing else i can remember now =P.

Now i did a few change in the script, i think you can easily understand them.

JASS:
function SacredInstinct_Conds takes nothing returns boolean  
    return GetSpellAbilityId() == 'A000' //Here you place the RAWCODE of the ability  
endfunction 
//================================================================================================================= 
function SacredInstinct_Acts takes nothing returns nothing 
    local group g 
    local unit caster = GetTriggerUnit()
    local unit vic
    local real hp = 50*GetUnitAbilityLevel( caster, 'A000' )  //This is a constant value used in JESP. In this case it is 50>>50*1 = 50>>50*2=100>>50*3=150 and so on
    call GroupEnumUnitsInRange( g, GetUnitX( caster ), GetUnitY( caster ), 300, Filter(null) ) //Selects units in 300 range of the caster, i am using coordinates
    loop  
        set vic = FirstOfGroup( g )  
        exitwhen vic==null  
        if IsUnitAlly(vic, GetOwningPlayer(caster)) then //Selects allied units 
            call SetUnitState(vic, UNIT_STATE_LIFE, GetWidgetLife(vic) + hp) //Heals hp to units    
        endif  
            call GroupRemoveUnit(g,vic)
    endloop
    call DestroyGroup(g)    
    set g = null 
    set caster = null 
    set vic = null    //Nullifies everything and prevents lag.
endfunction          //To nullify groups, effects and locations they must be destroyed first
//============================================================================
function Sacred_Instinct takes nothing returns nothing 
    local trigger SacredInstinct = CreateTrigger()  
    local integer index = 0
    loop 
        exitwhen index == 16
        call TriggerRegisterPlayerUnitEvent(SacredInstinct, Player(index), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set index = index + 1
    endloop       //I am replacing A BJ by it's value =)
    call TriggerAddCondition(SacredInstinct, Condition (function SacredInstinct_Conds))  
    call TriggerAddAction(SacredInstinct, function SacredInstinct_Acts) 
    set SacredInstinct = null //Integers, reals and booleans don't need to be nullified, but all others need to
endfunction

That is everything i guess.

Tutorials:
1- http://www.hiveworkshop.com/forums/showthread.php?t=16456
2- http://www.hiveworkshop.com/forums/showthread.php?t=30765
3- http://world-editor-tutorials.thehelper.net/faq.php#faq8
4- http://www.hiveworkshop.com/forums/showthread.php?t=7334
5- http://www.hiveworkshop.com/forums/showthread.php?t=19249

Here are some basic JASS tutorials you may want to read, i have already read those so i know they will help you out. There is also a GUI tutorial about making spells that i strongly recommend you. A good JASSER is some1 who is also good at GUI, besides converting and fixing GUI triggers is the best way to learn pro JASS (i talk by self experience). In the end you have a tutorial about JESP that will surely help you as well.

PS: You can download the program i use for JASS in this post.

About the idea for your project, well, you guys have a long and nice idea. It is good to see that. Still good projects always take time and you must be patient. I will help you guys as long as i can, and wouldn't to make part of the "team" or to just help you guys with your problems.
PS: want some credit in the end (kiding, it is a joke).
 

Attachments

  • JassCraft 1.1.3.rar
    882.3 KB · Views: 109
Level 40
Joined
Dec 14, 2005
Messages
10,532
9 - Indenting. Every time you start a function you must indent 4 spaces. When you use a loop, indent 4 spaces and when you use an if indent 4 spaces. This very important so people can understand your spells.
The example that is bellow is only to show you how to indent, it is not a JASS functional script.
It doesn't have to be 4, 4 is just cool :p. It can be any number, just be consistent.

EDIT: if you're gonna abuse GetWidgetLife, flame, you may as well abuse SetWidgetLife too ;)

EDIT2: I would use the predefined global trigger, it's a little better (already there, for one). Also, TriggerRegisterAnyUnitEventBJ is a gem as far as BJs go >_> (It's not that bad... it does so much stuff for you already that you may as well use it, in my opinion, but each man to his own)

EDIT3: I would say it's really nice to get started by using Convert from GuI-->JASS, but for more advanced stuff, it's just practice... practice... practice... and get your stuff reviewed by other people who've practiced more, to get feedback.
 
atatat meet my Jass Teacher, PurplePoot =P

PurplePoot said:
EDIT2: I would use the predefined global trigger, it's a little better (already there, for one). Also, TriggerRegisterAnyUnitEventBJ is a gem as far as BJs go >_> (It's not that bad... it does so much stuff for you already that you may as well use it, in my opinion, but each man to his own)

Lol, about the global trigger, it is in: http://www.hiveworkshop.com/forums/showthread.php?t=30765 . This tutorial does say that local triggers are recommended, although i also know about their limitations. However for JASS beginners i prefer to start small and only teach the great JASS stuff after when they know the small stuff :p . It's like a student teaching another student.
About the BJ evvent, yes i know, you already told me that. That that's due the person i am. I seek perfection in everything i do even in the smallest tiny things like that Bj... it is a life option you know =P .
Thx by the reply Purple, i am trying to help you out here in the JASS stuff, hope i am helping.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Well, in my opinion Access is not a good thing when you don't need to access it or don't want to. And map size it's just temporary because they are nullified after. Still if a global is permanent doesn't it mean that the variable is permanent and that will actually take more space in memory ?
Not at runtime, but script space.

Compare;

trigger xX

(or some other 2 letter combination)

event... xX
condition... xX
action... xX

versus

local trigger x
event... x
condition... x
action... x
set x = null

And a variable needs 4 bytes of memory space. I doubt that you'll ever even see that make the slightest blip on your computer.

Math stuff --
4 bytes * 256 = 1024 bytes = 1 kilobyte. 1 kilobyte * 1024 = 1024 kilobytes = 1 megabyte. Most computers have 512Mb to 1Gb of RAM at least. I personally have 2Gb. So, to make a 1 megabyte difference, you need... 1048576 trigger globals. xD. Handling all the objects themselves would probably freeze your computer before you got 1% of the way to that number.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
MMM, i c what you mean (i guess) still globals are messy when you want to make spells MUI.
Well, not global triggers for the default triggers... they don't make a difference there. I think you're a little overprejudiced against globals here. They're still great for a lot of things, but they should just be used in cases where they won't screw lots of things up if you make the slightest mistake (to a certain extent... if someone deletes all their triggers, that's their own fault)

And that means that you have to rep other people for other things before you can rep me again (so people can't just rep dump each other over and over or something... I dunno really)

Speaking of which, I should probably give off some rep... I've given it like, 3 times ever (I personally don't like rep as a system that much), so here's some rep for helping out this guy.

EDIT: Hahahahaha, my rep was worth 7 points (that's alot, if you didn't know. Almost doubled what you used to have). Have fun.
 

at

at

Level 4
Joined
Aug 18, 2007
Messages
88
Rep to both of you. It was only worth 1 tho, but shit happens :)
About credits, you will get it ^^, tho it's a little early to think of that now.

Thanks again. I think I've got the princip now. Really cleared up alot. And I am using JASScraft, actually it's become really helpful :)

About arrays: I read in some tutorial that arrays are quite uneffective unless you need to add a massive amount of variables to it, since it takes alot of place. But I'll try it out.

And the convert thingy, the only reason why I did that was because I had no idea about how to start, and then I found a GUI tutorial about auras, and I just copied the first part from there and converted it :p

BTW: more work!

The Rays of Suffering spell: Damages one enemy, and if that guy dies, it bounces to three new ones:

JASS:
function Rays_Suffering_Condition takes nothing returns boolean
    return GetSpellAbilityId() == 'A001' //whatever
endfunction
//=========================================================================
function Rays_Suffering_Actions takes nothing returns nothing
    local unit target = GetSpellTargetUnit()
    local group seconds
    local unit caster = GetTriggerUnit()
    local location targetloc = GetUnitLoc(target)
    local unit temp
    local real groupnumber
    local real count
    call GroupEnumUnitsInRangeOfLoc(seconds, targetloc, 300, null)
    set groupnumber = CountUnitsInGroup(seconds)
    call SetUnitLifeBJ(target, (GetUnitStateSwap(UNIT_STATE_LIFE, target)) - 200)
    if IsUnitDeadBJ(target) then
        loop
            exitwhen groupnumber == null or count == null
            set temp = GroupPickRandomUnit(seconds)
                if IsUnitEnemy(temp, GetOwningPlayer(caster)) then
                    call SetUnitLifeBJ(temp, (GetUnitStateSwap(UNIT_STATE_LIFE, target)) - 100)
                    set count = count - 1
                endif
            call GroupRemoveUnit(seconds, temp)
            set groupnumber = groupnumber - 1
        endloop
    endif
    set target = null
    call DestroyGroup(seconds)
    set seconds = null
    set caster = null
    set targetloc = null
    set temp = null
endfunction
//===========================================================================       
function Rays_Suffering_Trigger takes nothing returns nothing
    local trigger Rays_Suffering_Trigger 
        call TriggerRegisterAnyUnitEventBJ(Rays_Suffering_Trigger, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(Rays_Suffering_Trigger, Condition(function Rays_Suffering_Condition))
        call TriggerAddAction(Rays_Suffering_Trigger, function Rays_Suffering_Actions)
        set Rays_Suffering_Trigger = null
endfunction
I didn't really look it through or so, but I hope I didnt do any to brutal errors.

EDIT: Btw, again, why can't I use BJs?


And Again: I guess this is annoying for you :p Since these are very easy spells to script. I think I can manage them, and I don't find any errors in this one, but I just want to know how to make it smoother.

JASS:
function Swarm_Cond takes nothing returns boolean
    return GetSpellAbilityId() == 'A001'
endfunction
//================================================================================
//================================================================================
function Swarm_Act takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local location arrowloc = GetSpellTargetLoc()
    local location casterloc = GetUnitLoc(caster)
    local unit temp
    local real hp = 100 * (GetUnitAbilityLevel(caster, 'A001'))
    local group enemies 
    call GroupEnumUnitsInRangeOfLoc(enemies, arrowloc, 300, null)
    call PolledWait(3) 
        loop
            set temp = FirstOfGroup(enemies)
            if IsUnitEnemy(temp, GetOwningPlayer(caster)) then
                call UnitDamageTarget(caster, temp, 200, true, true, ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL, null)         
            endif
            call GroupRemoveUnit(enemies, temp)
            exitwhen temp == null
        endloop    
endfunction
//================================================================================
//================================================================================
function Swarm_Trigger takes nothing returns nothing
    local trigger swarm = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(swarm, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(swarm, Condition(function Swarm_Cond))
        call TriggerAddAction(swarm, function Swarm_Act)
endfunction
 
Last edited:
Level 40
Joined
Dec 14, 2005
Messages
10,532
BJs are slower and almost never accomplish more. TriggerRegisterAnyUnitEventBJ is good though ;)

Anyhow, you DID make a brutal error -.-. You used SetUnitLife(Bj...), as opposed to UnitDamageTarget, meaning that the caster won't get credit for kills.

---Small stuff---

Also, a real/integer can be equal to 0 but not null.

Also Also, you should use GetWidgetLife(target) == 0 as opposed to IsUnitDeadBJ(target)

Also Also Also, you leak a location (targetLoc)

Also Also Also Also (picky, this is way more efficient though), use FirstOfGroup and not GroupPickRandomUnit
 

at

at

Level 4
Joined
Aug 18, 2007
Messages
88
Can't say more then ops. Fixed :
But the integers and reals doesnt leak, do they?
EDIT: Working on the Zealots Destiny. How the heck do you set a units damage?
 
Last edited:

at

at

Level 4
Joined
Aug 18, 2007
Messages
88
Danke.
How exactly does that work. I see you call "AddDamageBonus" But I can't find any function with that name. ?
 
Last edited:
Level 2
Joined
Jun 25, 2005
Messages
23
Found out how to do it, I guess. This is a buff (aura) that gives the player a 25% chance to recover 10 life when they get hit:

JASS:
function aura_condition takes nothing returns boolean
return UnitHasBuffBJ == thebuffid //how to make a condition to check if the user has a buff?
endfunction
//=================================================================================
function aura_actions takes nothing returns nothing
local unit affected = GetTriggerUnit()
local real hp = GetUnitLifePercent(affected)
local integer random = GetRandomInt(1, 100)
    if random > 75 then
        call SetUnitLifeBJ(affected, hp + 10) //Does that work? Couldnt find any "Getunitsmaxlife"
    endif 
endfunction
//=================================================================================
function aura_trig takes nothing returns nothing
set gg_aura_trigger = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_aura_trigger, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(gg_aura_trigger, Condition(function aura_condition))
    call TriggerAddAction(gg_aura_trigger, function aura_actions) 
endfunction

I'm unsure of some things, please correct any errors.
Anyway, I still can't figure out how to add 10 hp to the unit when they have the buff

Why make the processor generate random between 1-100, when you can go low ball and make it generate between 1-4, and check if it's 4.

By the way you are using a BJ, a BJ is basically a function that calls another similar function, so they are pretty much useless, other than making the trigger editor look pretty.

SetUnitState(affected, UNIT_STATE_LIFE, hp + 10)
this will work much better.

EDIT: Wow... Didn't see you guys were on page 3, and talking about something else :(.
 

at

at

Level 4
Joined
Aug 18, 2007
Messages
88
Thanks, you're right :) does the BJs takes that much more memory?
 
Well, it depends on the BJ.
Normally BJ's are slower than natives and they do take a lot more memory, thus increasing greatly the game's lag.
However according to Daelin's there are a few BJ's that are faster than natives because they use some kind of game memory, thus reducing game lag.
Such BJ's like the last i explained are extremely rare to find, so my advice is for you to replace BJ's every time you can as they are a common problem.

About your project how is it going ?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
The overhead on a custom function is greater than the execution time of Sin in wc3.

Ouch.

Anyways, speaking of improvements;

UnitHasBuffBJ can be replaced with GetUnitAbilityLevel
SetUnitState can be replaced with SetWidgetLife :)P azule)

(of course, the parameters will need revising, as well as you'll have to add a >0 after GetUnitAbilityLevel)
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Sin is a really complicated math equation (on the inside, not on the calculator side...), that's why it's surprising.

Voila... (image from Wikipedia)

6bf16b97ce1b4c86ffa1ed55c3fdc25f.png


(note: since the summation series would otherwise go on forever, a precision is chosen to replace infinity. Also, in computer science, CORDIC is often used as a replacement for the taylor series)

And by overhead, I mean the stress of calling the custom function, not including any of its contents.
 
Status
Not open for further replies.
Top