Author Topic: Script duplicating items, need help  (Read 402 times)

Legacy_archer4217

  • Full Member
  • ***
  • Posts: 206
  • Karma: +0/-0
Script duplicating items, need help
« on: September 19, 2011, 07:33:50 pm »


               Hi all,

I have two problems I need help with today.

First,I have this script that's supposed to give a piece of turkey when the pc uses a whole turkey with 8 charges on it. It works fine, but it gives 2 pieces each time, instead of just one. How can I fix this?
Here's the script.

/*   Script generated by
Lilac Soul's NWN Script Generator, v. 2.3

For download info, please visit:
http://nwvault.ign.c...=4683&id=625テつ テつ テつ  */

void main()
{
object oPC;

if (GetIsInCombat(GetItemActivator())
){

SendMessageToPC(GetItemActivator(), "Improper use of item!");
return;}

oPC = GetItemActivatedTarget();

CreateItemOnObject("turkey_piece", oPC);

}

Second problem is that I have certain items that when used give the pc a boost to certain abilities, stats, etc. How can I keep these effects from stacking? For instance, in the following script, the pc's hit points are supposed to be raised +5 temporarily. I don't want players using piece after piece after piece raising their hp up and up and up.

/*   Script generated by
Lilac Soul's NWN Script Generator, v. 2.3

For download info, please visit:
http://nwvault.ign.c...=4683&id=625テつ テつ テつ  */

void main()
{
object oPC;

if (GetIsInCombat(GetItemActivator())
){

SendMessageToPC(GetItemActivator(), "Improper use of item!");
return;}

oPC = GetItemActivator();

object oTarget;
oTarget = oPC;

effect eEffect;
eEffect = EffectTemporaryHitpoints(5);

ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect, oTarget, 600.0f);

}

Any help is greatly appreciated. :happy:
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Script duplicating items, need help
« Reply #1 on: September 19, 2011, 08:44:10 pm »


               CreateItemOnObject("turkey_piece", oPC, 1);

In the Create Item Function you should tell it how many instances of the object you wish to create on the target, in this case oPC.  Do not know if by chance something has been changed to automatically give out 2 instances of an item when you create an item on an object, but you definitely can override that with putting 1 after oPC..

I'm not positive 100% this will solve the issue you are having, but it's a start, let me know if this worked.

If "turkey_piece" is also the name of the item they are using, then yeah, the original never got destroyed, e.g. they have the original plus the new one, that's the only other problem I can possibly forsee here.

You can use:

object oItem = GetItemActivated();
DestroyObject(oItem, 0.0);

to get rid of the original.

--------------------
In the second problem, all you need to do is set a local int on the PC after they use the item to buff, and check it before they are allowed to buff, e.g...

 object oPC = GetItemActivator();

 if (GetIsInCombat(oPC))
 { SendMessageToPC(oPC, "Not usable in combat!"); return;}

 if(GetLocalInt(oPC, "BUFFED")==TRUE) {return;} //Stop here if they have buffed before..

 //Set that they have buffed now
 SetLocalInt(oPC, "BUFFED", TRUE);
 //After 600 Seconds set it so that they can buff again...
 DelayCommand(600.0, SetLocalInt(oPC, "BUFFED", FALSE));
               
               

               


                     Modifiテδゥ par _Guile, 19 septembre 2011 - 07:55 .
                     
                  


            

Legacy_archer4217

  • Full Member
  • ***
  • Posts: 206
  • Karma: +0/-0
Script duplicating items, need help
« Reply #2 on: September 19, 2011, 10:25:31 pm »


               Thank you very much, sweetie. The buff is no longer stacking. *hugs*
               
               

               
            

Legacy_Aradan Kir

  • Jr. Member
  • **
  • Posts: 57
  • Karma: +0/-0
Script duplicating items, need help
« Reply #3 on: September 20, 2011, 06:56:47 pm »


               Re the first problem - it could be that your script is not just firing when the item is used, but possibly when the turkey item is affected in any way (picked up, dropped etc).

As a test - try sending a message at the top of the script and see how often that's displayed.

If it is that, you can GetUserDefinedItemEventNumber() and if it matches X2_ITEM_EVENT_ACTIVATE then do your creation code there - which means it should only create the turkey piece when the turkey item is used.  You'll need to add #include "x2_inc_switches to the top of your script
               
               

               


                     Modifiテδゥ par aradankir, 20 septembre 2011 - 05:58 .
                     
                  


            

Legacy_archer4217

  • Full Member
  • ***
  • Posts: 206
  • Karma: +0/-0
Script duplicating items, need help
« Reply #4 on: September 24, 2011, 12:53:10 am »


               Hi all,

So, I was trying to figure out why I keep getting two items instead of just one when activating something, and I went into my mod events and this is some of the script I have in the on activate slot. I noticed it has these lines I highlighted in red below and wondered if it could be the duplicating problem?

// Script: zep_on_activate
// by Barry_1066
// Feb. 12 2008 for CEP/DLA horse systems
// Integrates BOTH old and Tag based systems

#include "x3_inc_horse"
#include "z_inc_phenos"
#include "x2_inc_switches"
#include "nw_i0_generic"
void main()
{

 ExecuteScript (GetResRef (GetItemActivated()), GetItemActivator());
 ExecuteScript("xg_create_camps",OBJECT_SELF);
 ExecuteScript("int_mod_def_act",OBJECT_SELF);

object oItem = GetItemActivated();

    object oActivator = GetItemActivator();
    object oPC = GetItemActivator();
    object oTarget = GetItemActivatedTarget();
    string sTag = GetTag(oTarget);
    string sItem = GetTag(oItem);
    object oArea = GetArea(oTarget);
    location lActivator = GetLocation(oActivator);
    string sItemTag = GetTag(oItem);
    location lTarget = GetItemActivatedTargetLocation();

Any help is greatly appreciated. :happy:
               
               

               


                     Modifiテδゥ par archer4217, 23 septembre 2011 - 11:58 .
                     
                  


            

Legacy_Morbane

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-0
Script duplicating items, need help
« Reply #5 on: September 24, 2011, 02:33:39 am »


               I dont think those assignments will do what you are asking - at least not in the snippit you posted.
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Script duplicating items, need help
« Reply #6 on: September 24, 2011, 03:05:18 am »


               It's probably because you are Executing the OnActivateEvent TWICE!.. '<img'>

Delete this line and let me know

ExecuteScript (GetResRef (GetItemActivated()), GetItemActivator());
               
               

               
            

Legacy_archer4217

  • Full Member
  • ***
  • Posts: 206
  • Karma: +0/-0
Script duplicating items, need help
« Reply #7 on: September 26, 2011, 04:12:41 am »


               Guile, that was exactly the problem!! Thank you so much. *hugs* '<img'>
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Script duplicating items, need help
« Reply #8 on: September 26, 2011, 06:39:02 am »


               

archer4217 wrote...

Guile, that was exactly the problem!! Thank you so much. *hugs* '<img'>


Glad I could assist ya mate..   '^_^'