• 🏆 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!

Paying for the training of an Allied unit

Status
Not open for further replies.
Level 6
Joined
May 11, 2010
Messages
236
So pretty much, players on the map can train units from an allied npc's buildings, but the player's don't lose any resources and the npc has to pay for it even if the player is the one that selected to train the unit because the players have shared unit control with said npc. However, I don't want to change the the buildings' ability to 'trains a unit' to 'sells a unit' because it loses the build time for the unit.

Is there anyway to to make players' pay for the training of a unit from a allied structure?
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Create a very, very simple trigger like this?

  • Training
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to (==) Altar of Kings
    • Actions
      • Player - Set (Owner of (Trained unit)) Current gold to (((Owner of (Trained unit)) Current gold) - 200)
      • Player - Set (Owner of (Trained unit)) Current lumber to (((Owner of (Trained unit)) Current lumber) - 200)
 
Level 6
Joined
May 11, 2010
Messages
236
Create a very, very simple trigger like this?

  • Training
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to (==) Altar of Kings
    • Actions
      • Player - Set (Owner of (Trained unit)) Current gold to (((Owner of (Trained unit)) Current gold) - 200)
      • Player - Set (Owner of (Trained unit)) Current lumber to (((Owner of (Trained unit)) Current lumber) - 200)

No, the gold will be needed before the unit begins training, not after. And that also doesn't detect what player initialized the training. (Also, the trained unit belongs to the npc, it's just the players that begin the training.)
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
My mistake, either ways you could ofcourse change the Gold cost and Lumber cost inside the Object editor for the units you want trained....
If you really want to make sure that it's done for the corresponding player,
you could use GetLocalPlayer() to see if the local player equals the player selecting the tavern and respectively change the ownership to that player locally.

For example:
  • Unit Selection
    • Events
      • Player - Player 1 (Red) Selects a unit
      • Player - Player 2 (Blue) Selects a unit
      • Player - Player 3 (Teal) Selects a unit
      • Player - Player 4 (Purple) Selects a unit
      • Player - Player 5 (Yellow) Selects a unit
      • Player - Player 6 (Orange) Selects a unit
      • Player - Player 7 (Green) Selects a unit
      • Player - Player 8 (Pink) Selects a unit
      • Player - Player 9 (Gray) Selects a unit
      • Player - Player 10 (Light Blue) Selects a unit
      • Player - Player 11 (Dark Green) Selects a unit
      • Player - Player 12 (Brown) Selects a unit
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to (==) Tavern
    • Actions
      • Custom script: if (GetLocalPlayer() == Player(GetPlayerId(GetTriggerPlayer()))) then
      • Unit - Change ownership of (Triggering unit) to (Player((Player number of (Triggering player)))) and Retain color
      • Custom script: endif
I tested this and it seems to work fine for me.
If this somehow causes a desynchronization when several players select the building at once,
you might want to use a invisible dummy unit for each player and make the players select the dummy unit for the corresponding player when selecting the original tavern.

That should fix your issue.
 
Level 4
Joined
Aug 5, 2011
Messages
99
that will cause problems in multiplayer ^^ if 2 people select it at the same time, evrything is fucked, the player who first selected it could use up the gold from the second one. would need to clear selection for the first one if u do that.. and that wont look too good either :s
maybe try to give the building to a player with fullshared unit control to evryone, when it starts training a unit, check whether the triggering player has enough gold, if not then cancel the training... make sure u give infinate resources to that player then ^^
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
My mistake, either ways you could ofcourse change the Gold cost and Lumber cost inside the Object editor for the units you want trained....
If you really want to make sure that it's done for the corresponding player,
you could use GetLocalPlayer() to see if the local player equals the player selecting the tavern and respectively change the ownership to that player locally.

For example:
  • Unit Selection
    • Events
      • Player - Player 1 (Red) Selects a unit
      • Player - Player 2 (Blue) Selects a unit
      • Player - Player 3 (Teal) Selects a unit
      • Player - Player 4 (Purple) Selects a unit
      • Player - Player 5 (Yellow) Selects a unit
      • Player - Player 6 (Orange) Selects a unit
      • Player - Player 7 (Green) Selects a unit
      • Player - Player 8 (Pink) Selects a unit
      • Player - Player 9 (Gray) Selects a unit
      • Player - Player 10 (Light Blue) Selects a unit
      • Player - Player 11 (Dark Green) Selects a unit
      • Player - Player 12 (Brown) Selects a unit
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to (==) Tavern
    • Actions
      • Custom script: if (GetLocalPlayer() == Player(GetPlayerId(GetTriggerPlayer()))) then
      • Unit - Change ownership of (Triggering unit) to (Player((Player number of (Triggering player)))) and Retain color
      • Custom script: endif
I tested this and it seems to work fine for me.
If this somehow causes a desynchronization when several players select the building at once,
you might want to use a invisible dummy unit for each player and make the players select the dummy unit for the corresponding player when selecting the original tavern.

That should fix your issue.

why dont clear the selection for all player after change owner thing? :D
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
helekiller said:
that will cause problems in multiplayer ^^ if 2 people select it at the same time, evrything is fucked, the player who first selected it could use up the gold from the second one. would need to clear selection for the first one if u do that.. and that wont look too good either :s
maybe try to give the building to a player with fullshared unit control to evryone, when it starts training a unit, check whether the triggering player has enough gold, if not then cancel the training... make sure u give infinate resources to that player then ^^

First of all, you do know what GetLocalPlayer() does?

It gets the local player.
This way you can for example show multiboards to a local player instead of having to show it to all players.
I was hoping that this would be possible for unit ownership.
Causing the building to be owned by every local player selecting it.
But you're probably right that it would cause a desynchronization.

A desynchronization means that the server is sending incorrect information to the client.
The server in this case would be the host and the client the player.
When a desynchronization occurs, a player will see stuff on his screen that is not there or not see stuff that actually is there.
Usually this causes the player to disconnect.

I did however give an alternative... Dummy taverns ;)
You can achieve a lot of cool stuff with dummy's alright :D
Simply create invisible dummy units within the tavern.
Then when a player selects the tavern you can change it's selection to select the dummy unit for the corresponding player.
All that would need to be done then is set the gold and lumber cost for the units who are trained accordingly in the object editor.
This would solve his issue.

shadowvzs said:
why dont clear the selection for all player after change owner thing? :D
Then how can that player train a unit? :)
I was hoping that it would be possible to change the owner locally, causing the unit to have multiple owners.
 
Status
Not open for further replies.
Top