Author Topic: Script issue with adjust reputation  (Read 547 times)

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
Script issue with adjust reputation
« Reply #15 on: May 01, 2011, 07:19:04 am »


               the issue is each time you AdjustReputation it stacks is what it seems.  If your only running this function once add a local var to CreatureA,CreatureB, so when you go through the B creature if A all ready set it doesn't set again and moves to the next one.  If im understanding you corectly.  You would do the same thing if comparing items, objects etc
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Script issue with adjust reputation
« Reply #16 on: May 01, 2011, 09:12:03 am »


               Ok I now see what you are talking about.   After a couple hours of testing and looking for a workaround, I have come up with nothing.   Applying the adjustments between the same two creatures again only compounds the problem.   It seems like it is adding the last adjustment to the Next adjustment.  For when i tested doing the adjustment again between the same two both adjustments where screwed up and not just the second one.  

Right now I have no solution.  I will try and dig in a little bit deeper when i get a chance again.  First I guess I need to look at the faction format a little closer.
               
               

               
            

Legacy_DM_Vecna

  • Hero Member
  • *****
  • Posts: 501
  • Karma: +0/-0
Script issue with adjust reputation
« Reply #17 on: May 05, 2011, 05:56:40 am »


               I finally figured out a next step. I am going to make the first call to adjust reputation. Destroy the first creature then spawn it again and finally make the second call. I will post the results.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Script issue with adjust reputation
« Reply #18 on: May 08, 2011, 03:16:02 am »


               I have even used an adjusted version of repadjust.2da and have so far come up with no solution to this bug.
               
               

               
            

Legacy_virusman

  • Sr. Member
  • ****
  • Posts: 448
  • Karma: +0/-0
Script issue with adjust reputation
« Reply #19 on: January 21, 2012, 10:49:42 pm »


               What happens if you call AdjustReputation and GetReputation on different creatures from the same factions?
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Script issue with adjust reputation
« Reply #20 on: January 22, 2012, 12:49:01 am »


               I used the following code to do this in my own module, and it worked fine (bit of my own database code, but you get the picture):

int prr_GetIsReputationInitialized(object oTarget, object oSourceFactionMember)
{
    if (GetFactionEqual(oTarget, oSourceFactionMember))
    return TRUE;

    string sFaction = prr_GetFaction(oSourceFactionMember);
    string sFaction2 = prr_GetFaction(oTarget);

    if (ss_GetDatabaseInt(PRR_REPUTATION_INIT_PREFIX + sFaction + "_" + sFaction2))
        return TRUE;
    else
        return ss_GetDatabaseInt(PRR_REPUTATION_INIT_PREFIX + sFaction2 + "_" + sFaction);
}

void prr_InitializeReputation(object oTarget, object oSourceFactionMember)
{
    if (GetFactionEqual(oTarget, oSourceFactionMember))
        return;

    int    nAmount   = GetReputation(oSourceFactionMember, oTarget);
    string sFaction  = prr_GetFaction(oSourceFactionMember);
    string sFaction2 = prr_GetFaction(oTarget);
    prr_SetExternalReputation(oSourceFactionMember, oTarget, nAmount, sFaction, sFaction2);
    ss_SetDatabaseInt(PRR_REPUTATION_INIT_PREFIX + sFaction + "_" + sFaction2, 1);
    ss_SetDatabaseInt(PRR_REPUTATION_INIT_PREFIX + sFaction2 + "_" + sFaction, 1);
}

void prr_LoadFactionReputations()
{
    object oTargetFocus = GetObjectByTag(PRR_FACTION_FOCUS);
    object oSourceFocus;
    string sTargetFaction;
    string sSourceFaction;
    int    nCurrentRep;
    int    nStoredRep;
    int    nChange;
    int    nIndex;
    int    nIndex2;

    while(GetIsObjectValid(oTargetFocus))
    {
        nIndex2 = 0;
        sTargetFaction = prr_GetFaction(oTargetFocus);
        oSourceFocus   = GetObjectByTag(PRR_FACTION_FOCUS);
        while(GetIsObjectValid(oSourceFocus))
        {
            if(!GetFactionEqual(oTargetFocus, oSourceFocus))
            {
                if(prr_GetIsReputationInitialized(oTargetFocus, oSourceFocus))
                {
                    sSourceFaction = prr_GetFaction(oSourceFocus);
                    nCurrentRep = GetReputation(oSourceFocus, oTargetFocus);
                    nStoredRep = prr_GetExternalReputation(oSourceFocus, oTargetFocus, sSourceFaction, sTargetFaction);
                    nChange = nStoredRep - nCurrentRep;
                   AdjustReputation(oTargetFocus, oSourceFocus, nChange);
                }
                else
                    prr_InitializeReputation(oTargetFocus, oSourceFocus);
            }
            nIndex2++;
            oSourceFocus = GetObjectByTag(PRR_FACTION_FOCUS, nIndex2);
        }
        nIndex++;
        oTargetFocus = GetObjectByTag(PRR_FACTION_FOCUS, nIndex);
    }
}
I did have an issue like what you described, but at a different place. It turned out that the AdjustFactionReputation() function in nw_i0_plot was bugged. Doesn't look to be what's going on here, but thought I'd throw that out there.
               
               

               


                     Modifié par Squatting Monk, 22 janvier 2012 - 01:04 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Script issue with adjust reputation
