Author Topic: change a player's node color when they get shot  (Read 3930 times)

/title
Code: [Select]
package ProjectileDismemberment
{
   function ProjectileData::damage(%this, %obj, %col, %fade, %pos, %normal)
   {
   parent::damage(%this, %obj, %col, %fade, %pos, %normal);
      if(%col.gettype() & $TypeMasks::PlayerObjectType && fileName(%col.dataBlock.shapeFile) $= "m.dts")
   {
      %fvec = %col.getForwardVector();
      %vec1 = -getWord(%fvec,1) SPC getWord(%fvec,0) SPC 0;
      %vec2 = vectorNormalize(%obj.initialVelocity);
     
      %damloc = (vectorDot(%vec1,%vec2) > 0);
     
      %scale = getWord(%col.getScale(),2);
      if(getword(%pos, 2) > getword(%col.getWorldBoxCenter(), 2) - 3.3*%scale)
      {
         %client.player.setNodeColor(headskin, "0.6, 0, 0 1");
         %col.kill();
         if(!%col.disHead)
            {
            %col.dishead = 1;
         %proj = new Projectile()
            {
               scale = %col.getScale();
here is a little snip from the code, i have used
Code: [Select]
%client.player.setNodeColor(headskin, "0.6, 0, 0 1"); but it doesn't want to work, help?

%client isnt an object in the function; replace %client.player with %col since %col is the object the bullet collided with, aka the player object the projectile hit

alright thanks but I have run into an another issue,
I tried making the torso also color but I am having this syntax error, probably because there isn't enough or there is too much brackets
Code: [Select]
package ProjectileDismemberment
{
   function ProjectileData::damage(%this, %obj, %col, %fade, %pos, %normal)
   {
   parent::damage(%this, %obj, %col, %fade, %pos, %normal);
      if(%col.gettype() & $TypeMasks::PlayerObjectType && fileName(%col.dataBlock.shapeFile) $= "m.dts")
   {
      %fvec = %col.getForwardVector();
      %vec1 = -getWord(%fvec,1) SPC getWord(%fvec,0) SPC 0;
      %vec2 = vectorNormalize(%obj.initialVelocity);
      
      %damloc = (vectorDot(%vec1,%vec2) > 0);
      
      %scale = getWord(%col.getScale(),2);
      if(getword(%pos, 2) > getword(%col.getWorldBoxCenter(), 2) - 3.3*%scale)
      {
         %col.player.setNodeColor(headskin, "0.6 0 0 1");
         %col.kill();
         if(!%col.disHead)
            {
            %col.dishead = 1;
         %proj = new Projectile()
            {
               scale = %col.getScale();
               dataBlock = DismemExplosionProjectileaaa;
               initialVelocity = %col.getVelocity();
               initialPosition = %col.getPosition();
               sourceObject = %col;
               sourceSlot = 0;
               client = %col.client;
            };
            MissionCleanup.add(%proj);
            }
         for(%i=0;$hat[%i] !$= "";%i++) %hidestr = %hidestr SPC $hat[%i];
         for(%i=0;$accent[%i] !$= "";%i++) %hidestr = %hidestr SPC $accent[%i];
      }
      else if(getword(%pos, 2) > getword(%col.getWorldBoxCenter(), 2) - 4.5*%scale)
      {
         if(%damLoc == 0)
         {
%col.player.setNodeColor(lhand, "0.6 0 0 1");
%col.player.setNodeColor(lhook, "0.6 0 0 1");
%col.player.setNodeColor(larm, "0.6 0 0 1");
%col.player.setNodeColor(larmslim, "0.6 0 0 1");

            if(!%col.dislhand)
            {
            %col.disLhand = 1;
            %proj = new Projectile()
            {
               scale = %col.getScale();
               dataBlock = DismemLHandProjectileaaaa;
               initialVelocity = %col.getVelocity();
               initialPosition = %col.getPosition();
               sourceObject = %col;
               sourceSlot = 0;
               client = %col.client;
            };
            MissionCleanup.add(%proj);
            %proj = new Projectile()
            {
               scale = %col.getScale();
               dataBlock = DismemshoulderProjectileaaaaa;
               initialVelocity = %col.getVelocity();
               initialPosition = %col.getPosition();
               sourceObject = %col;
               sourceSlot = 0;
               client = %col.client;
            };
            MissionCleanup.add(%proj);
            }
         }
         else
         {
%col.player.setNodeColor(rhand, "0.6 0 0 1");
%col.player.setNodeColor(rhook, "0.6 0 0 1");
%col.player.setNodeColor(rarm, "0.6 0 0 1");
%col.player.setNodeColor(rarmslim, "0.6 0 0 1");
            if(!%col.dishand)
            {
            %col.dishand = 1;
            %proj = new Projectile()
            {
               scale = %col.getScale();
               dataBlock = DismemHandProjectileaaaa;
               initialVelocity = %col.getVelocity();
               initialPosition = %col.getPosition();
               sourceObject = %col;
               sourceSlot = 0;
               client = %col.client;
            };
            MissionCleanup.add(%proj);
            %proj = new Projectile()
            {
               scale = %col.getScale();
               dataBlock = DismemshoulderProjectileaaaaa;
               initialVelocity = %col.getVelocity();
               initialPosition = %col.getPosition();
               sourceObject = %col;
               sourceSlot = 0;
               client = %col.client;
            };
            MissionCleanup.add(%proj);
         }
         }
      }
      else
 {
%col.player.setNodeColor(chest, "0.6 0 0 1");
%col.player.setNodeColor(femchest, "0.6 0 0 1");
            if(!%col.dischest)
            {
            %col.dischest = 1;
            %proj = new Projectile()
            {
               scale = %col.getScale();
               dataBlock = DismemHandProjectileaaaa;
               initialVelocity = %col.getVelocity();
               initialPosition = %col.getPosition();
               sourceObject = %col;
               sourceSlot = 0;
               client = %col.client;
            };
            MissionCleanup.add(%proj);
            %proj = new Projectile()
            {
               scale = %col.getScale();
               dataBlock = DismemshoulderProjectileaaaaa;
               initialVelocity = %col.getVelocity();
               initialPosition = %col.getPosition();
               sourceObject = %col;
               sourceSlot = 0;
               client = %col.client;
            };
            MissionCleanup.add(%proj);
         }
      }
      else
      {
         if(%damLoc == 0)
         {
%col.player.setNodeColor(lshoe, "0.6 0 0 1");
%col.player.setNodeColor(lpeg, "0.6 0 0 1");
%col.player.setNodeColor(pants, "0.6 0 0 1");
            if(!%col.dislfoot)
            {
            %col.disLfoot = 1;
            %col.setCrouching(1);
            %proj = new Projectile()
            {
               scale = %col.getScale();
               dataBlock = DismemFootProjectileaaaa;
               initialVelocity = %col.getVelocity();
               initialPosition = %col.getPosition();
               sourceObject = %col;
               sourceSlot = 0;
               client = %col.client;
            };
            MissionCleanup.add(%proj);
            }
         }
         else
         {
%col.player.setNodeColor(rshoe, "0.6 0 0 1");
%col.player.setNodeColor(rpeg, "0.6 0 0 1");
%col.player.setNodeColor(pants, "0.6 0 0 1");
            if(!%col.disfoot)
            {
            %col.disfoot = 1;
            %col.setCrouching(1);
            %proj = new Projectile()
            {
               scale = %col.getScale();
               dataBlock = DismemFootProjectileaaaaa;
               initialVelocity = %col.getVelocity();
               initialPosition = %col.getPosition();
               sourceObject = %col;
               sourceSlot = 0;
               client = %col.client;
            };
            MissionCleanup.add(%proj);
            }
         }
      }
      
      if(%col.dismembermentUnhideStr $= "")
         %col.dismembermentUnhideStr = "START";
      
      for(%i=0;%i<getWordCount(%hidestr);%i++)
      {
         %node = getWord(%hidestr,%i);
         if(%col.isNodeVisible(%node) && strStr(%col.dismembermentUnhideStr," " @ %node) == -1)
            %col.dismembermentUnhideStr = %col.dismembermentUnhideStr SPC %node;
        
         %col.hideNode(%node);
      }
      
      cancel(%col.dismembermentResetSched);
      %col.dismembermentResetSched = %col.schedule(5000,dismembermentReset);
   }
heeeelp

EDIT: oh yeah also the syntax shows above the torso color node part
« Last Edit: August 13, 2017, 01:09:15 PM by _OXBADCODE# »

you really need to fix your spacing/formatting cause thats how you catch syntax bugs. i advise going through and redoing all the formatting (indent every bracket's contents an extra tab or something thats at least consistent and doesnt have multiple open/close brackets on the same indent).

since the formatting is forgeted i can only guess that you have an extra close brace above the chest node recolor, but i cant be sure

I have no idea how spacing and formatting works lmao, sometimes it works  sometimes it doesn't
is there some kind of a program that can show me what is the issue or whatever

I have no idea how spacing and formatting works lmao, sometimes it works  sometimes it doesn't
is there some kind of a program that can show me what is the issue or whatever
spacing doesnt affect whether or not code works its just for the coder and any potential readers

the error message from blockland is probably the best kind of error response you can get short of jury rigging another program to do it
« Last Edit: August 13, 2017, 03:29:42 PM by Conan »

the error message from blockland is probably the best kind of error response you can get short of jury rigging another program to do it
well this is what blockland is telling me

you have one too many }

you have one too many }
I'm probably aware of that, my question is what do I need to change and what are the rules of brackets cause I have no idea how to fix it

the rules of brackets are { put stuff here }

what you did is { put stuff here }}

ok i deleted some brackets and now the syntax error is uh, well here

post full code of that part

missing parenthesis at the end of the if statement

im not too sure if this is needed but if(%col.gettype() might need parenthesis for it

my personal way of formatting. A pair of { and } will always be in the same column, with their contents to the right, so they're easier to see.

Code: [Select]
function formatting(%a,%b,%c) //(%a, %b, %c) is also acceptable!
{ //{ on a new line
%d = %a+%b; //Tab because of previous {
if(%d > %c)
%e = %b+%c; //Tab because of single-line if
if(%e > 20)
{
%a++;  //more tabs!
%b++;
%c++;
%d++;
}  //less tabs because }
return %b+%d;
}

//commentless
function formatting(%a,%b,%c)
{
%d = %a+%b;
if(%d > %c)
%e = %b+%c;
if(%e > 20)
{
%a++;
%b++;
%c++;
%d++;
}
return %b+%d;
}

//note, use the TAB KEY, not just a bunch of spaces!