| 05-10-2005, 10:06 AM | #1 |
Hey everyone, another idea for my RPG I need help with. Does anyone know how to make XP gained by hitting an enemy rather than killing it? I've seen this done on the FFTactics map that is like DOTA. I figure if I did that, it would keep players from simply following a high level around, and at the same time still allow people to group up with others around the same level without having to worry about the strongest one always getting the kill. If anyone could offer some help i'd realy appreciate it! ^-^ |
| 05-10-2005, 11:19 AM | #2 |
A simple method would just be detecting when a unit attacks, however, if you wanted the experience gained per attack to depend on the ammount of damage dealt, then you would need to use the unit takes damage specific unit event which you would dynamicaly add for each unit that is created in the map... a bit difficult, the use of the generic unit event unit is attacked is a lot simpler. |
| 05-10-2005, 09:02 PM | #3 |
Not nearly so hard, Anitarf. Code:
Exp Per Hit
Events
Unit - A unit Is attacked
Conditions
Actions
Hero - Add (Integer((Damage taken))) experience to (Attacking unit), Show level-up graphics
|
| 05-10-2005, 09:05 PM | #4 |
really damage taken can be taken from an attack? i thought it was only for 'a unit takes damage' events... |
| 05-10-2005, 09:09 PM | #5 | |
Quote:
|
| 05-10-2005, 09:16 PM | #6 | |
Quote:
|
| 05-10-2005, 09:36 PM | #7 |
Oh really? Meh, I knew there was something I didn't know. Since I don't want to seem useless, I'll just write it out... Code:
Add Units
Events
Time - Every 5.00 seconds of game time
Conditions
Actions
Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Custom value of (Picked unit)) Equal to 0
Then - Actions
Set CurrentNum = (CurrentNum + 1)
Set unitsAdded[CurrentNum] = (Picked unit)
Unit - Set the custom value of (Picked unit) to 1
Trigger - Add to Experiance <gen> the event (Unit - unitsAdded[CurrentNum] Dies)
Else - Actions
Attacker
Events
Unit - A unit Is attacked
Conditions
Actions
Set Attacker = (Attacking unit)
Experiance
Events
Conditions
Actions
Hero - Add (Integer((Damage taken))) experience to Attacker, Show level-up graphicsDisclaimer: This trigger might really be laggy if you have several thousand units. Hopefully though this doesn't happen. It might also be nice for a remove unit from event trigger, but I'm not sure if that call even exists. |
| 05-10-2005, 09:51 PM | #8 |
Thanks alot guys! I'll start work on that ^-^ |
| 05-10-2005, 11:11 PM | #9 | |
Quote:
First of all, I don't see why at all do you need a unit array to store added units when you already use the custom values. But, actually, you don't need either, if you approach this trigger from a different perspective: Code:
AddNewUnitsToExperience
Events:
a unit enters (playable map area)
Conditions:
Actions:
Trigger - Add to Experience <gen> the event (Unit - (triggering unit) Takes damage)Code:
Experience
Events:
Conditions:
Actions:
If all conditions are true then do actions else do actions
If - conditions:
((damage source) is a Hero) equal to True
Then - actions:
set experience of (damage source) = (current experience of (damage source)) + ((damage taken)*([i]an experience factor, you'll probably want to have one[/i]))
Else - actions:
[i]I assume a player can only have a single hero, so I'll keep this last part which gives the hero experience whenever his summoned units or mercenaries deal damage simple; if you don't have such units in your map or you don't want their damage to give experience to the hero, you can skip this part[/i]
Set TempPoint = (position of (damage source))
Set TempUnitGroup = (units within ([i]whatever the experience gain range you want to have[/i]) range of TempPoint matching ((((matching unit) is a Hero) equal to True) and ((owner of matching unit) equal to (owner of (damage source)))))
set experience of (random unit from (TempUnitGroup)) = (current experience of (random unit from (TempUnitGroup))) + ((damage taken)*([i]an experience factor, this one can be different if you want[/i]))
custom script: call RemoveLocation( udg_TempPoint )
custom script: call DestroyGroup( udg_TempUnitGroup )
[i]The custom scripts clear the memory leaks, otherwise they would accumulate quite fast with many units attacking.
If you don't want to have any limitation on the experience gain range from the player's summons attacking, you don't need to use the "units within range matching condition" function, just use "units in (playable map area) matching condition", you then also don't need the TempPoint variable[/i]If you create lots of new units during the course of one game (don't know how many is lots, though), all those events being added and never cleared might cause performance issues. In such a case, you would need to, using JASS, create entire triggers instead of just adding events to an existing one and then link them to their respective units using either variable arrays or gamecache with the help of object handles... However, it's getting late, I need some sleep, don't have time to research how to do that right now. Anyway, it's even possible that such a system already exists in the repository. |
| 05-11-2005, 04:25 AM | #10 |
good call anitarf, it has my seal of approval for whatever that's worth -- its how i would have set up the trigger in the first place also don't worry about event build-up, generally i haven't seen performance issues from such a design so far also for future notice to other people, consider the event 'unit is attacked' almost never useful for checking 'hit' events, because they are not the same thing to elaborate, i played in 1 map where a damage effect was triggered on unit attacked for my unit who had a long cooldown, except all i had to do was wait till it begun to attack, hit stop, the trigger would still fire, my unit wouldn't actually go through with his natural attack, and i'd be able to strike again within a milisecond |
| 05-11-2005, 05:14 PM | #11 |
Actually I would have used: http://www.wc3jass.com/viewtopic.php?t=2020 Then at map init: Custom Script: AttackDetect_Initialize() Then when you know which unit should get experience when it hits: call AttackDetect_AddFunc(unit,"Trig_GiveExpWhenHit_Actions") Now create a trigger called GiveExpWhenHit : Events: none Conditions: none Actions: Give +10 Experience to (Event response Source of damage) |
| 05-11-2005, 06:19 PM | #12 |
i take it that dynamically creates damage triggers attached to each unit as they are 'attacked' and destroys them as they die? so you don't have a single trigger with a lot of events piled into it? if i misread that package whoops i'm tiredi just woke up |
| 05-12-2005, 10:04 PM | #13 |
It makes it as sure as possible that it only detects the hits of attacks, but in other ways it does what you said. |
| 05-13-2005, 12:12 AM | #14 | |
Quote:
doesn't the event 'unit takes damage' innately only detect when a unit is hit by an attack? or did i miss something? |
| 05-14-2005, 05:53 AM | #15 |
I'm sorry you guys... but I'm lost. I was hoping I could learn from this. :P That's what I thought Raptor... Is there an exception? |
