Author Topic: String to object?  (Read 530 times)

Legacy_Ryuhi2000

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
String to object?
« on: April 05, 2011, 11:11:34 pm »


               anyone have a StringToObject function?
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
String to object?
« Reply #1 on: April 05, 2011, 11:58:41 pm »


               Hmm..well there is the ObjectToString function which gives a hexidecimal string from an object already in exhistance. And this string is absolutely unique. No other object will have the same one which is useful for debugging or what not. You probably already know of this function.
But doing it in reverse wouldn't make much sense since an item only has this string once it is created. Did you want to assign a specific hexidecimal string to an object?
If you are just trying to creat items from strings then you would just use res refs and the functions: CreateItemOnObject, CreateObject.
Perhaps a bit more info about what you want to accomplish would help out?
               
               

               
            

Legacy_Ryuhi2000

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
String to object?
« Reply #2 on: April 06, 2011, 12:43:44 am »


               i need to take a location stored as a string in a database and assign it to be an object that my script will then use to teleport to. because the script is still kinda long ill save time by saying the problems im reciving for compiling  in the Destination function literaly its 3 lines that get the mismatch error but the other 3 lines are commented out because script editor was giving some other error when i went to save with the 3 mismatch error lines commented out

 the script is as clean as it could get while still doing what i want it to while i still understand whats going on in it
Below you can find the script but it wont compile if i uncomment the real lines of code with // in front of them since those lines are getting mismatched type error.

#include "nw_i0_plot"

//start of no xp loss and no gp loss function
void ApplyPenalty(object oPC)
{

//start variables (by default all are 0)
int nXP = GetXP(oPC) - 0;//set the 0 to the amount xp you want to take
int nGP = 0;//set the 0 to the amount gold you want to take

SetLocalInt(GetModule(), "gp_penalty_on", 0);//set to 1 if you are going to take a penalty for gold else leave 0
SetLocalInt(GetModule(), "xp_penalty_on", 0);//set to 1 if you are going to take a penalty for xp else leave 0
//end variables

SetXP(oPC, nXP);
AssignCommand(oPC, TakeGoldFromCreature(nGP, oPC, TRUE));

//the script will do this if gold penalty and xp penalty are turned off
if (GetLocalInt(GetModule(), "gp_penalty_on")== 0 && GetLocalInt(GetModule(), "xp_penalty_on")== 0)
{FloatingTextStringOnCreature("You have respawned without gold loss and without experience loss", oPC, FALSE);}

//the script will do this if gold penalty is turned on and xp penalty is turned off
else if(GetLocalInt(GetModule(), "gp_penalty_on")== 1 && GetLocalInt(GetModule(), "xp_penalty_on")== 0)
{FloatingTextStringOnCreature("You have respawned with gold loss", oPC, FALSE);}

//the script will do this if xp penalty is turned on and gold penalty is turned off
else if(GetLocalInt(GetModule(), "xp_penalty_on")== 1 && GetLocalInt(GetModule(), "gp_penalty_on")== 0)
{FloatingTextStringOnCreature("You have respawned with experience loss", oPC, FALSE);}

//the script will do this if xp penalty is turned on and gold penalty is turned on
else if(GetLocalInt(GetModule(), "xp_penalty_on")== 1 && GetLocalInt(GetModule(), "gp_penalty_on")== 1)
{FloatingTextStringOnCreature("You have respawned with experience and gold loss", oPC, FALSE);}

}
//end of no xp loss and no gp loss function

//start how much hp to restore of respawn function
void Rez(object oPC)
{

ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectResurrection(),oPC);

RemoveEffects(oPC);

//start of soul stone code that can be removed
do//while the player has the soul stone item
{

ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(GetMaxHitPoints(oPC)), oPC);

DestroyObject(GetItemPossessedBy(oPC, "soulstoneitem"));

} while (GetItemPossessedBy(oPC, "soulstoneitem") != OBJECT_INVALID);
//end of soul stone code that can be removed

do//while the player does not have the soul stone item
{ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(GetCurrentHitPoints(oPC) + 1), oPC);}
while (GetItemPossessedBy(oPC, "soulstoneitem") == OBJECT_INVALID);

}//end how much hp to restore on respawn function

