Aller au contenu

Photo

A simple script driving me nuts!


  • Veuillez vous connecter pour répondre
7 réponses à ce sujet

#1
Jerrus

Jerrus
  • Members
  • 15 messages
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));
}

 



#2
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

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));
}

  • Squatting Monk aime ceci

#3
meaglyn

meaglyn
  • Members
  • 813 messages

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.


  • Squatting Monk et Verilazic aiment ceci

#4
Shadooow

Shadooow
  • Members
  • 4 471 messages

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).



#5
MagicalMaster

MagicalMaster
  • Members
  • 2 003 messages

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.



#6
WhiZard

WhiZard
  • Members
  • 1 204 messages

 

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.



#7
MagicalMaster

MagicalMaster
  • Members
  • 2 003 messages

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.



#8
Jerrus

Jerrus
  • Members
  • 15 messages

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.