• 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.

[General] Castle Fight styled game - win, rounds, random pick

Status
Not open for further replies.
Level 2
Joined
Mar 8, 2017
Messages
19
I would like to create a game that is similar to the Castle Fight games. The code my game lacks are:
- how to let hosting player decide number of rounds
- make the builders spawn randomly for players when player 1 types "-ar"
- make the players chose their builder when player 1 types in "-ap"
- how to reset everything when a round is over (and that is when the town hall is destroyed)

I somehow manged to make the units uncontrollable when entering the map and moving towards the enemy side attacking any thing in their path by watching some youtube videos and reading some old posts... However, the winning condition and rounds seem above my level. If there is a kind soul out there who could help me with my game and explain it on a noob level it would be much appreciated!
I apologize if I may have broken rules which applies to posting, this is my first post on this forum.
 
Level 30
Joined
Aug 29, 2012
Messages
1,383
- To decide the number of rounds in chat like in CF, you have to use substrings to detect what number the host player types after "-rr" for instance.
- To make random builders, you have to save your builders in a unit variable with an array (e.g. Unit[1] = Human builder, Unit[2] = Orc builder, etc.). Then, when the round starts, just roll random number from 1 to (number max of builders) and assign one different to each player.
- Simply detect when player one types "-ap" in chat and then create a unit like a tavern or anything you want, so that players can pick their race.
- Resetting everything is a bit more difficult, you would have to respawn the town hall, remove every building in the map, remove every unit, but also probably reset your variables and reset player gold, lumber, etc.
 
Level 2
Joined
Mar 8, 2017
Messages
19
Random hero pick trigger problem | The Helper

I found an old post containing the code for making random units, however I dont understand these lines of code in the post:

Set RandomPickInteger = (Random integer number between 1 and 14)
Set Herostart[(Integer A)] = ((Player((Integer A))) start location)

I have to make strings if I've understood it correctly. However I don't really understand this piece of code. When I do it I get a box saying
Set RandomPickInteger[variable] = RandomPickInteger[variable]
What do I do wrong?

Any ideas how I can put together this so that player 1 can type "-ar" in chat in game to trigger the event?
 
Level 2
Joined
Mar 8, 2017
Messages
19
I attached the map with those things, it should help you somewhat.

Thank you for your help! It really helped med through the first process of the code.
Unfortunately my noob experience stopped med from progressing as I didn't understand this bit of code and how to implement it in my own game:

Unit Group - Pick every unit in (Random 1 units from (Units in Hero pick <gen> matching ((Point-value of (Unit-type of (Matching unit))) Equal to RandomPickInteger))) and do (Actions)

Do you have any idea?
 
Level 12
Joined
Dec 11, 2014
Messages
665
If your map is like castle fight I think it can be done in a simple way. Just set the builder to be in a unit-type array and use:

Unit - Create 1 UnitTypeArray[(Random integer number between 1 and 12)] for PLAYER at LOCATION facing Default building facing degrees

  • Unit - Create 1 UnitTypeArray[(Random integer number between 1 and 12)] for PLAYER at LOCATION facing Default building facing degrees
the number 12 is if you stored 12 total builders, you can change this.
the PLAYER can of course be changed to Player(Integer A) if it's in the loop.
the location can, like the above, be Player((Integer A))) start location.

I am thinking about this on the top of my head so: it might not be what you want, it might not work, there might be a better way.
 
Level 2
Joined
Mar 8, 2017
Messages
19
If your map is like castle fight I think it can be done in a simple way. Just set the builder to be in a unit-type array and use:

Unit - Create 1 UnitTypeArray[(Random integer number between 1 and 12)] for PLAYER at LOCATION facing Default building facing degrees

  • Unit - Create 1 UnitTypeArray[(Random integer number between 1 and 12)] for PLAYER at LOCATION facing Default building facing degrees
