Skip to content

I think I messed up a script using the "DoOnce" command.

I'm trying to give the PC a Recall Stone & some gold the first time they log into the persistent world. The first time they log in, it will be in a starting area. Then, every time after their first log-in into the PW, they don't get the Recall Stone & gold again. This is what I have so far - I thought the DoOnce command would solve this issue, but I was wrong.

// ** Gives a Stone of Recall to player on entering this area
//Put this script OnEnter
//** #include "nw_i0_tool" is for giving gold to player on enter of starting area.
#include "nw_i0_tool"
void main()
{

object oPC = GetEnteringObject();

if (!GetIsPC(oPC)) return;

int DoOnce = GetLocalInt(oPC, GetTag(OBJECT_SELF));

if (DoOnce==TRUE) return;

SetLocalInt(oPC, GetTag(OBJECT_SELF), TRUE);

CreateItemOnObject("nw_it_recall", oPC);
RewardPartyGP(50, oPC, TRUE);

}

Comments

  • TerrorbleTerrorble Member Posts: 169
    Variables set on the PC object do not carry across server resets.

    Variables set on objects in a PC's inventory do carry over. You can give your player an undroppable item that you use to store variables for the PC across resets. Otherwise, you'll need to use a database.

    Alternatively, just check if they have one. If not, give them one.
    if( GetItemPossessedBy(oPC,"TAG_OF_RECALL_STONE") == OBJECT_INVALID )
    {
    	CreateItemOnObject("nw_it_recall", oPC);
    	RewardPartyGP(50, oPC, TRUE);	
    }
    
  • ForSeriousForSerious Member Posts: 446
    I recommend using the built-in skin system for variables like that. Store everything on the PC Properties skin.
  • Ugly_DuckUgly_Duck Member Posts: 179
    I tried it and it didn't work. I probably screwed it up. This is how i added that code:

    // ** Gives a Stone of Recall to player on entering this area
    //Put this script OnEnter
    //** #include "nw_i0_tool" is for giving gold to player on enter of starting area.


    #include "nw_i0_tool"
    void main()


    {

    object oPC = GetEnteringObject();

    if (!GetIsPC(oPC)) return;

    int DoOnce = GetLocalInt(oPC, GetTag(OBJECT_SELF));

    if (DoOnce==TRUE) return;

    if( GetItemPossessedBy(oPC,"NW_IT_RECALL") == OBJECT_INVALID ) // Making recall stone only drop once.

    SetLocalInt(oPC, GetTag(OBJECT_SELF), TRUE);

    CreateItemOnObject("nw_it_recall", oPC);
    RewardPartyGP(50, oPC, TRUE);

    }

    Also, when I try to test in in multiplayer, sometimes it crashes the game when selecting a saved character. More help and ideas are welcome!
  • Ugly_DuckUgly_Duck Member Posts: 179
    ROFL! This script broke 2 of the areas I put it in. When I enter the area by any means, Start Location, portal, door, etc. 95% of the time, the game crashes to desktop. After removing the script from both areas, it still crashes the game when entering that area. I collected all the crash logs, dumps, and sent them to Beamdog support. I don't know what happened, maybe its connected to the problems I've been having after screwing up the CEP thing, but I could use some help..
  • ForSeriousForSerious Member Posts: 446
    I have no idea why it would crash the game. That might be something unrelated.

    Are you putting this in the area OnEnter or the module OnClientEnter?
    You did forget to put brackets on the last if statement. That can make it do unexpected things. Actually, you didn't put brackets on any of the if statements. That can lead to many painful hours scouring for what could be wrong.

    Anyway, you don't need the DoOnce part anymore. It wouldn't have worked anyway unless you have a player tagging system that gives players a unique tag when they enter the module. (I've shared how to do that on this forum before elsewhere.)

    Here's the revised script:
    // ** Gives a Stone of Recall to player on entering this area
    //Put this script OnEnter
    //** #include "nw_i0_tool" is for giving gold to player on enter of starting area.
    #include "nw_i0_tool"
    void main()
    {
        object oPC = GetEnteringObject();
        if(!GetIsPC(oPC))
        {
            return;
        }
        if(GetItemPossessedBy(oPC, "NW_IT_RECALL") == OBJECT_INVALID) // Making recall stone only drop once.
        {
            CreateItemOnObject("nw_it_recall", oPC);
            RewardPartyGP(50, oPC, TRUE);
        }
    }
    

    If you do want to put it in the module level OnClientEnter, I recommend just making it a new script and adding it to the OnClientEnter script with ExecuteScript (I named it give_recall):
    ExecuteScript("give_recall", OBJECT_SELF);
    
  • Ugly_DuckUgly_Duck Member Posts: 179
    It seems to be working well. I appreciate the help - thanks!
  • ForSeriousForSerious Member Posts: 446
    Glad to hear.
Sign In or Register to comment.