HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

GetAttackDamage

03-30-2004, 04:42 AM#1
Grasthik
I've written this function for a combat system. I've gotten it to this:
Code:
function GetAttackDamage takes unit u returns real
    local real i = 500
    local real i2 = 0
    local unit u2 = null
    call CreateNUnitsAtLoc( 1, 'h000', Player(13), GetRectCenter(GetPlayableMapRect()), bj_UNIT_FACING )
    set u2 = GetLastCreatedUnit()
    call CreateNUnitsAtLoc( 1, GetUnitTypeId(u), Player(13), GetRectCenter(GetPlayableMapRect()), bj_UNIT_FACING )
    set u = GetLastCreatedUnit()
    call IssueTargetOrder( u, "attack", u2 )
    call TriggerSleepAction( 1.00 )
    set i2 = GetUnitStateSwap(UNIT_STATE_LIFE, u2)
    call ExplodeUnitBJ( u2 )
    call RemoveUnit( u )
    set i = i - i2
    return i
endfunction

I know there are some problems with this function, namely the time it takes for a unit to attack and the defense/buffs of the recieving unit. I guess it would be possible to add the buffs (going back to do that now) to the unit, but I find it difficult to bypass the time it takes to attack the unit and find the armor of the unit efficiently. If not I guess I'll have to match unit codes with a unit that has the same armor/amount...which seems very inefficient. Maybe I'm just approaching this wrong.

I can provide more code/information that the system uses if you need it. Right now I assume it works but I have to use a wait and armor isn't taken into account.

Will edit in the changes when I add in the buff information.

Edit: Meh. Looked at the buffs and I can't see a standard Blizzard function that will allow me to read the buffs on a unit.
03-30-2004, 12:20 PM#2
mini.me
How about just making it so when a unit is being attacked get the attacking unit, and i think you can get the damage of the unit from there fairrly easily. If you want to get the damage being done you would have to make it go through a searies of equasions like for armor and *2 for critical strike. Anougher possibility would be getting the units current health and subtracting from max health every time it gets attacked.
03-30-2004, 12:48 PM#3
AIAndy
If you use the Unit is damaged event, you can get the damage an attack caused.
03-30-2004, 03:17 PM#4
Grasthik
Won't work. The combat system is similar to Morrowind's. If you haven't played Morrowind:
You swing a sword. If nothing is there, nothing gets damaged. If something is there damage is taken into effect.
So, the way I am trying to go about it is play the unit's attack animation, and damage the recieving unit if the unit is within the required field (25 Degrees each way, 400 radius atm. I need to reduce the radius I know). I just don't see any other way to make this happen, and once again, I can provide more information, sorry about not clearing this up before.

Edit: Mini.me, I did read your post but you didn't quite make much sense. I know I would have to go through a series of equations, but I don't see any efficient way to go about doing that.
03-30-2004, 04:51 PM#5
Cubasis
Quote:
Originally Posted by mini.me
and i think you can get the damage of the unit from there fairrly easily.

Sadly, they don't give us any access functions to get the damage of a unit unless with the UnitIsDamaged event. As there are so many factors that come in when damage is formulated, that what would such a function return? as there are firstly lower and upper bounds, this is defined with NrOfDies and DieSize or whatever, and we have no way to get those values in-game....So either are storage arrays the way to go, or make your own damage formula (remember, you can get the str/agi/int and stuff from the heros).

Cubasis
03-30-2004, 05:11 PM#6
Grasthik
Not sure if that was directed at me or not Cub but yeah, I understand that. The thing is that my function provides the randomization of the dice rolls and also for *some* kind of armor to be put into place. I think it is better this way than a simple formula of stats, because, as you said, there are too many variables that go into this to get a proper formula. This is the best I can come up with.

I forgot to add a hide unit function for the "u" unit. Consider that in there.

Edit: Is it possible to create pointers to the unit stats via Precompiler?
03-31-2004, 08:20 AM#7
AIAndy
You can automatically create code from tables with the ejass precompiler so you could use that to create code that stores the info into gamecache so that you can retrieve it later.

Another idea would be to have a dummy unit do the actual attack on the enemy. That way both armor and buffs would be taken into account (at least of the targetted unit, for the attacking unit you'd somehow need to copy the buffs or instead use the real unit for the attack and place a dummy unit in its place in the meantime)