Author Topic: Node Coloring || Ranged Vectors || Emitters && Corpses  (Read 4313 times)

player collisions are a cylinder around you, not a model-to-model collision.
Last time I checked it was a rectangular prism that didn't rotate with you

Darn, I'm back again. I've been working on a ghost-type gamemode where when you die, you don't just respawn, but you become a spooky ghost and you have to find a corpse to possess. I've make the possession button left click. It pretty much just makes a radius search, and then checks for $Typemasks::CorpseObjectType. I can't use raycasts since corpses don't have collision. Yet, corpses are probably only detected 1/4 of the time, and the command flat out stops working sometimes. I have no idea what's wrong.
//Haunted gamemode.
package Haunted
{
   function Player::removeBody(%player)
   {
      if($gamemode $= "Haunted")
         return;
      parent::removeBody(%player);
   }
   function gameConnection::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc)
   {
      if($gamemode $= "Haunted")
      {
         if(%client.isGhost == 1)
         {
            %pos = %client.player.getPosition();
            %client.chatMessage("\c3You can't die! You're already dead...");
            %client.instantRespawn();
            %client.player.setTransform(%pos);
            %client.player.setNodeColor("ALL","1 1 1 0.4");
            %client.player.mountImage(GhostTrailImage,$backslot);
            return;
         }
         else
         {
            %client.isGhost = 1;
            %corpse = %client.player;
            %corpse.setShapeNameDistance(0);
            %client.createPlayer(%corpse.getPosition());
            %client.player.setNodeColor("ALL","1 1 1 0.4");
            %client.player.mountImage(GhostTrailImage,$backslot);
            %client.player.setMaxForwardSpeed(13);
            return;
         }
      }
      else
         parent::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc);
   }
   function armor::onTrigger(%armor, %player, %slot, %value)
   {
      %client = %player.client;
      if(%slot == 0 && %client.isGhost == 1 && %client.cooldown < $Sim::Time)
      {
         %client.cooldown = $Sim::Time + 1;
         initContainerRadiusSearch(%player.getPosition(),13,$Typemasks::CorpseObjectType);
         %corpse = containerSearchNext();
         while(%corpse = containerSearchNext())
         {
            %hasFoundCorpse++;
            if(%client == %corpse.client)
            {
               %client.chatMessage("\c3You can't use your own corpse to revive!");
               return;
            }
            %client.chatMessage("\c3A corpse has been detected! You are being reborn...");
            %client.isGhost = 0;
            %client.player.schedule(33, delete);
            %client.createPlayer(%corpse.getTransform());
            %corpse.delete();
            return;
         }
         if(%hasFoundCorpse == 0)
         {
            %client.chatMessage("\c3You have tried to ressurect yourself, but there are no corpses in the area.");
         }
      }
      parent::onTrigger(%armor, %player, %slot, %value);
   }
   function servercmdLight(%client)
   {
      if(%client.isGhost)
      {
         %client.player.addVelocity("0 0 10");
         return;
      }
      parent::servercmdLight(%client);
   }
   function servercmdUpdateBodyColors(%client, %a, %b, %c, %d, %e, %f, %g, %h, %i, %j, %k, %l, %m, %body, %face)
   {
      if(%client.isGhost == 1)
      {
         %client.chatMessage("\c3You're a ghost! You can't change your appearance.");
         return;
      }
      parent::servercmdUpdateBodyColors(%client, %a, %b, %c, %d, %e, %f, %g, %h, %i, %j, %k, %l, %m, %body, %face);
   }
   function servercmdUpdateBodyParts(%client, %a, %b, %c, %d, %e, %f, %g, %h, %i, %j, %k, %l, %m, %body, %face)
   {
      if(%client.isGhost == 1)
         return;
      parent::servercmdUpdateBodyColors(%client, %a, %b, %c, %d, %e, %f, %g, %h, %i, %j, %k, %l, %m, %body, %face);
   }
};
activatePackage(Haunted);

For remove body, I usually put another variable like %value, so when that value is 1, it can parent the function.

For remove body, I usually put another variable like %value, so when that value is 1, it can parent the function.

