Author Topic: CreateObject -.2 down the Z axis  (Read 407 times)

Legacy_GIANTSWORD

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
CreateObject -.2 down the Z axis
« on: February 09, 2015, 06:51:15 am »


               

PC adds firewood to their fire turning the campfire placeable into a bonfire placeable.


 


Is it possible to spawn it in the exact location of the old campfire but bring it down -.2 the Z axis?


 


Here is what I have so far.  The bonfire placeable just isn't appearing at all.  Thanks in advance!


 


location lTarget;

location lTarget1;

object oTarget;

object oItem;

 

#include "nw_i0_2q4luskan"

void main()

{

object oPC = GetPCSpeaker();

if (GetItemPossessedBy(oPC, "wood_firewood")!= OBJECT_INVALID)

    {

    AssignCommand(oPC, ActionPlayAnimation(ANIMATION_LOOPING_GET_LOW, 1.0f, 5.0f));

    oItem = GetItemPossessedBy(oPC, "wood_firewood");

    if (GetIsObjectValid(oItem))    DestroyObject(oItem);

 

    oTarget = GetObjectByTag("FIRE");

    DelayCommand(3.0, DestroyObject(oTarget, 0.0));

 

    lTarget = GetLocation(oTarget);

    vector vCurrentPosition = GetPosition(oTarget);

    vector vNewPosition = Vector();

    vNewPosition.x= vCurrentPosition.x;

    vNewPosition.y= vCurrentPosition.y;

    vNewPosition.z= vCurrentPosition.z - 0.20;

    location lTargetl= Location(OBJECT_SELF, vNewPosition, 0.0);

 

    DelayCommand(1.5, CreateObjectVoid(OBJECT_TYPE_PLACEABLE, "bonfireflame", lTarget));

    DelayCommand(3.0, CreateObjectVoid(OBJECT_TYPE_PLACEABLE, "bonfire", lTarget1));

    DelayCommand(3.0, CreateObjectVoid(OBJECT_TYPE_PLACEABLE, "zep_smokeb", lTarget));

    DelayCommand(3.0, FloatingTextStringOnCreature("The fire begins to roar!", oPC));

    }

else

    {

    SendMessageToPC(oPC, "You don't have any firewood");

    }

}


               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
CreateObject -.2 down the Z axis
« Reply #1 on: February 09, 2015, 07:16:31 am »


               

What you're doing with the z-axis is fine. Your code could be simplified, but I suspect that the big problem is Location(OBJECT_SELF, vNewPosition, 0.0). The first parameter should be the area (e.g. GetArea(oPC)).



               
               

               
            

Legacy_GIANTSWORD

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
CreateObject -.2 down the Z axis
« Reply #2 on: February 09, 2015, 08:16:10 am »


               

Changed it to the area and still no dice.



               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
CreateObject -.2 down the Z axis
« Reply #3 on: February 09, 2015, 10:06:32 am »


               

I've always done my vectors a little different. Maybe try it like so?


 


 


#include "nw_i0_2q4luskan"

void main()

{

    object oPC = GetPCSpeaker();

    object oWood = GetItemPossessedBy(oPC, "wood_firewood");


    if (oWood != OBJECT_INVALID)

    {

        object oFire = GetObjectByTag("FIRE");

        object oArea = GetArea(oFire);

        vector vCurrentPosition = GetPosition(oFire);

        float fX = vCurrentPosition.x;

        float fY = vCurrentPosition.y;

        float fZ = vCurrentPosition.z - 0.2;

        vector vNewPosition = Vector(fX, fY, fZ);

        location lTarget = Location(oArea, vNewPosition, 0.0);


        AssignCommand(oPC, ActionPlayAnimation(ANIMATION_LOOPING_GET_LOW, 1.0f, 5.0f));

        DestroyObject(oWood);

        DestroyObject(oFire, 3.0);

        DelayCommand(1.5, CreateObjectVoid(OBJECT_TYPE_PLACEABLE, "bonfireflame", lTarget));

        DelayCommand(3.0, CreateObjectVoid(OBJECT_TYPE_PLACEABLE, "bonfire", lTarget));

        DelayCommand(3.0, CreateObjectVoid(OBJECT_TYPE_PLACEABLE, "zep_smokeb", lTarget));

        DelayCommand(3.0, FloatingTextStringOnCreature("The fire begins to roar!", oPC));

    }


    else

    {

        SendMessageToPC(oPC, "You don't have any firewood");

    }

}


 


 


Hope it helps.



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
CreateObject -.2 down the Z axis
« Reply #4 on: February 09, 2015, 02:20:50 pm »


               

What object / event is running the script? Does everything work except for the bonfire placeable? Have you checked that its resref (not tag) is "bonfire"?



               
               

               
            

Legacy_GIANTSWORD

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
CreateObject -.2 down the Z axis
« Reply #5 on: February 09, 2015, 04:53:56 pm »


               

The event is a conversation that appears when you click a campfire.  Adding wood runs the script above.  The resref is correct and works when I take out the vector part of the script.  So it does spawn in correctly until I try to mess with the Z axis using vectors.


 


GhostOfGod, thank you.  I'll try that version and see if it works.



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
CreateObject -.2 down the Z axis
« Reply #6 on: February 09, 2015, 06:05:06 pm »


               


 



        location lTargetl= Location(OBJECT_SELF, vNewPosition, 0.0);


 




 


 


This is your problem.  You defined lTargetl and never used it.  (You used lTarget and lTarget1 which were also defined).


               
               

               
            

Legacy_GIANTSWORD

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
CreateObject -.2 down the Z axis
« Reply #7 on: February 09, 2015, 06:16:43 pm »


               

Thanks WhiZard!



               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
CreateObject -.2 down the Z axis
« Reply #8 on: February 11, 2015, 02:06:01 am »


               

I've always done my vectors a little different. Maybe try it like so?

 

 

...

      

        vector vCurrentPosition = GetPosition(oFire);

        float fX = vCurrentPosition.x;

        float fY = vCurrentPosition.y;

        float fZ = vCurrentPosition.z - 0.2;

        vector vNewPosition = Vector(fX, fY, fZ);

        location lTarget = Location(oArea, vNewPosition, 0.0);


...       

 

Hope it helps.



 

 

This is not a correction. But I do my vectors a little different also.  

Instead of taring the vector apart to adjust it. I find it simpler to just add the vector of change to it.  

like so:

 

...

      

        vector vCurrentPosition = GetPosition(oFire);

        vector vNewPosition = vCurrentPosition + Vector(0.0, 0.0, -0.2);

        location lTarget = Location(oArea, vNewPosition, 0.0);


...


 


Or simply


 


    vector vNewPosition = GetPosition(oFire) + Vector(0.0, 0.0, -0.2);


    location lTarget = Location(oArea, vNewPosition, 0.0);


 


 


Just another way to look at it.