Unsorted mapping and scripting stuff
by Orogogus


PlayerIDs and VehicleIDs

Two of the most important object IDs in Starsiege scripting are the playerID and the vehicleID.
Their names should be self-explanatory. The playerID is an object ID for the player himself, and is assigned as soon as he joins the server, sitting in the wait room. the vehicleID isn't assigned until he actually joins the map, and has a vehicle.

There are two functions associated with the playerID. Player::OnAdd(%playerID) is a function that is run whenever a player joins, and Player::OnRemove(%playerID) runs whenever he leaves the server.

Two similar functions exist for the vehicleID. Vehicle::OnAdd(%vehicleID) takes place as soon as a vehicle is added to the map (and applies to AI units, as well). Vehicle::OnDestroyed(%destroyed, %destroyer) takes place whenever a vehicle is destroyed, where %destroyed and %destroyer refer to the vehicleIDs. DMStdLib.cs includes a vehicle::OnDestroyed() function, which can easily be overridden by another copy of the function in the script, so if you want to include death messages on the map, you have to include the following lines in your copy of the function:

  %message = getFancyDeathMessage(getHUDName(%destroyed), getHUDName(%destroyer));
  if(%destroyer == %destroyed) return;
  if(%message != "")
  {
     say( 0, 0, %message);
  }
Other functions for vehicles are vehicle::OnAttacked(%defender, %attacker), vehicle::onScan(%scannee, %scanner, %string), vehicle::OnTargeted, and vehicle::onMessage(%vehicleID, %message, %_1, %_2, %_3, %_4, %_5, %_6, %_7, %_8, %_9).

You can convert between the two IDs with playerManager::playerNumToVehicleID(%playerID) and playerManager::VehicleIDToPlayerNum(%vehicleID). Note, however, that while a player always has a playerID, he doesn't always have a vehicleID. For this reason, you should remember not to run playerManager::PlayerNumToVehicleID() in your player::OnAdd() functions.


Variables and the Dot (.)

A handy tool for working with variables is the dot. You can attach variables to objectIDs, in the form

%objectID.var2;

By doing so, the second variable, %var2, will follow %objectID around wherever it goes. The objectID doesn't have to be an actual, visible object, like a building or a HERC, but can also refer to playerIDs, sim groups, anything that has an objectID number, or even any variable that represents an objectID. Thus, you couldn't set a variable equal to a string and then use the dot operator to attach another variable to it -- a string doesn't have an objectID, after all.

This is useful mostly when dealing with vehicleIDs or playerIDs. You can attach all sorts of variables and values to a vehicle or player ID, allowing you instant access to the variables in any function that uses either ID as an argument. For instance:

function vehicle::OnAdd(%vehicleID)
{
  %vehicleID.name = getHUDName(%vehicleID);
  %vehicleID.vehicleName = getVehicleName(%vehicleID);
}
This small function ensures that as long as you're working in a function that uses a playerID argument, you have instant access to the player's name and the name of the vehicle, without having to write out the function.

Another use of the dot is to assign states to a playerID or vehicleID, or in fact anything with an ID number (including triggers).














1