It's usually bad practice to change the signature of the function you're packaging.

For remove body, I usually put another variable like %value, so when that value is 1, it can parent the function.

Put the functions that want to call the "real" remove body in the same package and they can call the parent:

Code: [Select]
package idk
{
    function serverCmdLight(%client)
    {
        return;
    }
   
    function manualLight(%client)
    {
        Parent::serverCmdLight(%client);
    }
};
activatePackage(idk);

Also, you can just do a raycast for $Typemasks::CorpseObjectType.

Also, you can just do a raycast for $Typemasks::CorpseObjectType.

No, raycasts don't collide with corpses

I thought you could use any type mask with raycasts. That's dumb.

Do you guys have any idea whats causing the function to sometimes not detect corpses?

Do you guys have any idea whats causing the function to sometimes not detect corpses?
Explain what you mean detect corpses and clarify a little more of where you detect corpses (On Possession? On Exiting?)

Explain what you mean detect corpses and clarify a little more of where you detect corpses (On Possession? On Exiting?)
If you look at his code, he obviously means detecting corpses when the player clicks.

The specific part I'm working on is where the player clicks as a ghost, and it starts a container radius search to check if there are any corpses within a range of 13 whatever-units. If it does find a corpse, the player then possesses that corpse. The script knocks them out of ghostmode and spawns them at the location of that corpse. Half of the time I run this though, it spits out saying it hasn't found any corpses, even though I'm next to several.

The specific part I'm working on is where the player clicks as a ghost, and it starts a container radius search to check if there are any corpses within a range of 13 whatever-units. If it does find a corpse, the player then possesses that corpse. The script knocks them out of ghostmode and spawns them at the location of that corpse. Half of the time I run this though, it spits out saying it hasn't found any corpses, even though I'm next to several.
         while(%corpse = containerSearchNext())
         {
            %hasFoundCorpse++;
            if(%client == %corpse.client)
            {
               %client.chatMessage("\c3You can't use your own corpse to revive!");
               return;
            }
            %client.chatMessage("\c3A corpse has been detected! You are being reborn...");
            %client.isGhost = 0;
            %client.player.schedule(33, delete);
            %client.createPlayer(%corpse.getTransform());
            %corpse.delete();
            return;
         }
Using return; in any part of the method instantly ends the method itself, not just the current block. In the case of your code, you return; as soon as the first while loop pass through occurs, regardless if it should have or not, meaning the while loops ends on whatever object was located first. What you should do instead, is put the part where you are revived in an else block and add a break; at the end. break; ends the loop prematurely and continues on with the code outside of the while block.

   function armor::onTrigger(%armor, %player, %slot, %value)
   {
      %client = %player.client;
      if(%slot == 0 && %client.isGhost == 1 && %client.cooldown < $Sim::Time)
      {
         %client.cooldown = $Sim::Time + 1;
         initContainerRadiusSearch(%player.getPosition(),5,$Typemasks::CorpseObjectType);
         %corpse = containerSearchNext();
         while(%corpse = containerSearchNext())
         {
            %hasFoundCorpse++;
            if(%client == %corpse.client)
            {
               %client.chatMessage("\c3You can't use your own corpse to revive!");
            }
            else if(%hasFoundIdealCorpse > 0)
            {
               %hasFoundIdealCorpse++;
               %client.chatMessage("\c3A corpse has been detected! You are being reborn...");
               %client.isGhost = 0;
               %client.player.schedule(33, delete);
               %client.createPlayer(%corpse.getTransform());
               %corpse.delete();
            }
         }
         if(%hasFoundCorpse == 0)
         {
            %client.chatMessage("\c3You have tried to ressurect yourself, but there are no corpses in the area.");
         }
      }
      parent::onTrigger(%armor, %player, %slot, %value);
   }

I just reformatted the thing to use if-statements. For some reason, it still doesn't work. I genuinely believe that by nature, corpse detection is really glitchy. I'll be standing on top of a corpse, and it still says there are no corpses in the area.

%hasFoundIdeal corpse doesn't exist, so it can never be >0, so your code never runs