• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[General] Experienced divided in range

Status
Not open for further replies.
Level 8
Joined
Aug 4, 2008
Messages
279
So, on my map, theres a max of 8 players.
Everyone controls one hero, thus gains exp.
How can I make, when a unit dies near 1+ heroes, to not divide the exp by the amount of heroes, but to be the same to all of them, if they are in range?
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
There is a rather simple one, I don't remember who is the creator.
 

Attachments

  • Advanced Exp and Bounty System v 1.0.w3x
    37.4 KB · Views: 36
Level 15
Joined
Aug 7, 2013
Messages
1,337
Here is an example of a custom exp system. It's in vJASS and it's not perfect, but basically it gets fired when a creep dies.

You wouldn't be able to copy and paste it into your map, but rather you can sort of see the functions and structure your custom exp system would need.

Basically when a creep dies, fire a function on it. Calculate how much exp each hero should gain, then loop through all players. If their hero is in X range of the dead creep, then add the appropriate amount of exp to that hero. You will have to disable normal exp gain as others have mentioned.

JASS:
library ExpTrig requires CreepRegionTable

globals
	private real EXP_RANGE = 1000.0
endglobals

function expExec takes Monster creep returns nothing
	local integer i = 0 //loop through all the players
	local integer j = 0 //loop through party and farm monsters
	local texttag tt //show the exp gained by each monster
	local PlayerData pd
	local Monster pm
	local unit m
	local unit pc
	local unit u = creep.u
	local integer expGain = GetHeroLevel(creep.u) * 10
	loop
		exitwhen i == TOTAL_PLAYERS
		set pd = playerDatum[i]
		set pc = pd.pc.u
		if IsUnitInRange(pc, u, EXP_RANGE) then //check to see if monster master is in range
			set j = 0
			//give the player some gold for now
			call SetPlayerState(players[i], PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(players[i], PLAYER_STATE_RESOURCE_GOLD) + expGain)
			loop //loop through the party and make sure each monster is in range
				exitwhen j == MAX_PARTY_SIZE
				if pd.party.monsters[j] != 0 then
					set pm = pd.party.monsters[j]
					set m = pm.u
					if IsUnitInRange(m, u, EXP_RANGE) and not pm.isDead() then
						if GetHeroLevel(m) < pm.maxLvl then
							call printl(I2S(pm.maxLvl))
							call print(pm.toString())
							set tt = CreateTextTag()
							call SetTextTagText(tt, "Exp +" + I2S(R2I(expGain)), 0.02)
							call SetTextTagVisibility(tt, false) //hide text tag
							if players[i] == GetLocalPlayer() then //show tag only if its the owning player
								call SetTextTagVisibility (tt, true)
							endif
							call SetTextTagPosUnit(tt, m, 0)
							call SetTextTagColor(tt, 190, 0, 255, 255)
							call SetTextTagVelocity(tt, 0, 0.04)
							call SetTextTagPermanent(tt, false)
							call SetTextTagLifespan(tt, 3)
							call SetTextTagFadepoint(tt, 2)
							call AddHeroXP(m, expGain, true)
							set tt = null
						endif
					endif
				endif
				set j = j + 1
			endloop
		endif
		set i = i + 1
	endloop
endfunction

endlibrary
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
how would I setup 100 different exp amounts?

You could assign exp based on the level of the creep. So something like

JASS:
set expGain = GetUnitLevel(creep) * 10 //creeps 10 times their level for experience when killed

Or you could use a hashtable / Table to store how much exp is given for each creep.

JASS:
set expTable['hfoo'] = 50 //50 exp for killing a footman
set expTable['Hpal'] = 100 //100 exp for killing a human paladin

So when a unit dies, you get its unit type id and then pass it as a key to the Table. It will then return the base exp for that unit. Then do whatever modifiers you want (e.g. a scroll of experience which boosts exp gain, or perhaps your heroes gain less exp the higher level they are).
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
Im sorry, i dont understand vjass that much, how would i make the trigger recognise the dying unit, and search the hashtable for the exp value?

Assuming you use a Unit Dies - Owned by Neutral Hostile, you can get the unit type and exp like this

JASS:
local unit u = GetDyingUnit()
local integer unitType = GetUnitTypeId(u)
local integer expGain = expTable[unitType]

So if a footman died, unitType = 'hfoo'.

But you should listen to CM and probably keep it simple for now. Just use the level of the unit to determine how much exp to dole out.
 
Last edited:
Status
Not open for further replies.
Top