• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] -repick

Status
Not open for further replies.
Level 4
Joined
May 23, 2010
Messages
83
Hello y'all, I've done my hero-pick system: You 'buy' a hero from a 'tavern'. The problem is: the repick system. It's basically simple: you remove your current hero from the game and create another unit to buy another hero. This may sound stupid: I can't re-buy a hero I just picked. For example, I bought an 'Archer' and typed '-repick'. The code creates another unit on the area (so I can buy another hero) and I can chose any hero except the one I repicked. It's not a big deal, and I hope I can fix it, if anybody can help me :)

JASS:
    private function Repick takes nothing returns nothing
        
        local real     x = GetRectCenterX(gg_rct_heropickarea)
        local real     y = GetRectCenterY(gg_rct_heropickarea)
        local player   p = GetTriggerPlayer()
        local integer  i = GetPlayerId(p)
        local integer ih = 0
        local unit     u = CreateUnit(p, 'e000', x, y, 0)
        call RemoveUnit(Hero[i])
        set FOG[i] = CreateFogModifierRect(p, FOG_OF_WAR_VISIBLE, gg_rct_heropickarea, false, true)
        call FogModifierStart(FOG[i])
        call SetUnitAnimation(u, "birth")
        
        if GetLocalPlayer() == p then
            call ClearSelection()
            call SelectUnit(u, true)
            call Refresh()
        endif
        
        loop
            call SetPlayerTechMaxAllowed(p, Code[ih], 1)
            exitwhen ih >= Count - 1
            set ih = ih + 1
        endloop
        
        set u = null
        set p = null
    endfunction
    private function onInit takes nothing returns nothing
    
        local player     p
        local integer    i = 0
        local trigger   rp = CreateTrigger()

        call TriggerAddAction(rp, function Repick)

        loop
            set p = Player(i)
            call TriggerRegisterPlayerChatEvent(rp, p, "-repick", true)
            call TriggerRegisterPlayerUnitEvent(tr, p, EVENT_PLAYER_HERO_LEVEL, null)
            exitwhen i >= 9
            set i = i + 1
        endloop
endfunction

EDIT: all globals are declared. some in other triggers (thats the reason i dont paste them)
EDIT EDIT: the code works properly. I just can't pick the hero I've already picked.
 
Last edited:
Level 14
Joined
Apr 20, 2009
Messages
1,543
Is it me or do these variables:

JASS:
    // **MULTIBOARD STUFF**
    set FOG[i]              = CreateFogModifierRect(p, FOG_OF_WAR_VISIBLE, gg_rct_heropickarea, false, true)
    set Class[i]            = ""
    set Icon[i]             = "ReplaceableTextures\\CommandButtons\\BTNSelectHeroOff.blp"
    set Level[i]            = 0
    // **HERO GLOBAL VAR**
    set Hero[i]             = null
    //**CAMERA SYSTEM GLOBAL VARS**
    set AllowCamDistance[i] = false
    set AllowCamRotation[i] = false
    set AllowUnitLock[i]    = false
    set CamUnit[i]          = null
    set CamDistance[i]      = 1650
    set CamAngle[i]         = 90
    set CamLocX[i]          = x
    set CamLocY[i]          = y

not exist? I guess you want to use udg_ infront of it? Or define the local variables first?
Unless they are in a global block ofcourse :S...

Also, are you sure you need to use this:

JASS:
local integer  i = GetPlayerId(p)

instead of this?:

JASS:
local integer  i = GetPlayerId(p)+1

Have you declared the 0 indexes of the arrays?

What is gg_rct_heropickarea?
Isn't that a region created with the region pallete ^.^?
 
Level 4
Joined
May 23, 2010
Messages
83
Unless they are in a global block ofcourse :S...

Yes, of course! I edited non-important parts of the trigger for better understanding. All globals exsist, I just dont paste my global block because there are too many unrelated vars. I believe that the reason is not the triggers but the game constants or objects, idk.
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Yes, of course! I edited non-important parts of the trigger for better understanding. All globals exsist, I just dont paste my global block because there are too many unrelated vars. I believe that the reason is not the triggers but the game constants or objects, idk.

Are you sure this got nothing to do with the stock amount of the hero your picking?
Obviously if the stock amount is 1 and the unit gets sold from the tavern it won't be sold anymore since there's no unit left in the stock :p
And if the stock never replenishes, the unit will be removed from the units that can be sold by the tavern.
Are you saying that the hero get's removed from a tavern when it is picked?
I assumed since your creating a dummy at a heropickarea that the dummy picks the hero from a tavern...
 
Level 4
Joined
May 23, 2010
Messages
83
Sure, that's it. But the units are not 'sold out'. It's a multiplayer map and I've already tested with a friend, we can pick the same hero.

