home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / KOOB / control / server / misc / item.cs < prev    next >
Encoding:
Text File  |  2006-09-24  |  3.6 KB  |  137 lines

  1. //============================================================================
  2. // control/server/misc/item.cs
  3. //  Copyright (c) 2003, 2005 by Kenneth C.  Finney.
  4. //============================================================================
  5. $RespawnDelay = 20000;
  6. $LoiterDelay = 10000;
  7. function Item::Respawn(%this)
  8. {
  9.    %this.StartFade(0, 0, true);
  10.    %this.setHidden(true);
  11.    // Schedule a resurrection
  12.    %this.Schedule($RespawnDelay, "Hide", false);
  13.    %this.Schedule($RespawnDelay + 10, "StartFade", 3000, 0, false);
  14. }
  15. function Item::SchedulePop(%this)
  16. {
  17.    %this.Schedule($LoiterDelay - 1000, "StartFade", 3000, 0, true);
  18.    %this.Schedule($LoiterDelay, "Delete");
  19. }
  20. function ItemData::OnThrow(%this,%user,%amount)
  21. {
  22.    // Remove the object from the inventory
  23.    if (%amount $= "")
  24.       %amount = 1;
  25.    if (%this.maxInventory !$= "")
  26.       if (%amount > %this.maxInventory)
  27.          %amount = %this.maxInventory;
  28.    if (!%amount)
  29.       return 0;
  30.    %user.DecInventory(%this,%amount);
  31.    %obj = new Item() {
  32.       datablock = %this;
  33.       rotation = "0 0 1 " @ (GetRandom() * 360);
  34.       count = %amount;
  35.    };
  36.    MissionGroup.Add(%obj);
  37.    %obj.SchedulePop();
  38.    return %obj;
  39. }
  40. function ItemData::OnPickup(%this,%obj,%user,%amount)
  41. {
  42.    %count = %obj.count;
  43.    if (%count $= "")
  44.       if (%this.maxInventory !$= "") {
  45.          if (!(%count = %this.maxInventory))
  46.             return;
  47.       }
  48.       else
  49.          %count = 1;
  50.    %user.IncInventory(%this,%count);
  51.    if (%user.client)
  52.       MessageClient(%user.client, 'MsgItemPickup', '\c0You picked up %1', %this.pickupName);
  53.    if (%obj.IsStatic())
  54.       %obj.Respawn();
  55.    else
  56.       %obj.Delete();
  57.    return true;
  58. }
  59. function ItemData::Create(%data)
  60. {
  61.    %obj = new Item() {
  62.       dataBlock = %data;
  63.       static = true;
  64.       rotate = true;
  65.    };
  66.    return %obj;
  67. }
  68. datablock ItemData(Copper)
  69. {
  70.    category = "Coins";
  71.    // Basic Item properties
  72.    shapeFile = "~/data/models/items/kash1.dts";
  73.    mass = 0.7;
  74.    friction = 0.8;
  75.    elasticity = 0.3;
  76.    respawnTime = 30 * 60000;
  77.    salvageTime = 15 * 60000;
  78.    // Dynamic properties defined by the scripts
  79.    pickupName = "a copper coin";
  80.    value = 1;
  81. };
  82. datablock ItemData(Silver)
  83. {
  84.    category = "Coins";
  85.    // Basic Item properties
  86.    shapeFile = "~/data/models/items/kash100.dts";
  87.    mass = 0.7;
  88.    friction = 0.8;
  89.    elasticity = 0.3;
  90.    respawnTime = 30 * 60000;
  91.    salvageTime = 15 * 60000;
  92.    // Dynamic properties defined by the scripts
  93.    pickupName = "a silver coin";
  94.    value = 100;
  95. };
  96. datablock ItemData(Gold)
  97. {
  98.    category = "Coins";
  99.  
  100.    // Basic Item properties
  101.    shapeFile = "~/data/models/items/kash1000.dts";
  102.    mass = 0.7;
  103.    friction = 0.8;
  104.    elasticity = 0.3;
  105.    respawnTime = 30 * 60000;
  106.    salvageTime = 15 * 60000;
  107.    // Dynamic properties defined by the scripts
  108.    pickupName = "a gold coin";
  109.    value = 1000;
  110. };
  111. datablock ItemData(FirstAidKit)
  112. {
  113.    category = "Health";
  114.    // Basic Item properties
  115.    shapeFile = "~/data/models/items/healthPatch.dts";
  116.    mass = 1;
  117.    friction = 1;
  118.    elasticity = 0.3;
  119.    respawnTime = 600000;
  120.    // Dynamic properties defined by the scripts
  121.    repairAmount = 200;
  122.    maxInventory = 0; // No pickup or throw
  123. };
  124. function FirstAidKit::onCollision(%this,%obj,%col)
  125. {
  126.    if (%col.getDamageLevel() != 0 && %col.getState() !$= "Dead" )
  127.    {
  128.       %col.applyRepair(%this.repairAmount);
  129.       %obj.respawn();
  130.       if (%col.client)
  131.       {
  132.          messageClient
  133.               (%col.client,'MSG_Treatment','\c2Medical treatment applied');
  134.       }
  135.    }
  136. }
  137.