Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

2 Pages12>
Options
Go to last post Go to first unread
Offline krit  
#1 Posted : Saturday, July 12, 2008 7:29:53 AM(UTC)
krit
Commander in Chief
Joined: 4/15/2004(UTC)
Posts: 2,200
Location: Gensokyo

Was thanked: 11 time(s) in 10 post(s)
WorldBuilder Tutorial - Identifying Players and Related Scripts
By: Krit
Thanks to Fleetatks for discovering some of the information in this tutorial.

Contents
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

1. Tutorial Introduction
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.

2. Identifying the Players
The basics are simple. All you need to know, if you already have scripting experiences, is that each player in the "Create Game Room" is given identification in WorldBuilder. For player one, the first player in the room - also the host -, the identification is "player0" This continues down the room with "player1" representing the second player in the room, "player2" representing the third player and so on. The general formula is "Player (X) in Create Game Room = player(X-1) in WorldBuilder" 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 PlyrCivilian folder.

3. Scripting - Object Transfer upon Action
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 Object Properties window.

Worked Example:
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:
Player > Owns > Player owns a specific Unit.
Condition script for unit in area is at:
Player > Area > Player has units in an area.
And the condition script for entering buildings:
Player > Player has entered a specific building.

The action script for unit transfer is at:
Player > Transfer > Transfer a specific unit to the control of a player.
Script disabling is:
Scripting > Script > Disable script.
Enabling a script is:
Scripting > Script > Enable script.

4. Scripting - Object Transfer upon Game Start
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.

Worked Example:
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; Identifying the Players, 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:
Skirmish > Start Position.

5. Scripting - Spawn Object for Player
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.

Worked Example:
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:
Unit > Spawn > Spawn -- named unit on a team at a position with an orientation.
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.

Worked Example:
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:
Skirmish > Player > Player is faction.
The waypoint spawning script is at:
Unit > Spawn > Spawn -- named unit on a team at a waypoint
Timer start is located at:
Scripting > Timer > Seconds countdown timer -- set.
Timer expires is at:
Scripting > Timer expired.

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]

Edited by moderator Monday, July 28, 2008 1:13:59 PM(UTC)  | Reason: Not specified

UserPostedImage
thanks 1 user thanked krit for this useful post.
KAJLogic on 12/9/2012(UTC)
Sponsor
Offline Drummin  
#2 Posted : Saturday, July 12, 2008 8:12:33 AM(UTC)
Drummin
General
C&C Labs Staff: Labs Staff MemberThe Forgotten Staff: The Forgotten StaffMaps Staff: Maps Staff MemberRed Alert Staff: Red Alert Staff Member
Joined: 12/11/2007(UTC)
Posts: 1,622
Location: CA, USA

Was thanked: 16 time(s) in 15 post(s)
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?
Offline krit  
#3 Posted : Saturday, July 12, 2008 8:22:09 AM(UTC)
krit
Commander in Chief
Joined: 4/15/2004(UTC)
Posts: 2,200
Location: Gensokyo

Was thanked: 11 time(s) in 10 post(s)
According to Fleetatks himself, it does work with AI players as well since they still take up a player slot.
UserPostedImage
Offline Drummin  
#4 Posted : Saturday, July 12, 2008 8:30:22 AM(UTC)
Drummin
General
C&C Labs Staff: Labs Staff MemberThe Forgotten Staff: The Forgotten StaffMaps Staff: Maps Staff MemberRed Alert Staff: Red Alert Staff Member
Joined: 12/11/2007(UTC)
Posts: 1,622
Location: CA, USA

Was thanked: 16 time(s) in 15 post(s)
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
Offline krit  
#5 Posted : Saturday, July 12, 2008 8:34:00 AM(UTC)
krit
Commander in Chief
Joined: 4/15/2004(UTC)
Posts: 2,200
Location: Gensokyo

Was thanked: 11 time(s) in 10 post(s)
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.
UserPostedImage
Offline Drummin  
#6 Posted : Saturday, July 12, 2008 11:53:14 AM(UTC)
Drummin
General
C&C Labs Staff: Labs Staff MemberThe Forgotten Staff: The Forgotten StaffMaps Staff: Maps Staff MemberRed Alert Staff: Red Alert Staff Member
Joined: 12/11/2007(UTC)
Posts: 1,622
Location: CA, USA

Was thanked: 16 time(s) in 15 post(s)
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 '<This Player>'
*** THEN ***
Unit 'Comanche01' is transferred to the command of Player '<This Player>'

With the method you discribed, you'd need to make eight versions for each player position. Isn't that correct?

I believe the real advantage is for scripting a multi-player map. Before the "Player0" idea was discovered, there wasn't a way to script for other Human players. I think for a personal skirmish map, using "<This Player>" would save time in coping and editing scripts to perform a simple function.

Edited by user Saturday, July 12, 2008 1:05:29 PM(UTC)  | Reason: Not specified

Offline krit  
#7 Posted : Saturday, July 12, 2008 5:00:20 PM(UTC)
krit
Commander in Chief
Joined: 4/15/2004(UTC)
Posts: 2,200
Location: Gensokyo

Was thanked: 11 time(s) in 10 post(s)
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 "<This Player>" method. This is because you have 12 factions in comparison to only 8 players. For a transfer upon action script, you only need one script per player, thus the "<This Player>" requires up to 5 more scripts (Including the scripts for the actual player) than the "player3" method. For the transfer upon game start scripts, while the "player#" method requires up to 8 script per starting location, the "<This Player>" requires up to 13 per starting location (One script for each start location for each AI and the player).

