Author Topic: A simple script driving me nuts!  (Read 513 times)

Legacy_Jerrus

  • Newbie
  • *
  • Posts: 30
  • Karma: +0/-0
A simple script driving me nuts!
« on: September 03, 2014, 01:38:34 pm »


               

I wrote a script that allows you to activate a bundle of firewood and spawn a campfire if you have a piece of flint in your inventory. Without the flint you just get a message saying that you need flint to start a campfire. Well, the activate function in the firewood's properties is set to single use. So, even if you don't have flint you still lose your bundle of firewood. So, I added a line to add a bundle of firewood back to your inventory if you don't have flint. But now when I activate the firewood in the game without flint it fills my entire inventory up with bundles of firewood. Here's the script. Can someone please tell me what I did wrong. Thanks!!


#include "x2_inc_switches"

void main()

{

object oSpawn;


// Get the PC

object oPC = GetItemActivator();


// Stop if the PC does not have Flint.

if ( GetItemPossessedBy(oPC, "jw_flint") == OBJECT_INVALID )

{

CreateItemOnObject("jw_firewood", oPC, 1);

SendMessageToPC(oPC, "You need a piece of flint to start the fire.");


return;

}


// Spawn Campfire.

oSpawn = CreateObject(OBJECT_TYPE_PLACEABLE, "jw_campfire", GetLocation(oPC));

}


 



               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
A simple script driving me nuts!
« Reply #1 on: September 05, 2014, 04:09:39 am »


               

LOL   I have a guess.    


 


Try adding a the filter for the TBS  to limit it to only fire on activation.   My guess is that you are creating the the firewood OnAquire also. 


 


 


EDIT: 


 




#include "x2_inc_switches"
void main()
{
  if (GetUserDefinedItemEventNumber() != X2_ITEM_EVENT_ACTIVATE) return;
  object oSpawn;


  // Get the PC
  object oPC = GetItemActivator();


  // Stop if the PC does not have Flint.
  if ( GetItemPossessedBy(oPC, "jw_flint") == OBJECT_INVALID )
  {
    CreateItemOnObject("jw_firewood", oPC, 1);
    SendMessageToPC(oPC, "You need a piece of flint to start the fire.");


    return;
  }


  // Spawn Campfire.
  oSpawn = CreateObject(OBJECT_TYPE_PLACEABLE, "jw_campfire", GetLocation(oPC));
}


               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
A simple script driving me nuts!
« Reply #2 on: September 05, 2014, 02:19:15 pm »


               

Heh, that's pretty funny. Lightfoot's got the right fix. I just had a suggestion, which is to make the wood unlimited uses per day and then destroy it when you actually make a campfire. That way you don't need to deal with making a new one at all if there is no flint. You'll want to follow Lightfoot's suggestion either way.


               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
A simple script driving me nuts!
« Reply #3 on: September 05, 2014, 08:21:54 pm »


               

I think SetIsDestroyable helps to prevent from automatical destroy when the last use is consumed (but its long time since Ive dealth with this so I might be wrong).



               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
A simple script driving me nuts!
« Reply #4 on: September 05, 2014, 08:24:49 pm »


               


Try adding a the filter for the TBS  to limit it to only fire on activation.   My guess is that you are creating the the firewood OnAquire also.




 


Bingo!


 




I think SetIsDestroyable helps to prevent from automatical destroy when the last use is consumed (but its long time since Ive dealth with this so I might be wrong).




 


I think you technically might need to set it to plot specifically.


 




Heh, that's pretty funny. Lightfoot's got the right fix. I just had a suggestion, which is to make the wood unlimited uses per day and then destroy it when you actually make a campfire. That way you don't need to deal with making a new one at all if there is no flint. You'll want to follow Lightfoot's suggestion either way.




 


Also a good idea.


 


And thanks for coming here, Jerrus, I think you'll find it very helpful.



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
A simple script driving me nuts!
« Reply #5 on: September 05, 2014, 11:17:58 pm »


               


 


I think you technically might need to set it to plot specifically.


 




 


Nope the Destroyable flags blocks all forms of destruction (hard-coded and DestroyObject).  The plot flag only blocks a few types of hard-coded destruction.


 


But in this case you would not need either blockage, as the 0 charge per uses or unlimited use per day will not cause the object to be destroyed if listed as the last cast spell item property.



               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
A simple script driving me nuts!
« Reply #6 on: September 06, 2014, 02:00:15 am »


               

Ah, so they'd both work in the particular case Shadow mentioned, then.


 


But yeah, if it's unlimited uses then it doesn't matter.



               
               

               
            

Legacy_Jerrus

  • Newbie
  • *
  • Posts: 30
  • Karma: +0/-0
A simple script driving me nuts!
« Reply #7 on: September 06, 2014, 03:37:50 am »


               

Thanks everyone!! That worked great.


 




 


 


 My guess is that you are creating the the firewood OnAquire also. 


 




That explains another problem that I was having with the firewood when I did have flint. After I activated the firewood with the flint in my inventory once, from then on every time I picked up a bundle of firewood it instantly spawned a campfire. I figured it was all part of the same problem. Thanks Lightfoot8!!


 



And thanks for coming here, Jerrus, I think you'll find it very helpful.


Thank you for convincing me to try and register here again. I tried one time a while back and it wouldn't let me for some reason.