//start function that determines where the player respawns
void Destination(object oPC)
{

int hasrezshrine;//variable that can not be erased or script will break
object oPC;
object oTarget;

switch (GetLocalInt(GetArea(oPC), "hasrezshrine"))
{

//start case 0 (if the area DOES NOT have a rez shrine)
case 0:

//if there is a set bindpoint on the player rez at it
if(GetCampaignString("bindpointdatabase", "sBindPoint", oPC) != "")
//{oTarget = GetCampaignString("bindpointdatabase", "sBindPoint", oPC);}
//end if there is a set bindpoint on the player

//if there IS NOT a set bindpoint on the player
if (GetCampaignString("bindpointdatabase", "sBindPoint", oPC) == "")
{
//if there is a module default respawn point rez at it
if (GetIsObjectValid(GetWaypointByTag("NW_DEATH_TEMPLE")) == TRUE)
{oTarget = GetWaypointByTag("NW_DEATH_TEMPLE");}
//end if there is a module default respawn point

//if there IS NOT a module default respawn point rez where you are
//if (GetIsObjectValid(GetWaypointByTag("NW_DEATH_TEMPLE")) == FALSE)
//{oTarget = GetLocation(oPC);}
//end if there IS NOT a module default respawn point

}//end if there IS NOT a set bindpoint on the player

break;//end case 0 (if the area DOES NOT have a rez shrine)

//start case 1 (if the area DOES have a rez shrine)
case 1:

//if the player found a rez shrine
if (GetLocalInt(oPC, "foundrezshrine") == 1)
{oTarget = GetNearestObjectByTag("rezshrine");}
//end if the player found a rez shrine

//if the player DID NOT find rez shrine
if (GetLocalInt(oPC, "foundrezshrine") == 0)
{

//if there is a set bindpoint on the player rez at it
//if(GetCampaignString("bindpointdatabase", "sBindPoint", oPC) != "")
//{oTarget = GetCampaignString("bindpointdatabase", "sBindPoint", oPC);}
//end if there is a set bindpoint on the player

//if there IS NOT a set bindpoint on the player
if (GetCampaignString("bindpointdatabase", "sBindPoint", oPC) == "")
{
//if there is a module default respawn point rez at it
if (GetIsObjectValid(GetWaypointByTag("NW_DEATH_TEMPLE")) == TRUE)
{oTarget = GetWaypointByTag("NW_DEATH_TEMPLE");}
//end if there is a module default respawn point

//if there IS NOT a module default respawn point rez where you are
//if (GetIsObjectValid(GetWaypointByTag("NW_DEATH_TEMPLE")) == FALSE)
//{oTarget = GetLocation(oPC);}
//end if there IS NOT a module default respawn point

}//end if there IS NOT a set bindpoint on the player

}//end if the player DID NOT find rez shrine

break;//end case 1 (if the area DOES have a rez shrine)

}//end switch

}//end function that determines where the player respawns

void main()
{

object oPC = GetLastRespawnButtonPresser();
object oTarget;//the respawn point the script will pick
location lTarget;

Destination(oPC);//sets the respawn point to use

Rez(oPC);//rez and heals the player

//sets the respawn point chosen by the script as the destination to send the player to
lTarget = GetLocation(oTarget);

AssignCommand(oPC, ClearAllActions());

AssignCommand(oPC, ActionJumpToLocation(lTarget));

ApplyPenalty(oPC);//by bioware default it should remove gold and xp but i changed that

}
               
               

               


                     Modifié par Ryuhi2000, 05 avril 2011 - 11:55 .
                     
                  


            

Legacy_Ryuhi2000

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
String to object?
« Reply #3 on: April 06, 2011, 01:01:28 am »


               the three mismatch lines are below and yes i know the one line is there twice it has to be since the code is mirrored everything from the else if the player has not found the rez shrine has to happen if the switch is run under case 0

//{oTarget = GetCampaignString("bindpointdatabase", "sBindPoint", oPC);}

//{oTarget = GetLocation(oPC);}

//{oTarget = GetCampaignString("bindpointdatabase", "sBindPoint", oPC);}
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
String to object?
« Reply #4 on: April 06, 2011, 01:07:44 am »


               You could just change this line:

oTarget = GetCampaignString("bindpointdatabase", "sBindPoint", oPC);

