Author Topic: JumpToLocation stored on player item?  (Read 349 times)

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
JumpToLocation stored on player item?
« on: February 26, 2011, 04:23:31 am »


               I'm trying to store a players location on an item in their inventory and using a unique power to teleport back to that stored location. Here are my two scripts. My guess is that it's not working because the stored location is a float, but I'm not sure. I know the unique power triggers the speakstring so I know that's working. Any help or info would be great.

The Soulbinder, binding the player (or setting the HOME variable on the players item.

void main()
{
object oPC = GetPCSpeaker();
object oItem = GetItemPossessedBy(oPC,"solusekseye");
SetLocalLocation(oItem, "HOME", GetLocation(oPC));
AssignCommand(oPC, ClearAllActions());
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_UNSUMMON), GetLocation(oPC));
SendMessageToPC(oPC, "You feel yourself bind to the area.");
}


And the UniquePower that should send them back to the stored location of HOME.

void main()
{
object oPC;
object oItem = GetItemPossessedBy(oPC,"solusekseye");
string HOME = GetLocalString(oItem,"HOME");
if (!GetIsPC(GetItemActivatedTarget()) || GetIsInCombat(GetItemActivator()))
    {
        SendMessageToPC(GetItemActivator(), "You can not cast that now!");
        return;
    }
oPC = GetItemActivator();
SendMessageToPC(oPC, "You begin casting Gate.");
AssignCommand(oPC, ClearAllActions());
DelayCommand(3.0, AssignCommand(oPC, ActionJumpToLocation(HOME))); // Issue seams to be here.
}

               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
JumpToLocation stored on player item?
« Reply #1 on: February 26, 2011, 04:38:16 am »


               Why not just spawn in a waypoint where the PC was when they jump (tag it uniquely when spawned and save that tag as a string on the PCs item if its a MP module), then jump them back to the waypoint's location and destroy the waypoint when they get there?
               
               

               


                     Modifié par _Knightmare_, 26 février 2011 - 04:39 .
                     
                  


            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
JumpToLocation stored on player item?
« Reply #2 on: February 26, 2011, 04:47:38 am »


               

_Knightmare_ wrote...

Why not just spawn in a waypoint where the PC was when they jump (tag it uniquely when spawned and save that tag as a string on the PCs item if its a MP module), then jump them back to the waypoint's location and destroy the waypoint when they get there?


It's a persistant world and want to make sure the data sticks around if they log for a while. Also, this same script will be used to "bind" themselves anywhere in the module.
               
               

               
            

Legacy_Zejan the Wonder Monkey

  • Jr. Member
  • **
  • Posts: 61
  • Karma: +0/-0
JumpToLocation stored on player item?
« Reply #3 on: February 26, 2011, 05:28:46 am »


               

Buddywarrior wrote...

I'm trying to store a players location on an item in their inventory and using a unique power to teleport back to that stored location. Here are my two scripts. My guess is that it's not working because the stored location is a float, but I'm not sure. I know the unique power triggers the speakstring so I know that's working. Any help or info would be great.


Hmm...

I think the trouble is in your choice of 'Get' function.  Since you're creating the variable "HOME" and storing the location of the player in it, you should then get the location stored in the variable.  So in the second piece of code, it should probably look like this (my changes in bold italic just to make it stand out):

void main()
{
object oPC;
object oItem = GetItemPossessedBy(oPC,"solusekseye");
location lHome  = GetLocalLocation(oItem,"HOME");
if (!GetIsPC(GetItemActivatedTarget()) || GetIsInCombat(GetItemActivator()))
    {
        SendMessageToPC(GetItemActivator(), "You can not cast that now!");
        return;
    }
oPC = GetItemActivator();
SendMessageToPC(oPC, "You begin casting Gate.");
AssignCommand(oPC, ClearAllActions());
DelayCommand(3.0, AssignCommand(oPC, ActionJumpToLocation(lHome)));
}


