Aller au contenu

Photo

If target has item dont run script: script


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

#1
AstoriaWMY

AstoriaWMY
  • Members
  • 15 messages
Alrighty so I was wundering if there is a function for finding if a creature has a specific item or not, and then if they do have the item to not run the rest of the script somthing simular to:

If (!GetIsEnemy(oPC))
{
return;
}

but for a specific item instead of it being a enemy have it be a specific item (either by resref, or tag)

#2
Morbane

Morbane
  • Members
  • 1 883 messages
// Get the object possessed by oCreature with the tag sItemTag
// * Return value on error: OBJECT_INVALID
object GetItemPossessedBy(object oCreature, string sItemTag);

#3
Morbane

Morbane
  • Members
  • 1 883 messages
Try This

Everyone starts with that great tool.

#4
AstoriaWMY

AstoriaWMY
  • Members
  • 15 messages
thanks!

#5
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
This is searchable, and includes the core functions. ( the doxygen links to every function used )

http://70.179.46.242.../csl/index.html

Code is largely usable as is ( copy paste what you need into your own codebase if its a simple function, actual files are on the nexus )

#6
AstoriaWMY

AstoriaWMY
  • Members
  • 15 messages
ive encountered a bit of a snag now in my script...

"void main()

{

object oCaster = OBJECT_SELF;
int nCasterLvl = GetCasterLevel (OBJECT_SELF);
//int nDLvl = GetLevelByclass(class_TYPE_*class, oCaster);
//int nDuration = nDLvl; im going to make the duration by characterlevel but its set to 10.0 for testing purposes
object oItem = GetObjectByTag("itemname");
object pItem = GetItemPossessedBy(oCaster, "itemname");
     DelayCommand(10.0, DestroyObject (oItem));
 if (pItem != OBJECT_INVALID)

                {

                SendMessageToPC(oCaster, "SPELL FAILED: One or more instances of spell Activated.");

                return;


                }                                                                

if (nCasterLvl > 10)
nCasterLvl = 10;

                {

                CreateItemOnObject("itemname", oCaster, nCasterLvl);

                }

                                                               

                }"


The script wont remove the items unless i cast the spell twice...other then that everything runs perfectly

Modifié par AstoriaWMY, 19 juillet 2012 - 07:23 .


#7
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
GetObjectByTag doesn't seem like the best thing to use here, why not just use the GetItemPossessedBy? Why an oItem and a pItem?

#8
AstoriaWMY

AstoriaWMY
  • Members
  • 15 messages
I changed it to just being pItem, didnt help though still wont remove the item unless it gets the return from my if(pItem != OBJECT_VALID)

#9
Morbane

Morbane
  • Members
  • 1 883 messages
Describe what you are trying to do... exactly

Your script is doing things back and forth - like deleting an item then creating it again? I think you are making it more complex than it needs to be.

#10
AstoriaWMY

AstoriaWMY
  • Members
  • 15 messages
alright the script is suppose to make an item when the spell is cast then remove that item after a set duration. If the player already has the item, for example if he cast the spell twice, the effect will fail to prevent the user from stacking the items. I already have the script to remove the item on rest as well. The problem is that after i cast the spell, it gives me the item and then dosnt remove it. When i cast it again it dosnt create another item (which is how its suppose to work) sends the message i wrote, but then removes the item like it was suppose to do the first time.

I need it to remove the item after the set duration after the first time i cast the spell. So is the problem that it cant find the item becuase it hasnt been created yet and therefor wont remove it? and if thats the case how to I fix it so that the order the script is fired is correct?

Modifié par AstoriaWMY, 22 juillet 2012 - 06:12 .


#11
kevL

kevL
  • Members
  • 4 070 messages
void main()
{
  object oCaster = OBJECT_SELF;
  object oItem = GetItemPossessedBy(oCaster, "itemname");
  if (GetIsObjectValid(oItem))
  {
    SendMessageToPC(oCaster, "SPELL FAILED: One or more instances of spell Activated.");
  }
  else
  {
    int nCasterLvl = GetCasterLevel(oCaster);
    if (nCasterLvl > 10) nCasterLvl = 10;

    // NB:
    oItem = CreateItemOnObject("itemname", oCaster, nCasterLvl);

    DelayCommand(10.f, DestroyObject(oItem));
  }
}



i think the problem is that oItem was not getting defined as oItem until the second pass ...

Modifié par kevL, 22 juillet 2012 - 06:46 .


#12
AstoriaWMY

AstoriaWMY
  • Members
  • 15 messages
Yup that was the issue :D thanks guys!

#13
AstoriaWMY

AstoriaWMY
  • Members
  • 15 messages
Using this same script is there a way to make the item bound to the players inventory yet remove itself once the item runs out of stacks.

Ive tried setting the the object to cursed/plot but this makes it so that the item remains in you inventory even after you use all the stacks. Ive also tried the CSLDestroyObjectDropped in the script but nothing happened, i also tried it in a heartbeat but still didnt do anything.

any suggestions?

#14
kevL

kevL
  • Members
  • 4 070 messages
you should probably write a subfunction for the DestroyObject part

Set the items cursed when they are created (or in their blueprint properties):

// When cursed, items cannot be dropped
void SetItemCursedFlag(object oItem, int nCursed);

as a part of void main() in the CreateObject scope,
Then instead of the line
DelayCommand(10.f, DestroyObject(oItem));

use
DelayCommand(10.f, DestroyCursedSpellItem(oItem));

and write a subfunction at the top of the script:

void DestroyCursedSpellItem(object oItem)
{
  SetItemCursedFlag(oItem, FALSE);
  DestroyObject(oItem);
}


- still not sure what's gonna happen if the stack is split tho; then you'll probly have to loop through Inventory ( GetFirst/GetLast etc ) such that if the tag matches, Destroy those extra stacks too -- assuming cursed item stacks can be split .....

I'm not sure how the items are being used, but assuming that a script runs you can write a similar function & use Get/SetItemStackSize(), perhaps quickly switching the flag on/off & thus let them get used up, whether or not the 10 second duration times out

can ya handle the details, the code that runs when Caster uses one item should look something like this:

void ExpendCursedSpellItem(object oItem)
{
  int i = GetItemStackSize(oItem);
  if (i > 1)
  SetItemStackSize(oItem, i - 1);
  else
  {
    SetItemCursedFlag(oItem, FALSE);
    DestroyObject(oItem);
  }
}