the number 12 is if you stored 12 total builders, you can change this.
the PLAYER can of course be changed to Player(Integer A) if it's in the loop.
the location can, like the above, be Player((Integer A))) start location.

I am thinking about this on the top of my head so: it might not be what you want, it might not work, there might be a better way.



This could work fine!
Do you know how I add my builders to be in a unit-type array?
 
Level 2
Joined
Feb 18, 2016
Messages
14
set UnitTypeVar[X] = your type of unit.

I don't think there is a faster way to get the unit type stored in an array, than doing it manually. Replace X by 1 to 12.
 
Level 2
Joined
Mar 8, 2017
Messages
19
Thank you all for your help! I personally think I've gotten very far in both the code and learning experience by doing the randomize builder code.
I have now put together something that looks like this (see the uploaded file).
The problem with this code is the following:
- it does spawn units, but they aren't random (acolyte wispz acolyte acolyte)
- it does spawn for the right players (player 1-6)

I want the code to give me one builder from my 4 builders
and I want 6 players to each get one of the builders
but I dont want players in their respective teams to have the same builder

Do I also have to put in a code that makes player 1 unable to re-type "-ar" which is the code for the randomization of builders?

Edit: I noticed that I didn't get a unit so I changed the variable 1 to 0 so that everyone would get a builder

Edit2: I also changed the variables for the workers so it was between 0 and 5 instead of 1 and 4, however this didnt change my problem. The random units where still fixed and not random.

Edit3: Found the File (Menu) -> Preferences (Menu option) -> Test Map (Tab) -> Uncheck "Use Fixed Random Seed" (Option) -> Ok (Button). So now I get random units... but.. now sometimes when I type "-ar" I only get 1 or 2 builders instead (which player one doesnt get to control) of the 6 I should be getting... Sometimes it seems as though a player doesn't get a builder at all..
 

Attachments

  • Randomize coding.png
    Randomize coding.png
    14.4 KB · Views: 67
Last edited:
Level 12
Joined
Dec 11, 2014
Messages
665
The red marked stuff should be set at map initialization. The green marked stuff isn't used as far as I can see, it's not needed, if it is used it should be inside the loop, just before the Unit - Create and then referenced instead of "Random int number between 1 and 4". Note that if you test the map form the worldeditor's "test map" button, the result may not be random (from my experience).
And you want 1 type of builder per team? That could maybe be done by checking which builder they got and then removing him from the array... Not sure right now.
And the end of the trigger just disable the trigger itself so typing -ar doesn't create builders again.
 

Attachments

  • Screenshot_1.png
    Screenshot_1.png
    18.2 KB · Views: 71
Last edited:
Level 2
Joined
Feb 18, 2016
Messages
14
Try to place the unit creation line after the arrayy settings. In fact, put your array setting outside the loop. You don't have to set it 6 time.

If you want to make the trigger a one shot, just add Turn off (This trigger) at the end (outside the Loop)
 
Level 2
Joined
Mar 8, 2017
Messages
19
I've done as you both suggested, however I still noticed that it doesn't always spawn 6 builders for the 6 players. Sometimes its 2 or 3 or 4 or 5. Any ideas of how I can fix this problem?
 
Level 2
Joined
Feb 18, 2016
Messages
14
If you do remove the units that the player already have, you destroy the units you create that you have twice. (sorry not sur if it is english)

Explain: If you have added a condition that check if the player have already, let say an acolyt, then, if you spawn an acolyte, you will have it twice. The trigger will remove the previous one, making only, 2, 3 or 5 units.
Same if the condition make your loop do nothing instead of create a unit.
It's just a conjecutre (but maybe?). :)

(hum, after re-reading my post, still not sure if the explaination is english, as well x) )
Edit: Here is a trigger that do what you want, I think. The Unit_Spawn_Int variable, and PlayerNumber_Int are integers. Unit Spawn determine how many time a random type unit will spawn for each players.
upload_2017-3-11_14-18-38.png