According to the Lexicon, SetLocalLocation/GetLocalLocation have to be used in tandem.  This is because a location actually contains three components, as opposed to a single for float or int.  Hope that helps.
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
JumpToLocation stored on player item?
« Reply #4 on: February 26, 2011, 12:18:06 pm »


               If Zejan's changes don't work for you let us know. I'll write up a script that uses the waypoints as I suggested. Should work for MP/PW just as well as for SP. You just need to tag the waypoint uniquely when spawned, simple to do.
               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
JumpToLocation stored on player item?
« Reply #5 on: February 26, 2011, 05:50:09 pm »


               

_Knightmare_ wrote...

If Zejan's changes don't work for you let us know. I'll write up a script that uses the waypoints as I suggested. Should work for MP/PW just as well as for SP. You just need to tag the waypoint uniquely when spawned, simple to do.

I'll be happy to take a look at how you solve this problem Knightmare.
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
JumpToLocation stored on player item?
« Reply #6 on: February 26, 2011, 09:59:13 pm »


               

Buddywarrior wrote...

_Knightmare_ wrote...

If Zejan's changes don't work for you let us know. I'll write up a script that uses the waypoints as I suggested. Should work for MP/PW just as well as for SP. You just need to tag the waypoint uniquely when spawned, simple to do.

I'll be happy to take a look at how you solve this problem Knightmare.


Here you go. Just threw it together, does compile fine but untested in game. Comments within script should tell you what's going on. Let me know how things turn out:

void main()
{
object oPC = GetItemActivator();
object oItem = GetItemPossessedBy(oPC,"solusekseye");

// If item activator is not a PC or is in combat, send message and end script
if (!GetIsPC(GetItemActivatedTarget()) || GetIsInCombat(GetItemActivator()))
    {
    SendMessageToPC(GetItemActivator(), "You can not cast that now!");
    return;
    }

// Check to see if we have a location set already (int "Bind" == 1)
if(GetLocalInt(oItem, "Bind") == 1)
    {
    // Find the dynamically tagged WP and jump to it
    object oWP = GetObjectByTag(GetFirstName(oPC) + GetLastName(oPC) + GetLocalString(oItem, "RandNum"));
    location lLocWP = GetLocation(oWP);
    AssignCommand(oPC, ClearAllActions());
    DelayCommand(3.0, AssignCommand(oPC, ActionJumpToLocation(lLocWP)));
    DestroyObject(oWP, 60.0); // Destroy the WP after 60 seconds to allow for loading times
    }

// No location set yet, so create one, then jump player somewhere else 
if(GetLocalInt(oItem, "Bind") != 1)
    {
    location lLocPC = GetLocation(oPC);
    int nRand = d100();

    // Save the Random number result so the "if condition" above can find it
    object oItem = GetItemPossessedBy(oPC,"solusekseye");
    SetLocalString(oItem, "RandNum", IntToString(nRand));

    // Spawn in a waypoint at PC's location
    // Dynamically tag the WP with PC's First Name + PC's Last Name + a Random Number
    object oWP = CreateObject(OBJECT_TYPE_WAYPOINT, "nw_waypoint001", lLocPC, FALSE, GetFirstName(oPC) + GetLastName(oPC) + IntToString(nRand));
    }
}

Should work for MP/PW play, unless 2 player happen to have the exact same First and Last name PLUS happen to roll the exact same random number.
               
               

               


                     Modifié par _Knightmare_, 26 février 2011 - 10:04 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
JumpToLocation stored on player item?
« Reply #7 on: February 26, 2011, 10:44:14 pm »


               I am having a hard time seeing the benifit of  dropping a WayPoint to jump to.  

First without code to store and recreate the WayPoints I do not see them  lasting over a server reset. 

Two without the waypoints not being there over resets you can end up with an item that is bound with no valid point. 

The Idea of useing the PC information for the waypoint tag will also cause problems if the item is ever tradded between players, I do not know if the OP want to allow this, but if he did the item would only work for the PC who did the binding. 

