| 04-26-2006, 07:03 PM | #1 |
Ok, here i am again with another annoying problem. Im getting no compile errors, which is a good start, but my spell is doing nothing. I have my own mini-function-system which goes in map script: JASS:// Init Game Cache function GC takes nothing returns gamecache if(udg_GC == null) then call InitGameCacheBJ("GC") set udg_GC = GetLastCreatedGameCacheBJ() endif return udg_GC endfunction // Handle Handles function H2I takes handle whichHandle returns integer return whichHandle return 0 endfunction function I2U takes integer whichInteger returns unit return whichInteger return null endfunction function I2E takes integer whichInteger returns effect return whichInteger return null endfunction function I2SE takes integer whichInteger returns sound return whichInteger return null endfunction // Conditional Functions function AreUnitsEnemy takes unit whichUnit, unit whichOtherUnit returns boolean return (IsPlayerEnemy(GetOwningPlayer(whichUnit), GetOwningPlayer(whichOtherUnit))) endfunction function AmountBetweenReals takes real whichReal, real whichOtherReal returns real if(whichReal < whichOtherReal) then return whichOtherReal - whichReal endif return whichReal - whichOtherReal endfunction function IsRealNegative takes real whichReal returns boolean return (0.00 > whichReal) endfunction function MidPointBetweenReals takes real whichReal, real whichOtherReal returns real return (whichReal + whichOtherReal) / 2 endfunction function GetUnitStrength takes unit whichUnit, boolean includeBonuss returns integer return GetHeroStatBJ(bj_HEROSTAT_STR, whichUnit, includeBonuss) endfunction function GetUnitAgility takes unit whichUnit, boolean includeBonuss returns integer return GetHeroStatBJ(bj_HEROSTAT_AGI, whichUnit, includeBonuss) endfunction function GetUnitIntelligence takes unit whichUnit, boolean includeBonuss returns integer return GetHeroStatBJ(bj_HEROSTAT_INT, whichUnit, includeBonuss) endfunction function GetUnitHp takes unit whichUnit returns real return GetUnitStateSwap(UNIT_STATE_LIFE, whichUnit) endfunction function GetUnitMp takes unit whichUnit returns real return GetUnitStateSwap(UNIT_STATE_MANA, whichUnit) endfunction function GetUnitMaxHp takes unit whichUnit returns real return GetUnitStateSwap(UNIT_STATE_MAX_LIFE, whichUnit) endfunction function GetUnitMaxMp takes unit whichUnit returns real return GetUnitStateSwap(UNIT_STATE_MAX_MANA, whichUnit) endfunction // Little Usage Functions function SpellDamageUnit takes unit credit, unit target, real damage returns nothing if(IsUnitType(target, UNIT_TYPE_MAGIC_IMMUNE) == false) then call UnitDamageTargetBJ(credit, target, damage, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL) endif endfunction function Percent2Colour takes real percent returns real return (percent / 100.00) * 255.00 endfunction function Colour2Percent takes real colour returns real return (colour / 255) * 100 endfunction function DrainHpFromGroup takes unit credit, group whichGroup, real amount, boolean acceptAllies returns nothing local real AmountPerPerson = amount / I2R(CountUnitsInGroup(whichGroup)) local group GroupNow = whichGroup local unit CurrentUnit loop set CurrentUnit = FirstOfGroup(GroupNow) exitwhen (CurrentUnit == null) if(acceptAllies == false) and (AreUnitsEnemy(credit, CurrentUnit) == false) then else call SpellDamageUnit(credit, CurrentUnit, AmountPerPerson) call GroupRemoveUnitSimple(CurrentUnit, GroupNow) endif endloop call DestroyGroup(GroupNow) set AmountPerPerson = 0.00 set GroupNow = null endfunction // Game Cache Usage Functions // AttachEffectForTime(On what unit(unit), Where to attach(string), Attach hat(string path), Attachment duration(real)) // AttachEffectForTime(null, "", "", 0.00) function AttachEffectForTime_Destroy takes nothing returns nothing local effect CurrentEffect = I2E(GetStoredIntegerBJ("AttachEffect", "AttachEffect", GC())) call TriggerSleepAction(GetStoredRealBJ("AttachDur", "AttachDur", GC())) call DestroyEffect(CurrentEffect) set CurrentEffect = null endfunction function AttachEffectForTime takes unit whichUnit, string attachmentPoint, string filePath, real dur returns nothing call AddSpecialEffectTargetUnitBJ(attachmentPoint, whichUnit, filePath) call StoreIntegerBJ(H2I(GetLastCreatedEffectBJ()), "AttachEffect", "AttachEffect", GC()) call StoreRealBJ(dur, "AttachDur", "AttachDur", GC()) call ExecuteFunc("AttachEffectForTime_Destroy") endfunction // AttachEffectToGroupForTime(On what group(group), Where to attach(string), Attach what(string), Attachment duration(real)) // AttachEffectToGroupForTime(null, "", "", 0.00) function AttachEffectToGroupForTime takes group whichGroup, string attachmentPoint, string filePath, real dur returns nothing local group groupNow = whichGroup local unit unitNow loop set unitNow = FirstOfGroup(groupNow) exitwhen (unitNow == null) call AttachEffectForTime(unitNow, attachmentPoint, filePath, dur) call GroupRemoveUnitSimple(unitNow, groupNow) endloop set groupNow = null set unitNow = null endfunction Heres my code for my spell: JASS:constant function Spell_SoulDefection_Radius takes integer lvl returns real return 400.00 + (100.00 * lvl) endfunction constant function Spell_SoulDefection_SpellAbilityID takes nothing returns integer return 'A000' endfunction constant function Spell_SoulDefection_Damage takes integer lvl returns real return 100.00 * lvl endfunction function Spell_SoulDefection_Conditions takes nothing returns boolean return GetSpellAbilityId() == Spell_SoulDefection_SpellAbilityID() endfunction function Trig_Soul_Defection_Actions takes nothing returns nothing local unit caster = GetSpellAbilityUnit() local integer lvl = GetUnitAbilityLevelSwapped(Spell_SoulDefection_SpellAbilityID(), caster) local location casterpoint = GetUnitLoc(caster) local group enemies = GetUnitsInRangeOfLocMatching(Spell_SoulDefection_Radius(lvl), casterpoint, null) local real dmg = Spell_SoulDefection_Damage(lvl) call DrainHpFromGroup(caster, enemies, dmg, false) if(FirstOfGroup(enemies) != null) then call SetUnitLifeBJ(caster, GetUnitHp(caster) + dmg) endif call AttachEffectForTime(caster, "overhead", "Abilities\\Spells\\Undead\\ReplenishMana\\ReplenishManaCaster.mdl", 5.00) call AttachEffectToGroupForTime(enemies, "overhead", "Abilities\\Spells\\NightElf\\SpiritOfVengeance\\SpiritOfVengeanceBirthMissile.mdl", 7.50) call DestroyGroup(enemies) call RemoveLocation(casterpoint) set caster = null set casterpoint = null set enemies = null endfunction //=========================================================================== function InitTrig_Soul_Defection takes nothing returns nothing set gg_trg_Soul_Defection = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_Soul_Defection, EVENT_PLAYER_UNIT_SPELL_EFFECT ) call TriggerAddCondition( gg_trg_Soul_Defection, Condition( function Spell_SoulDefection_Conditions ) ) call TriggerAddAction( gg_trg_Soul_Defection, function Trig_Soul_Defection_Actions ) endfunction Thx in advance |
| 04-26-2006, 07:50 PM | #2 |
I wanted to figure out the cause, but I got terminated with a bunch of wrong, really wrong things that are not the reason of your problem but are really bad. please stop it - Stop the usage of the silly BJ functions If JASS wasn't a super slow language, then the name helping functions you made would have been a great idea, but JASS is a very slow language so they are really going to be problematic. functions like IsRealNegative and MidPointBetweenReals really seem like a bad idea to me, they are so common operations that having them directly would be much easier to read, it will also be faster to type. functions like GetUnitStrength ,make me wonder if you ever saw common.j JASS:native GetHeroStr takes unit whichHero, boolean includeBonuses returns integer native GetHeroAgi takes unit whichHero, boolean includeBonuses returns integer native GetHeroInt takes unit whichHero, boolean includeBonuses returns integer Remove GetUnitHp it is easier to use GetWidgetLife . SpellDamageUnit is terribly wrong, Just use DAMAGE_TYPE_FIRE or other magical damage type. In the DrainHPFromGroup function I don't understand this: local group GroupNow = whichGroup why are you using another group variable? Percent2Colour and Colour2Percent are bad for 2 reasons. first of all blizzard.j has: JASS://=========================================================================== // Converts a percentage (real, 0..100) into a scaled integer (0..max), // clipping the result to 0..max in case the input is invalid. // function PercentToInt takes real percentage, integer max returns integer local integer result = R2I(percentage * I2R(max) * 0.01) if (result < 0) then set result = 0 elseif (result > max) then set result = max endif return result endfunction //=========================================================================== function PercentTo255 takes real percentage returns integer return PercentToInt(percentage, 255) endfunction Second if you ever need to use those functions it means that you are using silly BJ functions that you shouldn't be using. -- Now that I check things it seems you are using the enemies group after you destroyed it. your DrainHpFromGroup will destroy the enemies group man. |
| 04-26-2006, 08:35 PM | #3 |
Well, im fairly newish to jass, i was thinking i would get a list from somebody with hundreds of problems with me functions. I'v seen common.j and blizzard.j, but not read every function, i just examined what they both did. In the past, i'v learn that if you use the same type of method or operation in a function, then you should make that into a function, as good programming, which iv used in my java, but i dident know jass went slow =/.. Il take it into mind and just do what i need done. My Percent2Colour uses slightly less code :D I surpose BJ's are lame, but most this was just really for testing, not for 100% leak free and as fast as it could be, i would change the BJ's to the natives once i found whats going on And no, unfortunatly, iv never saw the natives GetHeroStr/Agi/Int |