Edit 2: You can remove the variable just before the Turn Off thing. It's cleaner.
 
Last edited:
Level 2
Joined
Mar 8, 2017
Messages
19
If you do remove the units that the player already have, you destroy the units you create that you have twice. (sorry not sur if it is english)

Explain: If you have added a condition that check if the player have already, let say an acolyt, then, if you spawn an acolyte, you will have it twice. The trigger will remove the previous one, making only, 2, 3 or 5 units.
Same if the condition make your loop do nothing instead of create a unit.
It's just a conjecutre (but maybe?). :)

(hum, after re-reading my post, still not sure if the explaination is english, as well x) )
Edit: Here is a trigger that do what you want, I think. The Unit_Spawn_Int variable, and PlayerNumber_Int are integers. Unit Spawn determine how many time a random type unit will spawn for each players.

Edit 2: You can remove the variable just before the Turn Off thing. It's cleaner.

So In my trigger I create a condition, and this condition should be a unit comparision - Triggering unit Equal to Triggering Unit. But how do I remove the unit from my array?
 

Attachments

  • Randomize remove from array.png
    Randomize remove from array.png
    15.4 KB · Views: 85
Level 2
Joined
Mar 8, 2017
Messages
19
Here's a map with what you want, one problem is that it doesn't work if the random rolls the biggest possible number, but maybe you'll get an idea how to bypass that :)

Thank you very much for your time and help!
I will be trying to understand the concept of the code in the following days to come.
 
Level 2
Joined
Feb 18, 2016
Messages
14
Your trigger start with a player, so you can't use triggering unit in your condition.

Well, if you got what you want that's nice :) gl
 
Level 2
Joined
Mar 8, 2017
Messages
19
Hello again! I managed to complete the randomization in my game (thanks to you guys :) ).

I now want to add a global gold income based on the numbers of buildings, and these buildings upgrades, a player controls just like in the Castle Fight games.

I managed to find this code on the net:
  • if.gif
    Gold for Every Building
  • events.gif
    Events
    • joinbottom.gif
      timer.gif
      Time - Every (Seconds) of Game-Time
  • cond.gif
    Conditions
  • actions.gif
    Actions
  • if.gif
    For Each Integer (1) to (Number of Players)
    • joinbottomminus.gif
      if.gif
      For Each (Building Type) owned by (Player (Number of Integer A))
      • empty.gif
        joinbottom.gif
        if.gif
        Property - Add 30 to Current Gold of (Player (Integer A))
However, I havn't been able to copy it in my game to try it out. Could someone show me in a map?
And do anyone have an idea of how I could add upgrades to the equation?

Edit: Can you make your own map in the unit creation in the object editor?
 
Last edited:
Level 2
Joined
Feb 18, 2016
Messages
14
To add an upgrade to the gold received equation you have Player - Current Research Level for player function. You need to use an arithmetic function to add more than 1 gold/level (Player - Property Add (Here arithmetic function: X*Player Current research Level of Gold Income Upgrade) To Player (Integer A) current Gold.

I'll make a map to show the trigger to you, I'll edit this message.

Edit : Here is the map, I've created the upgrade and the building so you can try it. If you don't want to wait 60 seconde, just change the time on the event before testing.
I used a custom variable integer because you use a trigger with (Integer A) and (Integer B) already, I think, with your randomization trigger. That way they won't interfeer.

Oh, and I added a string that display the gold of all player after an income, to see if it worked on all player. Remove it if you don't want it (it spam a lot ^^).

For those who don't want to dl the map to see the trigger (Same as the one before):
upload_2017-3-17_15-2-39.png
 

Attachments

  • Gold Income Map.w3x
    18.7 KB · Views: 54
Last edited:
Level 2
Joined
Mar 8, 2017
Messages
19
This code is almost what I want. I would like to be able to increase my income whenever I build a new constructed building (not just one in particular). Do I make an array of all the buildings?
 
Level 2
Joined
Mar 8, 2017
Messages
19
Something like this, but something that is working:
Edit: noticed that I had Time - Elapsed Event instead of the Time - Periodic Event. However this doesn't solve it fully.
 

Attachments

  • Gold inc.png
    Gold inc.png
    13.1 KB · Views: 57
Last edited:
Level 2
Joined
Mar 8, 2017
Messages
19
I added something that looks like this and it seems to be working!
I will continue to try it out :)
Edit: Nope it doesnt, work. I seem only to be getting gold as long as I have buildings equal to the numbers of players in the game.
Edit: Is the problem that my Building_Array is a unit-type?
 