To this:

oTarget = GetWaypointByTag(GetCampaignString("bindpointdatabase", "sBindPoint", oPC));

Hope it helps.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
String to object?
« Reply #5 on: April 06, 2011, 01:09:19 am »


               

Ryuhi2000 wrote...

the three mismatch lines are below and yes i know the one line is there twice it has to be since the code is mirrored everything from the else if the player has not found the rez shrine has to happen if the switch is run under case 0

//{oTarget = GetCampaignString("bindpointdatabase", "sBindPoint", oPC);}

//{oTarget = GetLocation(oPC);}

//{oTarget = GetCampaignString("bindpointdatabase", "sBindPoint", oPC);}


For all 3 of these lines you are telling an object to be either a string or a location. oTarget has to be an object. This is why you are getting the mismatched type.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
String to object?
« Reply #6 on: April 06, 2011, 01:21:01 am »


               Your Rez function could also be further condensed to something more like so:

void Rez(object oPC)
{
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectResurrection(),oPC);
RemoveEffects(oPC);

//start of soul stone code that can be removed
if (GetItemPossessedBy(oPC, "soulstoneitem") != OBJECT_INVALID)
    {
    ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(GetMaxHitPoints(oPC)), oPC);
    DestroyObject(GetItemPossessedBy(oPC, "soulstoneitem"));
    }
else
    {
    ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(GetCurrentHitPoints(oPC) + 1), oPC);
    }
}//end how much hp to restore on respawn function


No need to do any "do while" loops if you aren't looping through anything.

And since the Resurrection effect already heals the player to 1 hp you don't even need that "else" which adds another hit point..unless the desire is for the player to have 2 hps. So you could further condense it like so:

void Rez(object oPC)
{
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectResurrection(),oPC);
RemoveEffects(oPC);

//start of soul stone code that can be removed
if (GetItemPossessedBy(oPC, "soulstoneitem") != OBJECT_INVALID)
    {
    ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(GetMaxHitPoints(oPC)), oPC);
    DestroyObject(GetItemPossessedBy(oPC, "soulstoneitem"));
    }
}//end how much hp to restore on respawn function


               
               

               


                     Modifié par GhostOfGod, 06 avril 2011 - 12:27 .
                     
                  


            

Legacy_Ryuhi2000

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
String to object?
« Reply #7 on: April 06, 2011, 01:34:30 am »


               nice i didnt relize resurrection healed to a positive 1 hp i thought it just brought them to 0 hp and exellent point gog that was something i missed sometime it takes more then a pairs eyes to spot something like that speciaily when that pair pair constantly has the script editor open.......

and i had looping just because the old version of it on nwvault had a cluster EFF of ifs so i tried to avoid if everywhere i could in the script lol but yeah i only need it to run once not loop
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
String to object?
« Reply #8 on: April 06, 2011, 01:52:08 am »


               Also if you don't mind me making a suggestion...Since your destination function isn't returning an object or a location it won't correctly work the way you have it. But you can just have it do the work of jumping to an object. So you could condense it quite a bit as well. So with a change to that plus the other changes your whole script might look like so:


#include "nw_i0_plot"

//start of no xp loss and no gp loss function
void ApplyPenalty(object oPC)
{

//start variables (by default all are 0)
int nXP = GetXP(oPC) - 0;//set the 0 to the amount xp you want to take
int nGP = 0;//set the 0 to the amount gold you want to take

SetLocalInt(GetModule(), "gp_penalty_on", 0);//set to 1 if you are going to take a penalty for gold else leave 0
SetLocalInt(GetModule(), "xp_penalty_on", 0);//set to 1 if you are going to take a penalty for xp else leave 0
//end variables

SetXP(oPC, nXP);
AssignCommand(oPC, TakeGoldFromCreature(nGP, oPC, TRUE));

//the script will do this if gold penalty and xp penalty are turned off
if (GetLocalInt(GetModule(), "gp_penalty_on")== 0 && GetLocalInt(GetModule(), "xp_penalty_on")== 0)
{FloatingTextStringOnCreature("You have respawned without gold loss and without experience loss", oPC, FALSE);}

//the script will do this if gold penalty is turned on and xp penalty is turned off
else if(GetLocalInt(GetModule(), "gp_penalty_on")== 1 && GetLocalInt(GetModule(), "xp_penalty_on")== 0)
{FloatingTextStringOnCreature("You have respawned with gold loss", oPC, FALSE);}

//the script will do this if xp penalty is turned on and gold penalty is turned off
else if(GetLocalInt(GetModule(), "xp_penalty_on")== 1 && GetLocalInt(GetModule(), "gp_penalty_on")== 0)
{FloatingTextStringOnCreature("You have respawned with experience loss", oPC, FALSE);}

//the script will do this if xp penalty is turned on and gold penalty is turned on
else if(GetLocalInt(GetModule(), "xp_penalty_on")== 1 && GetLocalInt(GetModule(), "gp_penalty_on")== 1)
{FloatingTextStringOnCreature("You have respawned with experience and gold loss", oPC, FALSE);}

}
//end of no xp loss and no gp loss function

