Aller au contenu

Photo

need help altering a script...


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

#1
zero-feeling

zero-feeling
  • Members
  • 144 messages
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

#2
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
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.

#3
zero-feeling

zero-feeling
  • Members
  • 144 messages
great, i will give this a try

#4
Greyfort

Greyfort
  • Members
  • 234 messages
// 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 .


#5
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
@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 .


#6
Greyfort

Greyfort
  • Members
  • 234 messages
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.