Author Topic: need help altering a script...  (Read 402 times)

Legacy_zero-feeling

  • Sr. Member
  • ****
  • Posts: 287
  • Karma: +0/-0
need help altering a script...
« on: February 19, 2011, 10:48:54 pm »


               so i have this script here thats supposed to save a players location when used, then when used a second time, return the player to the location he was when he first used it. the script works fine how it is for a single player mod, but not a multi-player mod, so i need help making it so it is, here's the script:

#include "x2_inc_switches"
void main()
{
int nEvent =GetUserDefinedItemEventNumber();
if(nEvent !=  X2_ITEM_EVENT_ACTIVATE)return;
object oPC = GetItemActivator();
object oStone = GetItemPossessedBy(oPC, "whitestone");//Put your item tag here.
location lPCLocation = GetLocation(oPC);
location lStoredLocation = GetLocalLocation(oStone, "STORED_LOCATION");
if (!GetIsObjectValid(GetAreaFromLocation(lStoredLocation)))
    {
    SetLocalLocation(oStone, "STORED_LOCATION", lPCLocation);
    SendMessageToPC(oPC, "Your location has been saved.");
    return;
    }
if (GetIsObjectValid(GetAreaFromLocation(lStoredLocation)))
    {
    AssignCommand(oPC, ActionJumpToLocation(lStoredLocation));
    DestroyObject(oStone, 1.0);
    SendMessageToPC(oPC, "You have been teleported to your saved location and your stone has been destroyed.");
    }
}

thanks in advance

zero
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
need help altering a script...
« Reply #1 on: February 19, 2011, 11:52:26 pm »


               i see no reason it would work in Single player but not work in Multi player.  Either way the script does have one major bug.  If the PC has more then one of the items in there possesion the

object oStone = GetItemPossessedBy(oPC, "whitestone");

line may not be  returning the same item that was used.  

You would be better off Identifing the item with:
 
object oStone = GetItemActivated();

This will garentee that the item used is the same one you are storing your location on.  This should be fixed in both the single and multi player Modules.
               
               

               
            

Legacy_zero-feeling

  • Sr. Member
  • ****
  • Posts: 287
  • Karma: +0/-0
need help altering a script...
« Reply #2 on: February 20, 2011, 12:08:57 am »


               great, i will give this a try
               
               

               
            

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
need help altering a script...
« Reply #3 on: February 20, 2011, 12:14:51 am »


               // zero_loc_itm
#include "x2_inc_switches"
void main()
{
int nEvent =GetUserDefinedItemEventNumber();
if(nEvent !=  X2_ITEM_EVENT_ACTIVATE){return;}

object oPC = GetItemActivator();
location lPCLocation = GetLocation(oPC);

//object oStone = GetItemPossessedBy(oPC, "whitestone");//Put your item tag here.
object oStone = GetItemActivated();
location lStoredLocation = GetLocalLocation(oStone, "STORED_LOCATION");

if (!GetIsObjectValid(GetAreaFromLocation(lStoredLocation)))
   {
   SetLocalLocation(oStone, "STORED_LOCATION", lPCLocation);
   SendMessageToPC(oPC, "Your location has been saved.");
   return;
   }
if (GetIsObjectValid(GetAreaFromLocation(lStoredLocation)))
   {
   AssignCommand(oPC, ActionJumpToLocation(lStoredLocation));
   DestroyObject(oStone, 1.0);
   SendMessageToPC(oPC, "You have been teleported to your saved location and your stone has been destroyed.");
   }
}

so this is what Lightfoot8 is suggesting.  Oh and if you want to insure the item being used is your "whitestone" use
if( GetTag(oStone)==""whitestone")
{
// then script here
}
               
               

               


                     Modifié par Greyfort, 20 février 2011 - 12:17 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
need help altering a script...
« Reply #4 on: February 20, 2011, 12:56:13 am »


               @GrayFort.
There is no reason to check the tag.  The Tag has already been checked by running the script in the first place.  Since this is TagBased Scripting the Tag of the Item is matching the name of the script.   All the Tag check will do in this script is make it harder to add the Script to another item if he ever tries to do that.  The script would them have to be modified.    The Script name and the Tag Check in the code would always have to match.  Much simpler to just let the name of the script verify the tag of the object.
               
               

               


                     Modifié par Lightfoot8, 20 février 2011 - 12:56 .
                     
                  


            

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
need help altering a script...
« Reply #5 on: February 20, 2011, 01:03:25 am »


               I didn't even notice that, I was remebering from a old on activate item script that zero had sent me to look at, and he did not used tag based scripting. Forgive me Lightfoot/Zero my eyes are a bit foggy, been trying to figure out my mistake with item props.