Attachments

  • Gold Inc working.png
    Gold Inc working.png
    16 KB · Views: 58
Last edited:
Level 2
Joined
Feb 18, 2016
Messages
14
I just discovered something that will be useful (thanks to you): the Player - Count Structure.

So, do you want that ALL the buildings owned by the player brings income, or just some of them?

If all:

-Replace the picked unit thing by For each Integer Variable(you have to create a new integer var) from 1 to (Count structures controlled by player(PlayerInteger) exclude incomplete.

It will not check anything (except if the structure is finished), just count, and each time there is +1, It will do the income.

Should look like that:
upload_2017-3-18_12-20-19.png

If not all:

-I suggest you to do a passive ability that every building that bring income will have.
-Then change that:

Pick every Unit owned by player (Integer) Matching condition ((Matching Unit) Is a structure) AND Level of ability (GoldIncomeAbility) for (Matching Unit) greater or equal to 1.

So it will pick a unit and if that picked unit have the ability, It will do the income, then take the next, verify,if yes, do income...

PS: Try to not double or triple post. Just use the edit button :)
 
Level 2
Joined
Mar 8, 2017
Messages
19
This works like a charm! Is it possible to add building upgrades in the equation for the gold income?

ex: Current players gold = 5 + 2 (number of structures a player owns + number of upgrades on a building)

Edit: Another problem is that the formula I use doesn't give a proportional income. Instead it goes from 1 gold (if I have 1 building) to 4 gold (for 2 buildings) to 9 gold (for 3 buildings)
Instead I want one that goes 5 + 2 gold (one building) to 5 + 4 (2 buildings)
5 + 2xB where B = number of Buildings owned by player
 
Last edited:
Level 2
Joined
Feb 18, 2016
Messages
14
For the income problem in your formula, you need to put a gold income beetwin the first loop (for each playerInt) and the second (for each structureInt) that add 5. So for each player, even without building, 5 gold will be given. It's the 5 in 5+ 2xB
Then, under the second loop (for each structureInt) change the gold income to 2. It's the (2xB) part as the loop determine how many time 2 gold will be given.

Then you wanted to add the research level.

So: -if it work for each building, as I did in my previous trigger: Under the Structure Int Loop you change the income from 2 to 2+ (X*Level of research for Player (Integer)) where X is how many gold each upgrade level add for each structure.

upload_2017-3-18_15-21-21.png

-If it work only for the player base income (the 5 gold ), change the income under PlayerInt loop from 5 to 5 + (X*Level if Research for PlayerInt). X is how many gold is added to the base income per upgrade level.
upload_2017-3-18_15-22-29.png
In each case, you have to create a dummy upgrade, which do nothing except getting a level when researched. You can have as much upgrade as you want(well the limit is the one of w3).
 
Last edited:
Level 2
Joined
Mar 8, 2017
Messages
19
The code works well with buildings, but I dont think I understand how I should implement gold income increase for an upgraded building
right now its 5 gold + 2 x number of buildings
I want it to be the same for upgraded building (2 x number of upgrades on all buildings)

Edit: Do you know how to make your own map in the object manager?
 
Last edited:
Level 2
Joined
Feb 18, 2016
Messages
14
If you did exactly what I said before, then it does not do 5+ 2 x number of building. It does 5 + 2(number of building x Level of Income researched).

