Skip to content

Test to see if campaign object exists without creating it? (Supposed to be in Scripting discussion)

NeverwinterWightsNeverwinterWights Member Posts: 339
edited August 2023 in General Discussions NWN:EE
I might be overthinking this, but I can't seem to find a function to just check if a campaign object exists in a specified campaign database without actually creating the object. RetrieveCampaignObject(); seems to HAVE to create the object somewhere even if you don't actually want to create it yet. And there is no simple GetCampaignObject(); check.
Post edited by JuliusBorisov on

Comments

  • DazDaz Member Posts: 125
    There's no builtin function for it, but you can write one yourself if you know a bunch of sql:
    int GetCampaignObjectExists(string sCampaignName, string sVarName, object oPlayer = OBJECT_INVALID)
    {
        string sPlayerId = "";
        if (oPlayer != OBJECT_INVALID && GetIsPC(oPlayer)) sPlayerId = GetStringLeft(GetPCPlayerName(oPlayer), 16) + GetStringLeft(GetName(oPlayer), 16);
        sqlquery sql = SqlPrepareQueryCampaign(sCampaignName, "SELECT * FROM db WHERE varname = @varname AND vartype = @vartype" + (sPlayerId != "" ? " AND playerid = @playerid" : "") + ";");
        SqlBindString(sql, "@varname", sVarName);
        SqlBindInt(sql, "@vartype", 79);
        if (sPlayerId != "") SqlBindString(sql, "@playerid", sPlayerId);
        return SqlStep(sql);
    }
    
  • NeverwinterWightsNeverwinterWights Member Posts: 339
    Thanks Daz. Unfortunately I hardly know any sql but I did manage to figure out those time functions you replied to me in another post. Hopefully I can figure this one out too.
Sign In or Register to comment.