« Reply #21 on: January 22, 2012, 01:13:04 am »


               Monk - are those rewrites of the functions in PRR 2?
               
               

               
            

Legacy_ShadowM

  • Hero Member
  • *****
  • Posts: 1373
  • Karma: +0/-0
Script issue with adjust reputation
« Reply #22 on: January 22, 2012, 01:16:41 am »


               Seem that AdjustReputation is holding the adjustment amount and adding it to any more calls after the first call that relate to the two factions in the script, it just weird. I added a third faction in testing and it was not affected.
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Script issue with adjust reputation
« Reply #23 on: January 22, 2012, 01:42:58 am »


               

henesua wrote...

Monk - are those rewrites of the functions in PRR 2?

Yes. I think I modified those from an NWNX version of PRR I found, but I can't seem to locate the originals anywhere. (Could be I rewote the NBDE version to use NWNX, but I don't think I was good enough at scripting to do that back in 2007 when I wrote this).

I do have my full edited versions if anyone wants them, though there are a few bugs hiding out.
               
               

               


                     Modifié par Squatting Monk, 22 janvier 2012 - 01:45 .
                     
                  


            

Legacy_virusman

  • Sr. Member
  • ****
  • Posts: 448
  • Karma: +0/-0
Script issue with adjust reputation
« Reply #24 on: January 22, 2012, 05:27:51 pm »


               Looking at the implementation code, I don't really see where AdjustReputation can affect both reputations.
GetReputation, on the other side, also adds personal reputation, so try to call GetReputation on other creatures from these factions.
               
               

               
            

Legacy_ShadowM

  • Hero Member
  • *****
  • Posts: 1373
  • Karma: +0/-0
Script issue with adjust reputation
« Reply #25 on: January 22, 2012, 06:33:00 pm »


               Can someone make a sample module (vanilla nwn) , with two factions both at 50 and adjust one up 2 and adjust the other up 3 every heartbeart ( where they say there reputations towards the each other on that heartbeat) I did this and the numbers jump all weird. So a sample module maybe of the right way will enlighten me and I sure some others. Thanks. '<img'>
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Script issue with adjust reputation
« Reply #26 on: January 22, 2012, 06:52:20 pm »


               

ShadowM wrote...

Can someone make a sample module (vanilla nwn) , with two factions both at 50 and adjust one up 2 and adjust the other up 3 every heartbeart ( where they say there reputations towards the each other on that heartbeat) I did this and the numbers jump all weird. So a sample module maybe of the right way will enlighten me and I sure some others. Thanks. '<img'>


9 months ago when this first came up,  I did one with the adjust script set on the OnOpen event of a chest.  I got the Odd results also.   The problem seems to compond with old results adding back into the faction adjust.    

So if you adjust the first faction by 2, a call to adjust the first faction by 2 adjusts it by 4 instead.    

I still have this thread bookmarked to trace out the function calls, I have just not been able to find enough free time to delve into it that deep.     
               
               

               
            

Legacy_virusman

  • Sr. Member
  • ****
  • Posts: 448
  • Karma: +0/-0
Script issue with adjust reputation
« Reply #27 on: January 22, 2012, 08:05:35 pm »


               Ok, it appears to be a bug in the parameters (GetReputation and SetReputation have their parameters mixed up, and I can't figure out which one is right '<img'> ). I'll try to fix it and check the functions again.
               
               

               


                     Modifié par virusman, 22 janvier 2012 - 08:10 .
                     
                  


            

Legacy_virusman

  • Sr. Member
  • ****
  • Posts: 448
  • Karma: +0/-0
Script issue with adjust reputation
« Reply #28 on: January 22, 2012, 08:38:04 pm »


               The fix is now in NWNX Fixes 1.0.8:
http://nwn.virusman..../changeset/458/
http://nwn.virusman..../changeset/459/
http://data.virusman...1.0.8-linux.rar
               
               

               


                     Modifié par virusman, 22 janvier 2012 - 09:56 .
                     
                  


            

Legacy_Melkior_King

  • Full Member
  • ***
  • Posts: 234
  • Karma: +0/-0
Script issue with adjust reputation
« Reply #29 on: January 24, 2012, 04:40:56 am »


               I don't know if this is worth mentioning, but I found that the reputation functions don't work correctly if the "reference" NPC is set to be "Plot" (unkillable).  It works fine, even if the NPC is in a different area, so long as the NPC can be killed.

So I put my "reference" NPCs into a tiny area players can't access.

If working with an individual NPC rather than the whole faction, perhaps the NPC could be temporarily set to be killable, then adjust the reputation, then set the NPC back to Plot?  To ensure this is done in the correct order, the functions would probably have to be executed as commands by a "commandable" object.

Ensuring the NPC isn't killed in the interval (maybe by an ongoing AoE spell) is another problem.  Immunities applied to a NPC skin, maybe?
               
               

               


                     Modifié par Melkior_King, 24 janvier 2012 - 04:46 .