//start how much hp to restore of respawn function
void Rez(object oPC)
{
    ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectResurrection(),oPC);
    RemoveEffects(oPC);

    //start of soul stone code that can be removed
    if (GetItemPossessedBy(oPC, "soulstoneitem") != OBJECT_INVALID)
    {
        ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(GetMaxHitPoints(oPC)), oPC);
        DestroyObject(GetItemPossessedBy(oPC, "soulstoneitem"));
    }
}//end how much hp to restore on respawn function

//start function that determines where the player respawns
void Destination(object oPC)
{
    object oArea = GetArea(oPC);
    int iShrineCheck = GetLocalInt(oArea, "hasrezshrine");
    object oTarget;

    //if there is a set bindpoint on the player teleport to it
    if  (GetCampaignString("bindpointdatabase", "sBindPoint", oPC) != "")
    {
        oTarget = GetWaypointByTag(GetCampaignString("bindpointdatabase", "sBindPoint", oPC));
        AssignCommand(oPC, ActionJumpToObject(oTarget));
    }
    //else if there is a shrine in the area teleport to it
    else if (iShrineCheck == 1)
    {
        oTarget = GetNearestObjectByTag("rezshrine", oPC, 1);
        AssignCommand(oPC, ActionJumpToObject(oTarget));
    }
    //else if there is a valid death temple WP then teleport to it
    else if (GetIsObjectValid(GetWaypointByTag("NW_DEATH_TEMPLE")) == TRUE)
    {
        oTarget = GetWaypointByTag("NW_DEATH_TEMPLE");
        AssignCommand(oPC, ActionJumpToObject(oTarget));
    }
}//end function that determines where the player respawns

void main()
{
    object oPC = GetLastRespawnButtonPresser();

    Rez(oPC);//rez and heals the player
    ApplyPenalty(oPC);//by bioware default it should remove gold and xp but i changed that
    Destination(oPC);//player respawns at appropriate waypoint
}


I haven't tested this or anything but just figured I'd point out how you can streamline it a bit.
               
               

               


                     Modifié par GhostOfGod, 06 avril 2011 - 12:53 .
                     
                  


            

Legacy_Ryuhi2000

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
String to object?
« Reply #9 on: April 06, 2011, 02:34:54 am »


               looks bit better then what i had gog but i need to leave the option for the player to rez where they are if there is no NW_DEATH_TEMPLE since i planned on making the thing completely modular so people can customize easily if they wish to remove the any of the destinations i made. entire system is modular....  and customizable
               
               

               


                     Modifié par Ryuhi2000, 06 avril 2011 - 01:36 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
String to object?
« Reply #10 on: April 06, 2011, 03:31:39 am »


               That's how it works. If there is not bindpoint, no shrinepoint, or no Deathtemple waypoint then they won't go anywhere.
               
               

               
            

Legacy_Ryuhi2000

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
String to object?
« Reply #11 on: April 06, 2011, 05:20:43 am »


               ah ok i though i had to code that in that it wouldnt be there by default shame on me for misreading that code and that code gave me a good idea on how i could reduce more lines from what i had
               
               

               
            

Legacy_Werehound

  • Newbie
  • *
  • Posts: 22
  • Karma: +0/-0
String to object?
« Reply #12 on: May 04, 2011, 06:35:55 pm »


               In the end, NWNx2 and nwnx_funcs has a StringToObject function for both Windows and linux.