I think it has something to do with the game (if anyone has ever played PG on wc3, you can't buy a hero you already have) and I think that's the problem.

Even removing the hero, you can't buy another equal one, and I don't know if there's anything that can fix it.

EDIT: the stock replenish time is 2 seconds.
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Even removing the hero, you can't buy another equal one, and I don't know if there's anything that can fix it.

That's odd, it does work in my map...
And yes a player should be abled to have 2 of the same hero's at once, tested and worked.

So... The unit can still be sold by the tavern but it simply doesn't get created when you click on the button to buy the hero?
And this does seem to work for other hero's after repicking??? If yes then this means it got nothing to do with the dummy unit being out of range or the dummy unit not being selected by the local player.

Have you already debugged with some text messages to check if the dummy gets created, if the dummy is being selected etc etc?
 
Level 4
Joined
May 23, 2010
Messages
83
It happens to all the heroes (there are 4 heroes total: so if I 'repick' all 4 heroes, I won't be able to play, since they all will be unavailable).

What happens is: the icon simply doesn't show up.

EDIT: I already changed on gameplay constants (Techtree - Heroes) but it doesn't work either.
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Level 4
Joined
May 23, 2010
Messages
83
JASS:
globals
        private integer array Code
endglobals
private function onInit takes nothing returns nothing
        set Code[0] = 'H001'
        set Code[1] = 'H002'
        set Code[2] = 'H003'
        set Code[3] = 'H004'
endfunction

EDIT: I read the article, that means I should use the BJ instead? I'll find a way.
EDITEDIT: I took the native (from the BJ, duh) and found the number should be -1, so:

JASS:
call SetPlayerTechMaxAllowed(p, Code[ih], -1)

Tested and now I have good news: It worked! I'm happy but still confused. why should it be a negative number? sooo strange. Thanks for the help also!
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
JASS:
globals
        private integer array Code
endglobals
private function onInit takes nothing returns nothing
        set Code[0] = 'H001'
        set Code[1] = 'H002'
        set Code[2] = 'H003'
        set Code[3] = 'H004'
endfunction

I read the article, that means I should use the BJ instead? I'll find a way.

Basically what your doing here when using this:
JASS:
call SetPlayerTechMaxAllowed(p, Code[ih], 1)

Is your saying: set the maximum tech allowed for that unit type to be 1.
So after the player has picked a unit of this type, the player is not allowed to pick another unit of this same type.
This will be done locally for the player who has already picked that unit type.
So other players are allowed to pick the same unit type, only the player who already picked this unit type won't see the icon for the unit he already picked.

(Just a second I haven't started JNGP yet, I've got to make sure that what I say is correct :p)
 
Level 4
Joined
May 23, 2010
Messages
83
Yes, you are correct, I've just tested that. And I get it. When you put -1 (is a 'impossible' number, as it doens't belong to the natural numbers) the game itself lets you buy as many as you want to. So if i change to 2, I would be allowed to (theorically) 'repick' the sabe hero 2 times before it happens again.
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Yes, you are correct, I've just tested that. And I get it. When you put -1 (is a 'impossible' number, as it doens't belong to the natural numbers) the game itself lets you buy as many as you want to. So if i change to 2, I would be allowed to (theorically) 'repick' the sabe hero 2 times before it happens again.

Yay generall knowledge without WE ftw! ^.^

EDIT: there's still one thing I don't get:
When you put -1 (is a 'impossible' number, as it doens't belong to the natural numbers) the game itself lets you buy as many as you want to.

Why call the function at all if the purpose is to buy as many as you want to?

The idea behind it is to remove all the units that can be sold to a player who has already bought a hero right?
Wouldn't it be easyer to do something like: whenever a player has a hero, remove all the units from the tavern.
JASS:
call SetPlayerTechMaxAllowed(p, Code[ih], 0)
Whenever the player repicks, add all the units to the tavern.
JASS:
call SetPlayerTechMaxAllowed(p, Code[ih], -1)
Of course since you have to specify which player, it's being done locally.

B.t.w. I have no idea if this works or if there is a more efficient way of doing this :p
 
Level 4
Joined
May 23, 2010
Messages
83
I did it and it works.
JASS:
function SetPlayerUnitAvailableBJ takes integer unitId, boolean allowed, player whichPlayer returns nothing
    if allowed then
        call SetPlayerTechMaxAllowed(whichPlayer, unitId, -1)
    else
        call SetPlayerTechMaxAllowed(whichPlayer, unitId, 0)
    endif
endfunction

I created a trigger in GUI and turned into text. Now the secret is discovered.
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Great stuff, I also learned something new here :goblin_good_job:

Ow b.t.w. you could've also checked the function list from your JNGP to check what the native SetPlayerUnitAvailableBJ does ^.^

EDIT: nevermind I missed this part:
EDITEDIT: I took the native (from the BJ, duh) and found the number should be -1, so:
I see you already know of course -,^

This part just got me confused:
I created a trigger in GUI and turned into text. Now the secret is discovered.
As in: why would you do that to show what the native does xD
 
Status
Not open for further replies.
Top