An upgraded building is actually another unit that replace the previous one when the upgrade is finish. If you want to add for each upgraded building an income upgrade, you have to detect the type of the unit and count the number of that type, store that number in a variable (Number of upgraded building of type T let name that var int_TypeT_UnitCount), add another income increase function after the second loop that add X*int_TypeT_UnitCount.

I suggest you do another trigger to count, using A Unit Finish an upgrade , and conditions to filter and store properly the +1 to the variable.


I don't think I get what you mean by "make your own map in the object manager"?
 
Last edited:
Level 2
Joined
Mar 8, 2017
Messages
19
I will try it out :)

When you want to create a unit in the object manager there is several map (ex: human, orcs, nuetral hostile, neutral, etc). But how do you make your own map?
 
Level 2
Joined
Mar 8, 2017
Messages
19
If you did exactly what I said before, then it does not do 5+ 2 x number of building. It does 5 + 2(number of building x Level of Income researched).

An upgraded building is actually another unit that replace the previous one when the upgrade is finish. If you want to add for each upgraded building an income upgrade, you have to detect the type of the unit and count the number of that type, store that number in a variable (Number of upgraded building of type T let name that var int_TypeT_UnitCount), add another income increase function after the second loop that add X*int_TypeT_UnitCount.

I suggest you do another trigger to count, using A Unit Finish an upgrade , and conditions to filter and store properly the +1 to the variable.


I don't think I get what you mean by "make your own map in the object manager"?



I am a bit uncertain of how exactly I am suppose to write the code. My understanding is that it should be something like this?
 

Attachments

  • Condition.png
    Condition.png
    5.6 KB · Views: 46
  • Trigger.png
    Trigger.png
    20.3 KB · Views: 51
Level 2
Joined
Feb 18, 2016
Messages
14
Two solutions: a customized income depending on the level of the building.Or, if an upgrade always add two gold to the income (It's way easier), just change the int_TypeT_UnitCount so it become a array. It is to separate the upgrades number depending on the player owner.

E: A unit finish an upgrade
C:
-Triggering unit is a structure.
-add here a condition to be sure that the upgrade researched is the one you want.
A:
Here, IF the income added is constant do:

Set int_TypeT_UnitCount[Integer(Index number of (Owner of (triggering unit))] = (int_TypeT_UnitCount[Integer(Index number of (Owner of (triggering unit))] + 1)

OR, If the income added change, you have to create new variables with array for each type of building and store it depending on his type:

If
Unit Type of triggering unit = T
Then
Set int_TypeT_UnitCount[Integer(Index number of (Owner of (triggering unit))] = (int_TypeT_UnitCount[Integer(Index number of (Owner of (triggering unit))] + 1)​
Else
If
Unit Type of triggering unit = U​
Then
Set int_TypeU_UnitCount[Integer(Index number of (Owner of (triggering unit))] = (int_TypeU_UnitCount[Integer(Index number of (Owner of (triggering unit))] + 1)​
Else
If
...​
Add new conditions under ELSE for each type of building . This is the filter I was talking about.


-----------------
In the income trigger:

Replace the integer variable of the loop by a new variable and do from 1 to int_Unit_TypeT_UnitCount[Player_Income].
And do the same for each type of building, (if you want customized Income depending on the level of the upgrade) with new loop, new integer....


PS: T and U and whatever the letter you choose, will be the type of the unit BEFORE the upgrade.
 
Level 2
Joined
Mar 8, 2017
Messages
19
This is what I've understood so far. I want the trigger to affect every building built. How do I need to think in order to complete it? Doesn't the condition already include every building built?
 

Attachments

  • Condition2.png
    Condition2.png
    25.1 KB · Views: 68
  • Trigger2.png
    Trigger2.png
    36.7 KB · Views: 52
Status
Not open for further replies.
Top