Code: Select all
***PlayLoop***
***
/* ------------------------------------- */
// Spawn players
if (G_PlayerSpawnQueue.count > 0 && LastSpawnTime + (S_SpawnInterval * 1000) < Now) {
UpdateBlockSpawnQueue();
SpawnPlayers();
LastSpawnTime = Now;
UIManager.UIAll.BigMessageSound = CUIConfig::EUISound::StartRound;
UIManager.UIAll.BigMessage = _("Spawning players...");
LastMessageTime = -1;
UIManager.UIAll.CountdownEndTime = LastSpawnTime + (S_SpawnInterval * 1000);
LayerUpdated = Layers::Update("SpawnQueue", UpdateLayerSpawnQueue());
}
// ---------------------------------- //
/** Spawn items
* This function must be called at each frame inside the play loop
*/
Void SpawnItems() {
// Loop on all the items the mapper put on the map
foreach (ItemAnchor in ItemAnchors) {
// Check if an item is already spawn on this anchor
declare ItemSpawned for ItemAnchor = False;
if (ItemSpawned) continue;
// Check if the respawn timer has been reach
declare ItemNextSpawn for ItemAnchor = Now;
if (ItemNextSpawn > Now) continue;
// Create an empty item
declare CSmItem Item;
// Depending on the item anchor tag, assign the right item
switch (ItemAnchor.Tag) {
case "Armor" : Item = CreateItem(ArmorId);
case "Rocket" : Item = CreateItem(RocketId);
case "Laser" : Item = CreateItem(LaserId);
case "Nucleus" : Item = CreateItem(NucleusId);
case "Arrow" : Item = CreateItem(ArrowId);
}
// If the item was correctly created
if (Item != Null) {
// Save from which anchor the item was spawned
declare AnchorId for Item = NullId;
AnchorId = ItemAnchor.Id;
// Save the tag of the anchor in the item
declare Tag for Item = ItemAnchor.Tag;
Tag = ItemAnchor.Tag;
// Spawn the item on the anchor
AttachItemToAnchor(Item, ItemAnchor);
ItemSpawned = True;
}
}
}
// ---------------------------------- //
//second part
/** Pick up item
*
* @param _Player The player who picked up the item
* @param _Item The item picked up by the player
*/
Void PickUpItem(CSmPlayer _Player, CSmItem _Item) {
if (_Player == Null || _Item == Null) return;
// Get the tag and the anchor of the item
declare Tag for _Item = "";
declare AnchorId for _Item = NullId;
// Check that the anchor associated with the item really exists
if (!ItemAnchors.existskey(AnchorId)) return;
declare ItemAnchor <=> ItemAnchors[AnchorId];
// We picked up the item, so it's not spawned on the anchor anymore
declare ItemSpawned for ItemAnchor = False;
ItemSpawned = False;
// Update the time of the next item respawn on this anchor
declare ItemNextSpawn for ItemAnchor = Now;
ItemNextSpawn = Now + 45000; ///< Respawn in 45 seconds
// Check the tag associated to the item and do something accordingly
switch (Tag) {
// If it's an armor, reload one armor point
case "Armor": {
_Player.Armor += 100;
}
// If it's a weapon, then switch to this weapon
case "Rocket": {
SetPlayerWeapon(_Player, CSmMode::EWeapon::Rocket, False);
}
case "Laser": {
SetPlayerWeapon(_Player, CSmMode::EWeapon::Laser, False);
}
case "Nucleus": {
SetPlayerWeapon(_Player, CSmMode::EWeapon::Nucleus, False);
}
case "Arrow": {
SetPlayerWeapon(_Player, CSmMode::EWeapon::Arrow, False);
}
}
// Attach the item to the player to display the blue flashing screen feedback
AttachItemToPlayer(_Item, _Player);
// Destroy the item after that
DestroyItem(_Item);
}
Code: Select all
//second part
/** Pick up item
*
* @param _Player The player who picked up the item
* @param _Item The item picked up by the player
*/
Void PickUpItem(CSmPlayer _Player, CSmItem _Item) {
if (_Player == Null || _Item == Null) return;
// Get the tag and the anchor of the item
declare Tag for _Item = "";
declare AnchorId for _Item = NullId;
// Check that the anchor associated with the item really exists
if (!ItemAnchors.existskey(AnchorId)) return;
declare ItemAnchor <=> ItemAnchors[AnchorId];
// We picked up the item, so it's not spawned on the anchor anymore
declare ItemSpawned for ItemAnchor = False;
ItemSpawned = False;
// Update the time of the next item respawn on this anchor
declare ItemNextSpawn for ItemAnchor = Now;
ItemNextSpawn = Now + 45000; ///< Respawn in 45 seconds
// Check the tag associated to the item and do something accordingly
switch (Tag) {
// If it's an armor, reload one armor point
case "Armor": {
_Player.Armor += 100;
}
// If it's a weapon, then switch to this weapon
case "Rocket": {
SetPlayerWeapon(_Player, CSmMode::EWeapon::Rocket, False);
}
case "Laser": {
SetPlayerWeapon(_Player, CSmMode::EWeapon::Laser, False);
}
case "Nucleus": {
SetPlayerWeapon(_Player, CSmMode::EWeapon::Nucleus, False);
}
case "Arrow": {
SetPlayerWeapon(_Player, CSmMode::EWeapon::Arrow, False);
}
}
// Attach the item to the player to display the blue flashing screen feedback
AttachItemToPlayer(_Item, _Player);
// Destroy the item after that
DestroyItem(_Item);
}