Other advantages of using the "player#" method are as follows:
> Game will not crash when more than one skirmish enemy is using the same faction.
> No need to import the Skirmish Scripts.
> Most scripts can be copied and modified instead of starting new for each AI folder.
UserPostedImage
Offline Drummin  
#8 Posted : Sunday, July 13, 2008 8:36:38 AM(UTC)
Drummin
General
C&C Labs Staff: Labs Staff MemberThe Forgotten Staff: The Forgotten StaffMaps Staff: Maps Staff MemberRed Alert Staff: Red Alert Staff Member
Joined: 12/11/2007(UTC)
Posts: 1,622
Location: CA, USA

Was thanked: 16 time(s) in 15 post(s)
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.
Offline krit  
#9 Posted : Monday, July 14, 2008 6:55:59 AM(UTC)
krit
Commander in Chief
Joined: 4/15/2004(UTC)
Posts: 2,200
Location: Gensokyo

Was thanked: 11 time(s) in 10 post(s)
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.
UserPostedImage
Offline fleetatks  
#10 Posted : Tuesday, July 15, 2008 5:42:08 PM(UTC)
fleetatks
Colonel
Joined: 6/2/2006(UTC)
Posts: 961
Location: USA

Was thanked: 3 time(s) in 2 post(s)
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 :)
Email me if you ever need help (edited signature November 6th, 2014)
Offline Phe0n1x  
#11 Posted : Tuesday, July 15, 2008 7:12:00 PM(UTC)
Phe0n1x
Administrator
C&C Labs Staff: Labs Staff MemberThe Forgotten Staff: The Forgotten StaffMaps Staff: Maps Staff Member
Joined: 1/26/2006(UTC)
Posts: 1,001
Location: Houston, TX

Was thanked: 6 time(s) in 6 post(s)
could you spawn it for Plyrcivilian at the beginning and transfer it to player0. and eventually transfer it for the player later on?
UserPostedImage
Offline Drummin  
#12 Posted : Tuesday, July 15, 2008 7:20:27 PM(UTC)
Drummin
General
C&C Labs Staff: Labs Staff MemberThe Forgotten Staff: The Forgotten StaffMaps Staff: Maps Staff MemberRed Alert Staff: Red Alert Staff Member
Joined: 12/11/2007(UTC)
Posts: 1,622
Location: CA, USA

Was thanked: 16 time(s) in 15 post(s)
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.

Edited by user Sunday, July 20, 2008 10:37:19 AM(UTC)  | Reason: Not specified

Offline krit  
#13 Posted : Tuesday, July 15, 2008 9:32:49 PM(UTC)
krit
Commander in Chief
Joined: 4/15/2004(UTC)
Posts: 2,200
Location: Gensokyo

Was thanked: 11 time(s) in 10 post(s)
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?

Edited by user Saturday, July 19, 2008 7:18:26 PM(UTC)  | Reason: Not specified

UserPostedImage
Offline Drummin  
#14 Posted : Saturday, July 19, 2008 9:24:38 PM(UTC)
Drummin
General
C&C Labs Staff: Labs Staff MemberThe Forgotten Staff: The Forgotten StaffMaps Staff: Maps Staff MemberRed Alert Staff: Red Alert Staff Member
Joined: 12/11/2007(UTC)
Posts: 1,622
Location: CA, USA

Was thanked: 16 time(s) in 15 post(s)
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 <ThisTeam> doesn't even work for spawning in AI folders I doubt we can spawn to a generic team in the civilian folder that would automatically go to a player.
Offline krit  
#15 Posted : Saturday, July 19, 2008 11:56:17 PM(UTC)
krit
Commander in Chief
Joined: 4/15/2004(UTC)
Posts: 2,200
Location: Gensokyo

Was thanked: 11 time(s) in 10 post(s)
Still worth a little more experimenting though.

Oh, and the tutorial is complete.
UserPostedImage
Offline Drummin  
#16 Posted : Sunday, July 20, 2008 8:32:31 AM(UTC)
Drummin
General
C&C Labs Staff: Labs Staff MemberThe Forgotten Staff: The Forgotten StaffMaps Staff: Maps Staff MemberRed Alert Staff: Red Alert Staff Member
Joined: 12/11/2007(UTC)
Posts: 1,622
Location: CA, USA

Was thanked: 16 time(s) in 15 post(s)
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!!!
Offline Me Myself and Pi  
#17 Posted : Wednesday, July 30, 2008 7:00:08 AM(UTC)
Me Myself and Pi
Colonel
Joined: 8/22/2007(UTC)
Posts: 867

Was thanked: 12 time(s) in 5 post(s)
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!
Offline Drummin  
#18 Posted : Thursday, August 7, 2008 11:23:51 AM(UTC)
Drummin
General
C&C Labs Staff: Labs Staff MemberThe Forgotten Staff: The Forgotten StaffMaps Staff: Maps Staff MemberRed Alert Staff: Red Alert Staff Member
Joined: 12/11/2007(UTC)
Posts: 1,622
Location: CA, USA

Was thanked: 16 time(s) in 15 post(s)
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.
Sky Demon  
#19 Posted : Monday, September 8, 2008 4:31:15 AM(UTC)
Guest
Guest
Joined: 7/31/2008(UTC)
Posts: 563

Was thanked: 1 time(s) in 1 post(s)
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...
Offline Drummin  
#20 Posted : Monday, September 8, 2008 10:33:01 AM(UTC)
Drummin
General
C&C Labs Staff: Labs Staff MemberThe Forgotten Staff: The Forgotten StaffMaps Staff: Maps Staff MemberRed Alert Staff: Red Alert Staff Member
Joined: 12/11/2007(UTC)
Posts: 1,622
Location: CA, USA

Was thanked: 16 time(s) in 15 post(s)
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.
Users browsing this topic
Guest
2 Pages12>
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.