Author Topic: Need help with this tag-based script  (Read 328 times)

Legacy_StefanoD

  • Newbie
  • *
  • Posts: 39
  • Karma: +0/-0
Need help with this tag-based script
« on: July 11, 2015, 12:18:27 am »


               

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.



               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Need help with this tag-based script
« Reply #1 on: July 11, 2015, 12:49:20 am »


               

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



               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Need help with this tag-based script
« Reply #2 on: July 11, 2015, 01:16:05 am »


               

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


               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Need help with this tag-based script
« Reply #3 on: July 11, 2015, 09:57:56 am »


               

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.



               
               

               
            

Legacy_StefanoD

  • Newbie
  • *
  • Posts: 39
  • Karma: +0/-0
Need help with this tag-based script
« Reply #4 on: July 11, 2015, 07:42:12 pm »


               

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.