Aller au contenu

Photo

Need help with this tag-based script


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

#1
StefanoD

StefanoD
  • Members
  • 20 messages

So, I'm new to scripting and (re)started a module and want to implement new stuff into it.

 

So I started with something fairly simple:

#include "x2_inc_switches"

void main()

if (GetTag(oItem) == "SRBwand")
{

       // get the wand's activator and target, put target info into local vars on activator
      object oPC = GetItemActivator();
      object oMyTarget = GetItemActivatedTarget();
      SetLocalObject(oPC, "BPWandTarget", oMyTarget);
      location lTargetLoc = GetItemActivatedTargetLocation();
      SetLocalLocation(oPC, "BPWandLoc", lTargetLoc);

      //Make the activator start a conversation with itself
      AssignCommand(oPC, ActionStartConversation(oPC, "everything", TRUE));
      return;
}

The thing is: I don't see any error in this script but it's saying that "if (GetTag(oItem) == "SRBwand")" is wrong "Unknows State in Compiler" I already searched everywhere but when I compare the correct scripts, they look exactly the same as mine. I don't know what to do.



#2
Tarot Redhand

Tarot Redhand
  • Members
  • 2 687 messages

So what is oItem? Where does it come from? In the code you've shown you haven't declared it anywhere. Also you haven't got any braces for void main() (i.e. no "{" or "}".)

 

TR


  • StefanoD aime ceci

#3
kalbaern

kalbaern
  • Members
  • 824 messages

Give this a shot:

 

#include "x2_inc_switches"

void main()
{
int nEvent =GetUserDefinedItemEventNumber();
if(nEvent !=  X2_ITEM_EVENT_ACTIVATE)return;
object oItem = GetItemActivated();

if (GetTag(oItem) == "SRBwand")
{

       // get the wand's activator and target, put target info into local vars on activator
      object oPC = GetItemActivator();
      object oMyTarget = GetItemActivatedTarget();
      SetLocalObject(oPC, "BPWandTarget", oMyTarget);
      location lTargetLoc = GetItemActivatedTargetLocation();
      SetLocalLocation(oPC, "BPWandLoc", lTargetLoc);

      //Make the activator start a conversation with itself
      AssignCommand(oPC, ActionStartConversation(oPC, "everything", TRUE));
      return;
}
}

  • StefanoD aime ceci

#4
GhostOfGod

GhostOfGod
  • Members
  • 863 messages

Also on a side note if you have tag-based scripting activated then you also don't need the line that checks for the tag. You just need to make sure that the name of the script matches the tag of the item.



#5
StefanoD

StefanoD
  • Members
  • 20 messages

Tarot Redhand was right, all I had to do was to put 

object oItem = GetItemActivated();

Before putting

if (GetTag(oItem) == "SRBwand")
{

       // get the wand's activator and target, put target info into local vars on activator
      object oPC = GetItemActivator();
      object oMyTarget = GetItemActivatedTarget();
      SetLocalObject(oPC, "BPWandTarget", oMyTarget);
      location lTargetLoc = GetItemActivatedTargetLocation();
      SetLocalLocation(oPC, "BPWandLoc", lTargetLoc);

      //Make the activator start a conversation with itself
      AssignCommand(oPC, ActionStartConversation(oPC, "everything", TRUE));
      return;
}

So it'll look like this

object oItem = GetItemActivated();
if (GetTag(oItem) == "SRBwand")
{

       // get the wand's activator and target, put target info into local vars on activator
      object oPC = GetItemActivator();
      object oMyTarget = GetItemActivatedTarget();
      SetLocalObject(oPC, "BPWandTarget", oMyTarget);
      location lTargetLoc = GetItemActivatedTargetLocation();
      SetLocalLocation(oPC, "BPWandLoc", lTargetLoc);

      //Make the activator start a conversation with itself
      AssignCommand(oPC, ActionStartConversation(oPC, "everything", TRUE));
      return;
}

Thanks alot guys. Sorry for bothering you with such a simple thing... I'm still new into scripting hahaha.