| Posted by: krit - Saturday, July 12, 2008 8:29:53 AM |
|---|
| [size=7][b][u]WorldBuilder Tutorial - Identifying Players and Related Scripts[/u][/b][/size] [i]By: Krit[/i] [i]Thanks to Fleetatks for discovering some of the information in this tutorial.[/i] [u][b]Contents[/b][/u] 1. Tutorial Introduction 2. Identifying the Players 3. Scripting - Object Transfer upon Action 4. Scripting - Object Transfer upon Game Start 5. Scripting - Spawn Object for Player [u][b]1. Tutorial Introduction[/b][/u] While Fleetatks has already explained how to do this in his 'ZH: Map Scripting FAQ Table', I felt like the section needs expanding including giving it more descriptions, details and examples. Back in April, Fleetatks made a little discovery on how different players are defined in WorldBuilder, making unit and structure transfers for multiple players possible in both multiplayer and skirmish. Despite being much more easier to do such scripts using Fleetatks' discovery, not many people noticed and are still using other, often flawed methods of transferring objects between players. This tutorial is aimed to further detail Fleetatks' little discovery so people can put it to use on their own maps. [u][b]2. Identifying the Players[/b][/u] The basics are simple. All you need to know, if you already have scripting experiences, is that each player in the [i]"Create Game Room"[/i] is given identification in WorldBuilder. For player one, the first player in the room - also the host -, the identification is [i]"player0"[/i] This continues down the room with [i]"player1"[/i] representing the second player in the room, [i]"player2"[/i] representing the third player and so on. The general formula is [b]"Player [i](X)[/i] in Create Game Room = player[i](X-1)[/i] in WorldBuilder"[/b] If you are unsure on the player numbers, it's the same numbers used to show the start locations on the map preview. The identifications are not available on the drop down menu in WorldBuilder and will have to be typed in manually by the user. Once typed in, WorldBuilder will show a question mark on the script icon and exclaim that the "player#" (Where # is the player number minus 1) does not exist. Ignore this exclamation and continue as the game will still register the script as valid. Scripting with such identifications are a long and tedious task as each script would need to be recreated 7 times for each player. While people can get away with implementing scripts only to the amount of players on the map (Example, making scripts for "player0" and "player1" only for a two player map), such shortcut is not advised as there can be cases where players in the Create Game Room are not in their correct orders (Example, a player is in slot 7 on a three player map). Please note from this point onwards, all the following scripts, unless specifically point out, are placed in the [b]PlyrCivilian[/b] folder. [u][b]3. Scripting - Object Transfer upon Action[/b][/u] Objects placed in WorldBuilder on the map, such as units or structures, can be scripted to be transferred to certain players on completion of certain actions. For example, a set of tanks can be turned over to a player if the player has captured War factory in the middle of the map. To do so, the objects that are going to be transferred along with the objects that are associated with the condition must be each given a name. This is done by typing in the name in the [b]Object Properties[/b] window. [b]Worked Example:[/b] Script: AirfieldTransferPlyr0 *** IF *** Unit 'Airfield01' is owned by Player 'player0' *** THEN *** Unit 'Comanche01' is transferred to the command of Player 'player0' Unit 'Comanche02' is transferred to the command of Player 'player0' Unit 'Comanche03' is transferred to the command of Player 'player0' Unit 'Comanche04' is transferred to the command of Player 'player0' Disable Script 'AirfieldTransferPlyr1'. Disable Script 'AirfieldTransferPlyr2'. Disable Script 'AirfieldTransferPlyr3'. Disable Script 'AirfieldTransferPlyr4'. Disable Script 'AirfieldTransferPlyr5'. Disable Script 'AirfieldTransferPlyr6'. Disable Script 'AirfieldTransferPlyr7'. Using this script, if Player 1 captures the airfield on the map called "Airfield01", the Comanche helicopters "Comanche01", "Comanche02", "Comanche03" and "Comanche04" are immediately transferred to Player 1's ownership. At the same time, scripts "AirfieldTransferPlyr1-7", representing the same scripts for Player 2 to 7, is disabled so if any other player captures the airfield later, ownership of the Comanches will not be transferred with them. Not all scripts transferring units upon certain action has to follow this format. If the player wishes to transfer the ownership of the units if the structure is captured again by another player, the additional conditions for disabling the other scripts can be changed to enabling the other scripts (This allows for the same player to capture the structure twice and regain ownership of the units as scripts are disabled once used). The condition can also be changed to the user's wishes so it isn't always capturing buildings to transfer units or other structures. Using the Airfield example above; if you want the Comanche to be transferred once the player enters a specific area called "AreaAirbase", simply change the Script Conditions to: *** IF *** Player 'player0' has units in area 'AreaAirbase'. Areas on the map are defined using the Polygon Tool And if you want the Comanches to transfer once the player garrisons a civilian building named "ControlTower": *** IF *** Player 'player0' has entered building named Unit 'ControlTower' The condition script for object ownership is located at: [i]Player > Owns > Player owns a specific Unit.[/i] Condition script for unit in area is at: [i]Player > Area > Player has units in an area.[/i] And the condition script for entering buildings: [i]Player > Player has entered a specific building.[/i] The action script for unit transfer is at: [i]Player > Transfer > Transfer a specific unit to the control of a player.[/i] Script disabling is: [i]Scripting > Script > Disable script.[/i] Enabling a script is: [i]Scripting > Script > Enable script.[/i] [u][b]4. Scripting - Object Transfer upon Game Start[/b][/u] While scripting for pre-placed objects to be transferred at game start is mainly the same as transferring objects upon action, there are a few important things to take note on and will be explained in this section. [b]Worked Example:[/b] Script: ComancheTransPlyr0Start1 *** IF *** Player 'player0' starting position is 1 . *** THEN *** Unit 'Start1Comanche01' is transferred to the command of Player 'player0' Unit 'Start1Comanche02' is transferred to the command of Player 'player0' With this script, when Player 1 starts at Starting Position 1, the Comanches “Start1Comanche01” and “Start1Comanche02” is transferred to the player. As you may have noticed, this script would only work with Player 1 and only if Player 1 is on Starting Position 1. To making the map operational with all players, this script will have to be recreated another 7 times with different players in place of “player0” and more sets of such scripts created for each starting position placed on the map. Obviously in this case, the less starting positions on the map, the less scripts are required. As stated in section 2; [i]Identifying the Players[/i], a shortcut of only scripting players in accordance to how many players are actually on the map at once can be used, but this is not advised for a fully functioning map. The script for allocating players with starting positions is: [i]Skirmish > Start Position.[/i] [u][b]5. Scripting - Spawn Object for Player[/b][/u] Spawning object requires two actions to be made in one script. This is because - currently - there are no known methods to directly spawn objects for a player that works for all players regardless of AI or Human players. Like the transfer scripts, different conditions can be set to trigger the spawn. [b]Worked Example:[/b] Script: ChinaSpwnPlyr0Start1 *** IF *** Player 'player0' starting position is 1 . *AND* Player 'player0' is Faction Name: China *** THEN *** Spawn Unit 'Overlord01' of type 'ChinaTankOverlord' on Team 'teamPlyrCivilian' at waypoint Waypoint 'Spawn01' Unit 'Overlord01' is transferred to the command of Player 'player0' In this script, if the first player starts in Starting Position 1 and is using China, an Overlord tank will be transferred to the player at the waypoint "Spawn01". As you may notice, the Overlord tank is actually spawned as a civilian unit and then transferred to the command of Player 1. Some minor tests have already been made to spawn units directly to the control of players with limited success; while spawning for the first player succeeded, spawning for skirmish players in other slots failed with serious errors. Waypoints are not always needed for spawning objects as another spawning script allows for the placement of objects on map coordinates and may sometimes be preferred over the script using the waypoint as it allows specifying the angle in which the unit is facing when spawned. This script is located at: [i]Unit > Spawn > Spawn -- named unit on a team at a position with an orientation.[/i] The position is the coordinates on the map. Specific coordinates can be found on the map by placing the cursor over where you want the coordinates and looking at the lower left status bar. The coordinate of the current position of the cursor comes after the object and waypoint count. For orientation, just place a unit down, rotate it to where you need and copy down the angle from the Object Properties window. If you learn math, then everything is rather obvious. The conditions to trigger the scripts can be changed at will. In this example, the script would only work if Player 1 starts at Starting Position 1 and is playing China. By also including faction conditions, players can spawn specific units if players are playing as specific factions. Units can also be scripted to spawn after a time delay later in game by using two scripts. [b]Worked Example:[/b] Script: SpawnTimer *** IF *** True. *** THEN *** Set timer 'UnitSpawn' to expire in 60.00 seconds. Script: OverlordSpawnPosition1 *** IF *** Timer 'UnitSpawn' has expired. *AND* Player 'player0' starting position is 1 . *** THEN *** Spawn Unit 'Overlord01' of type 'ChinaTankOverlord' on Team 'teamPlyrCivilian' at waypoint Waypoint 'Spawn01' Unit 'Overlord01' is transferred to the command of Player 'player0' In this example, the first script starts a 60 second timer. The second script is only enabled if the timer in the first script has expired. By doing so, the spawn script is given a delay and thus will not spawn the designated object until the timer in the timer script has expired. Multiple spawn scripts can use the same timer and thus only one timer script is required if all the spawning times are the same. Also note that like the Object Transfer upon Game Start scripts, all combinations between player slots and Starting Positions requires a copy of the script for the map to function correctly for all players. The faction defining condition is located under: [i]Skirmish > Player > Player is faction.[/i] The waypoint spawning script is at: [i]Unit > Spawn > Spawn -- named unit on a team at a waypoint[/i] Timer start is located at: [i]Scripting > Timer > Seconds countdown timer -- set.[/i] Timer expires is at: [i]Scripting > Timer expired.[/i] It is also good to note that the timers can also be used with the transfer scripts so that objects can be transferred between players after a set amount of time. [EDIT: Moved to Tutorials forum -- CommieDog] |
| Posted by: Drummin - Saturday, July 12, 2008 9:12:33 AM |
|---|
| Hi Krit, Nice tutorial! Yes Fleetatks did a good job discovering or pointing out the "player0" idea. But isn't that referring to just a multi-player (Human) map? |
| Posted by: krit - Saturday, July 12, 2008 9:22:09 AM |
|---|
| According to Fleetatks himself, it does work with AI players as well since they still take up a player slot. |
| Posted by: Drummin - Saturday, July 12, 2008 9:30:22 AM |
|---|
| I believe he also said that if there were more than TWO AI player's of the same faction, it would crash. I would use, the "Player0" for start position1 in a "Multi-Human" map and "Player1" for start position1 in a Skirmish map. Just my take on it.[smile] |
| Posted by: krit - Saturday, July 12, 2008 9:34:00 AM |
|---|
| Actually, he said that for the other method, not this one, that defines players using the Skirmish Faction Scripts and thus the reason why it crashes when there's two AI using the same faction. |
| Posted by: Drummin - Saturday, July 12, 2008 12:53:14 PM |
|---|
|
Hello Krit,
Please bear with with me as I'm trying to figure out the advantage of using this method of transfer.
Wouldn't it be simpler to use one script that says the following and then deactivates?
*** IF ***
Unit 'Airfield01' is owned by Player ' |
| Posted by: krit - Saturday, July 12, 2008 6:00:20 PM |
|---|
|
Actually, no, by comparison, to make a fully functioning map (A map that works with all factions and all AIs), you actually need more work using the older " |
| Posted by: Drummin - Sunday, July 13, 2008 9:36:38 AM |
|---|
| Well Krit, I never really understood the concept or the implications of using this method. I had tried using "player0" in scripts before and it never seemed to work. It was because I didn't understand that "it" was referring to both rooms as well as start positions. I also was trying to use them in AI folders rather than the plrycivilian folder. It's too bad we still can't give player's Base Buildings without them being sold, unless you've found another trick for that. So, the bottom line folks is that learning this method will save you a lot of scripting time. You'll be able to transfer "Units" and Civilian buildings to any player on your map without needing to load AI scripts into your map. A huge time saver. Thanks to you and Fleetatks for bring these methods to light. Let us know if you figure out how to spawn buildings and transfer them to an AI player. |
| Posted by: krit - Monday, July 14, 2008 7:55:59 AM |
|---|
| I only delayed that section because I haven't tested it and don't have access to WB for a week. I'll get tp work on it once I get back. |
| Posted by: fleetatks - Tuesday, July 15, 2008 6:42:08 PM |
|---|
| I can already tell you from experience that the only way to Spawn a Team/Unit for a player is to spawn it as a named unit on team Plyrcivilian and then (in the same script if you wish) transferring it to the player. By memmory, it should look something like this: IF "This Happens" THEN Spawn unit "Unit_Tank01" of type "AmericanVehicleCrusador" at waypoint "Spawn." Transfer control of unit "Unit_Tank01" to player "Player0." Drummin was the one who helped me on that one :) |
| Posted by: Phe0n1x - Tuesday, July 15, 2008 8:12:00 PM |
|---|
| could you spawn it for Plyrcivilian at the beginning and transfer it to player0. and eventually transfer it for the player later on? |
| Posted by: Drummin - Tuesday, July 15, 2008 8:20:27 PM |
|---|
| Yes Fleetatks, spawn to teamPlyrCivilian then make the transfer. Too bad we can only give units to AI players. So though you can give units to any player whether spawned or placed, AI buildings are still out... At least from the civilian folder. But if that's what you want to do, this new method of transferring to "player0" etc is the way to go. And Yes Phe0n1x, the units can be spawned at any time and transferred at anytime. It doesn't need to be in the same script or happen at the same time. And I don't know why you would want to, but you could give the units to "player0" then give them to another player if a condition is met. It's because they're named units. |
| Posted by: krit - Tuesday, July 15, 2008 10:32:49 PM |
|---|
| I'll look into it once I get home. Weather or not I might find an easier way or an alternate method will be reported in the completed tutorial with working examples. EDIT: Okay, played around with the scripts and discovered something new. By manually typing in "teamplayer0" in the team section works in transfering directly to the first player; the host. However, as far as my tests have went, "teamplayer1" and so on failed to work on Skirmish, causing a serious error at game start. Multiplayer with human players is untested. Given that this particular discorvery does not work on Skirmish and only might or might not work on Multiplayer, I'd say it's better to use Fleetatk's stated scripts as it has been proved to work on both Skirmish and Multiplayer. However, given that we know "teamplayer#" does partially work, it might be interesting to experiment around with it a bit more. Fleetatks, care to look into this? |
| Posted by: Drummin - Saturday, July 19, 2008 10:24:38 PM |
|---|
|
Hey Krit,
It would be great to spawn directly to any player from the Civilian folder, however, I believe the only reason it worked for teamplayer0 is because that slot is always reserved for a human player. As |
| Posted by: krit - Sunday, July 20, 2008 12:56:17 AM |
|---|
| Still worth a little more experimenting though. Oh, and the tutorial is complete. |
| Posted by: Drummin - Sunday, July 20, 2008 9:32:31 AM |
|---|
| Again, great job Krit, I know you covered this in the second section but just so it's clear to everyone, I think you should remind them that they should script for all eight rooms. So if you're using check start position in your condition, you would make eight scripts for each start position. For example, your script names might look like this... Player0Position1 Player1Position1 Player2Position1 Player3Position1 Player4Position1 Player5Position1 Player6Position1 Player7Position1 Player0Position2 Player1Position2 Player2Position2 Player3Position2 Player4Position2 Player5Position2 Player6Position2 Player7Position2 And again, though you mentioned it in section two, all this scripting goes in the PlryCivilian folder. Nice Job Krit!!! |
| Posted by: Me Myself and Pi - Wednesday, July 30, 2008 8:00:08 AM |
|---|
| This is absolutely incredible! I haven't been coming to the forums lately so I haven't seen this until now. When I first saw Fleetatks bring this up, I couldn't get it to work, but now I can! This could open up a lot of possibilities for AOD maps! |
| Posted by: Drummin - Thursday, August 7, 2008 12:23:51 PM |
|---|
| Being able to script for all player's has really been great. Just be sure of what you're getting into. I'm working on a six-player Skirmish/Muli-Player map and wanted to give each player unique units depending on their faction and start location. I've placed each set of scripts in a seperate folder. So far when testing there has been almost no game lag with this new scripting. However, scripting is starting to really bog-down World builder because of the bulk. There's six start positions, twelve factions and eight rooms. This works out to 576 folders (6x12x8) containing at least three scripts each in the PlyrCivilian folder not counting other supporting scripts. It's cool scripting this way but it takes time. |
| Posted by: Sky Demon - Monday, September 8, 2008 5:31:15 AM |
|---|
| This is quite a remarkable discovery for the map making community. Now knowing that you can script for each individual player, AI and human alike is quite somethng. Well done Fleetatks for discovering this and for Krit posting up this indepth tutorial. I know it's bad to post my problems on a Tutorial thread, but I feel it's related. 1) In any case, I found that adding in a script that relates to the AI directly stopped them carrying out there usual Skirmish scripting. For example. If I were to add in a script that said something along the lines of: **IF** Player 'SkirmishChina' has one or more units in area 'BridgeCrossing' **THEN** Spawn team 'ChinaTankDropReinforcements' at waypoint 'DropOff' They wouldn't behave normally and build like they should. Sometimes they wouldn't even do anything, just sit there with the dozer and Command Center. I did of course add in all of the requirements for the AI to work. Such as 'Add Skirmish players' and all of the required waypoints & areas. I just find it strange that it messes the normal scripts up when all it does is call in a chinese plane to drop of some china tanks... |
| Posted by: Drummin - Monday, September 8, 2008 11:33:01 AM |
|---|
| If you add any scripting to AI player folders WITHOUT importing the default AI scripts as well, then the default scripts won't load into the game and AI won't build. Your options are to script as Krit explained using player0 - player7 and placing these scripts in the civilian folder, OR, import the default scripts and write scripts as you posted in each AI faction folder. |
| Posted by: Sky Demon - Tuesday, September 9, 2008 12:17:30 PM |
|---|
| Okay, thanks. |
| Posted by: assassin4359 - Sunday, May 30, 2010 7:49:26 AM |
|---|
| uuummmm can i have this simple i want to have a unit enter a building then he gains controll of a turret how plz as simple as posable as in a step by step plz thx u |
| Posted by: Drummin - Sunday, May 30, 2010 7:56:56 PM |
|---|
| The first worked example in section 3 will work for what you're doing for human players. |
| Posted by: krit - Sunday, May 30, 2010 8:26:17 PM |
|---|
| It would also work for AI players provided you have the building named as one of the designated garrison buildings for the AI to send troops into. |
| Posted by: Drummin - Sunday, May 30, 2010 10:03:31 PM |
|---|
| Yes the transfer would be made but AI players sell any buildings transferred over to them and he's talking about turrets. |
| Posted by: i^love^mixery - Tuesday, August 2, 2011 5:35:11 AM |
|---|
| [quote=Drummin]Being able to script for all player's has really been great. Just be sure of what you're getting into. I'm working on a six-player Skirmish/Muli-Player map and wanted to give each player unique units depending on their faction and start location. I've placed each set of scripts in a seperate folder. So far when testing there has been almost no game lag with this new scripting. However, scripting is starting to really bog-down World builder because of the bulk. There's six start positions, twelve factions and eight rooms. This works out to 576 folders (6x12x8) containing at least three scripts each in the PlyrCivilian folder not counting other supporting scripts. It's cool scripting this way but it takes time.[/quote] even though this topic is old i feel like pointing this out: you do not need 6x12x8 script folders for this and its pretty funny that you wasted your time like that. just think logically: 1. you check: what faction is in area InnerPerimeter1? you need this 12 times (for each faction) 2. you check: which player is it? you need this 8 times (for each lobby player) so you need only 20 scripts per start position, 160 scripts for a map with 8 start position and not like 1.500 lol. seriously.. |
| Posted by: Drummin - Tuesday, August 2, 2011 6:25:10 AM |
|---|
| You've pointed this out to me several times already. |
| Posted by: i^love^mixery - Wednesday, August 3, 2011 6:49:31 AM |
|---|
| [quote=Drummin]You've pointed this out to me several times already.[/quote] 1. this is the first time i wrote it in a public topic 2. i only fixed your post since you talked crap in a tutorial topic and i'd like to prevent more time wasting |
| Posted by: Drummin - Wednesday, August 3, 2011 9:03:28 AM |
|---|
|
You have to realize this was a whole new way of scripting at the time it was introduced and the first time we could script for players other than |
| Posted by: Phe0n1x - Wednesday, August 3, 2011 9:17:34 AM |
|---|
| [color=darkred]There's no need to be rude in this thread. If you have a problem with a tutorial bring it up in an educated fashion. Posting "lolumad" is not an appropriate response. I do hope you take this advice into account. The community needs positive reinforcement rather than trolling and negative reinforcement as you have just done. If you continue to post in this manner I will take administrative action rather than moderation action as I have just done. Have a good day, Phe0n1x[/color] |
| Posted by: i^love^mixery - Thursday, August 4, 2011 10:51:53 AM |
|---|
|
[quote=Drummin]You have to realize this was a whole new way of scripting at the time it was introduced and the first time we could script for players other than |
| Posted by: Drummin - Thursday, August 4, 2011 11:04:00 AM |
|---|
| Hey you should have seen that map when I also scripted snipers and rocket launchers in the hills for each player. That added even more scripts. |
| Posted by: i^love^mixery - Thursday, August 4, 2011 11:57:21 AM |
|---|
| [quote=Drummin]Hey you should have seen that map when I also scripted snipers and rocket launchers in the hills for each player. That added even more scripts. [/quote] yea nice.. you know what i find funny? you probably created this map so you can play it online without problems but now i have another problem: my internet wont upload it to the other players in time because its by far too big! well done [grin] |
| Posted by: Drummin - Thursday, August 4, 2011 12:17:15 PM |
|---|
| I never "played online". |
| Posted by: i^love^mixery - Friday, August 5, 2011 4:37:46 AM |
|---|
| are you kidding me? |