Author Topic: Problem with script or known issue?  (Read 536 times)

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Problem with script or known issue?
« on: August 05, 2010, 05:54:58 am »


               I've run into a bit of an issue with my script here. When i create an object and then give it a new tag that is the players public cd key, then try to find and destroy that object later by gettings its tag, it doesn't seem to find the object. Is there some issue with using the pc public cd key as a string for a tag? It's only 8 characters long and it says it's a string. ~scratches head~

Heres the script:

#include "x2_inc_switches"
void main()
{

int nEvent =GetUserDefinedItemEventNumber();
if(nEvent !=  X2_ITEM_EVENT_ACTIVATE)return;

object oPC = GetItemActivator();
object oItem = GetItemActivated();
string sName = GetName(oPC);
string sCDKey = GetPCPublicCDKey(oPC);
float fFace = GetFacing(oPC);
location lLoc = GetLocation(oPC);
string sNameEnd = GetStringRight(sName, 1);
int iState = GetLocalInt(oPC, "STORE_STATE");

if (iState == 0)
    {
    object oCrate = CreateObject(OBJECT_TYPE_PLACEABLE, "plc_box2", lLoc, FALSE, sCDKey);
    AssignCommand(oCrate, SetFacing(fFace));
    SetPlotFlag(oCrate, TRUE);
    SetLocalString(oCrate, "PLAYER_CD_KEY", sCDKey);
    if (sNameEnd == "s" || sNameEnd == "S") SetName(oCrate, sName + "' Store.");
    else SetName(oCrate, sName + "'s Store.");
    SetLocalInt(oPC, "STORE_STATE", 1);
    }
else
    {
    DestroyObject(GetNearestObjectByTag(sCDKey, oPC, 1));
    SetLocalInt(oPC, "STORE_STATE", 0);
    }
}

If I replace the tags, where i create the object and destroy the object with sName, everything works just fine.

Any help very much appreciated. Thanks in Advance.
               
               

               
            

Legacy_420

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Problem with script or known issue?
« Reply #1 on: August 05, 2010, 06:39:26 am »


               Not sure why it works with the PC's name as the tag and not the CD key. But I think it would be easier to just store the crate as a local object on the PC. That way it works even if the PC isn't in the same area as the crate.

Try this:


#include "x2_inc_switches"
void main()
{

int nEvent =GetUserDefinedItemEventNumber();
if(nEvent !=  X2_ITEM_EVENT_ACTIVATE)return;

object oPC = GetItemActivator();
object oItem = GetItemActivated();
string sName = GetName(oPC);
string sCDKey = GetPCPublicCDKey(oPC);
float fFace = GetFacing(oPC);
location lLoc = GetLocation(oPC);
string sNameEnd = GetStringRight(sName, 1);
int iState = GetLocalInt(oPC, "STORE_STATE");

if (iState == 0)
    {
    object oCrate = CreateObject(OBJECT_TYPE_PLACEABLE, "plc_box2", lLoc, FALSE, sCDKey);
    SetLocalObject(oPC, "Crate", oCrate); //Make the crate personal
    AssignCommand(oCrate, SetFacing(fFace));
    SetPlotFlag(oCrate, TRUE);
    SetLocalString(oCrate, "PLAYER_CD_KEY", sCDKey);
    if (sNameEnd == "s" || sNameEnd == "S") SetName(oCrate, sName + "'s Store.");
    else SetName(oCrate, sName + "'s Store.");
    SetLocalInt(oPC, "STORE_STATE", 1);
    }
else
    {
    DestroyObject(GetLocalObject(oPC, "Crate")); //Destroy personal crate
    SetLocalInt(oPC, "STORE_STATE", 0);
    }
}

-420
               
               

               


                     Modifié par 420, 05 août 2010 - 05:47 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Problem with script or known issue?
« Reply #2 on: August 05, 2010, 07:08:12 am »


               Hmm. So it's not just me then. I was mainly just wondering why using the cd key as a tag didn't work. But I definitely like the idea of storing the crate as an object if I go that route. This is in the super early "thinking out loud" stages.



Thanks 420.



And if anyone else has any info on the pc public cd key being used as a string issue I sure would like to know what's up with that.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Problem with script or known issue?
« Reply #3 on: August 05, 2010, 09:24:43 am »


               Don't you test it in singleplayer? In that case GetPCPublicCDKey(oPC); returns empty string you have to use ,TRUE argument to return non-empty string in SP as well.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Problem with script or known issue?
« Reply #4 on: August 05, 2010, 09:53:01 am »


               Oh duh. haha. Thanks Shadow.