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
The reason you use another dummy ability would be to apply the effect of that ability -.-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.
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
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
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
local unit u = CreateUnit()
local unit u
set u = CreateUnit()
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.
function GetAttackedUnitBJ takes nothing returns unit
return GetTriggerUnit()
endfunction
constant native GetTriggerUnit takes nothing returns unit
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.
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.JASS:constant native GetTriggerUnit takes nothing returns unit
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
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
It doesn't have to be 4, 4 is just cool . It can be any number, just be consistent.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.
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)
Not at runtime, but script space.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 ?
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)MMM, i c what you mean (i guess) still globals are messy when you want to make spells MUI.
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
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
GetWidgetLife(target) == 0
as opposed to IsUnitDeadBJ(target)
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
SetUnitState(affected, UNIT_STATE_LIFE, hp + 10)
Still in the planning stage Check out the thread in the recruitment forums.About your project how is it going ?