Also there is no reason to search the PC's inventory for the item activated with 
  object oItem = GetItemPossessedBy(oPC,"solusekseye"); 
Beyond the fact that the search only wasts cpu time. The only way to garrentee that it returns the right item is if the PC only has one item with that tag.  It would be better to just use: 
object  oItem = GetItemActivated();
It will return the correct item used without having to loop through the PC's inventory to maybe find the right item.

Even if the WayPoints where stored and recreated to be persistant over resets. I do not see the point in having make the script serarh through all the waypoints in the module to find the location to jump the PC to, when the location can just be stored on the item.  

Is there an advantage here that I am missing?
               
               

               
            

Legacy_Zejan the Wonder Monkey

  • Jr. Member
  • **
  • Posts: 61
  • Karma: +0/-0
JumpToLocation stored on player item?
« Reply #8 on: February 26, 2011, 11:53:47 pm »


               

Lightfoot8 wrote...

I am having a hard time seeing the benifit of  dropping a WayPoint to jump to.  

First without code to store and recreate the WayPoints I do not see them  lasting over a server reset. 

Two without the waypoints not being there over resets you can end up with an item that is bound with no valid point. 

The Idea of useing the PC information for the waypoint tag will also cause problems if the item is ever tradded between players, I do not know if the OP want to allow this, but if he did the item would only work for the PC who did the binding. 

Also there is no reason to search the PC's inventory for the item activated with 
  object oItem = GetItemPossessedBy(oPC,"solusekseye"); 
Beyond the fact that the search only wasts cpu time. The only way to garrentee that it returns the right item is if the PC only has one item with that tag.  It would be better to just use: 
object  oItem = GetItemActivated();
It will return the correct item used without having to loop through the PC's inventory to maybe find the right item.

Even if the WayPoints where stored and recreated to be persistant over resets. I do not see the point in having make the script serarh through all the waypoints in the module to find the location to jump the PC to, when the location can just be stored on the item.  

Is there an advantage here that I am missing?


Aha...

So you're saying it should actually look like this:

void main()
{
object oPC;
object  oItem = GetItemActivated();
location lHome  = GetLocalLocation(oItem,"HOME");
if (!GetIsPC(GetItemActivatedTarget()) || GetIsInCombat(GetItemActivator()))
    {
        SendMessageToPC(GetItemActivator(), "You can not cast that now!");
        return;
    }
oPC = GetItemActivator();
SendMessageToPC(oPC, "You begin casting Gate.");
AssignCommand(oPC, ClearAllActions());
DelayCommand(3.0, AssignCommand(oPC, ActionJumpToLocation(lHome)));
}
               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
JumpToLocation stored on player item?
« Reply #9 on: February 27, 2011, 02:31:20 am »


               I got it working like it needs to be now. Thank you all for the help. '<img'>
               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
JumpToLocation stored on player item?
« Reply #10 on: February 27, 2011, 02:34:05 am »


               

_Knightmare_ wrote...
    // Spawn in a waypoint at PC's location
    // Dynamically tag the WP with PC's First Name + PC's Last Name + a Random Number
    object oWP = CreateObject(OBJECT_TYPE_WAYPOINT, "nw_waypoint001", lLocPC, FALSE, GetFirstName(oPC) + GetLastName(oPC) + IntToString(nRand));


I had no idea you could spawn in a waypoint. That is great to know. Thanks Knightmare!
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
JumpToLocation stored on player item?
« Reply #11 on: February 27, 2011, 04:35:31 am »


               Just keep in mind also Buddywarrior, that if you make any changes to the areas of your module, the area ID will change. If players have stored locations from one of these areas, the locations will no longer be valid. This is why it is a good idea to use the GetAreaFromLocation check first to make sure the area you are porting to is a valid area. Otherwise the player could end up in some place they are not supposed.....like in a locked area of your bank....not that this happened on our PW. ':whistle:'
               
               

               


                     Modifié par GhostOfGod, 27 février 2011 - 04:36 .