Author Topic: Scripting question:  (Read 1477 times)

Angryvet

  • New to the Mists
  • *
  • Posts: 19
    • C.R.Beaumont
Scripting question:
« on: May 26, 2015, 10:58:42 AM »
Alright, so I want to alter an xp system. Of course, I am out of practice and quite forgetful and haven't attempted scripting in maybe over a year.

What I want it to do is give xp based on proximity with out players being in a party while still having the other nifty features such as scaling and such. I don't want players to be in a party, but I would like the xp to still be distributed even if another player kills a spawn. Of course, the other features already in the system I want to use allow for cr scaling and level scaling, of course the level scaling might have to be a proximity thing as well since the players wouldn't be in a party.  Any advise or tips on this would be very much appreciated. 

I'd like to use this system as the basis: http://neverwintervault.org/project/nwn1/script/pwfxp-20-flexible-xp-distribution-system

Bad_Bud

  • Developers
  • Dark Power
  • *
  • Posts: 4438
Re: Scripting question:
« Reply #1 on: May 27, 2015, 07:51:00 AM »
It's going to be something like this:

Code: [Select]
   //oKiller being the player who killed some creature
    object oKiller = WHATEVER KILLED SOMETHING, HOWEVER YOU GET THAT;
    location lKiller = GetLocation(oKiller);

    //Finding objects near the player that killed something
    object oParty = GetFirstObjectInShape(SHAPE_SPHERE, fRadius, lKiller);
    while(GetIsObjectValid(oTarget))
    {
        //If the object is a player
        if(GetIsPC(oTarget))
        {
            //If the player is not an enemy
            if(GetIsReactionTypeFriendly(oParty) || GetIsReactionTypeNeutral(oParty))
            {
                //If you want to do things like figure out who the highest level character is, party average level or whatever, you need to do it in this loop.
                //This first loop is for collecting information.
            }
        }

        oParty = GetNextObjectInShape(SHAPE_SPHERE, fRadius, lTarget);
    }

    //Loop again with the same rules
    oParty = GetFirstObjectInShape(SHAPE_SPHERE, fRadius, lKiller);
    while(GetIsObjectValid(oTarget))
    {
        if(GetIsPC(oTarget))
        {
            if(GetIsReactionTypeFriendly(oParty) || GetIsReactionTypeNeutral(oParty))
            {
                //Give experience based on your scaling rules or whatever.
            }
        }

        oParty = GetNextObjectInShape(SHAPE_SPHERE, fRadius, lTarget);
    }

Our system takes other things into consideration such as whether or not the player could perceive the enemy when it died, so if the player is blinded they cannot receive experience, but that is the basic structure of what you're going to be looking at.
« Last Edit: May 27, 2015, 07:54:17 AM by Bad_Bud »

Angryvet

  • New to the Mists
  • *
  • Posts: 19
    • C.R.Beaumont
Re: Scripting question:
« Reply #2 on: May 27, 2015, 10:53:14 AM »
Thanks Bad-Bud, I think I should be able to figure out how to mesh things and get what I want to do what I want with this reference bit.  Might take me a little while, but I should be able to figure it out now.

Angryvet

  • New to the Mists
  • *
  • Posts: 19
    • C.R.Beaumont
Re: Scripting question:
« Reply #3 on: June 09, 2015, 05:10:32 PM »
Alright, been fighting with this with no real success. . . The goal is to have the trigger check an area for a player with a local int set on them, and if there is one, to stop, if not then port player entering trigger to a way point.
The script compiles just fine, but gives a tmi error when trying to enter it and thus doing nothing. Any suggestions? Fixes? Simplifying? 

///Caine's attempt at area checking cutsceen trigger
location lTarget;
object oTarget;

void main()
{

//Call for the way point in the area, get the area, get the pc
object oWaypoint = GetWaypointByTag("wp_st_entry");
object oPC = GetEnteringObject();
object oArea = GetArea(oWaypoint);
{
  if (!GetIsPC(oPC)) return;

       ///Cycle through checking area objects
       object oObject = GetFirstObjectInArea(oArea);
       while(GetIsObjectValid(oObject))
      {
         if(GetIsPC(oObject))
         {
         ///Check for the local variable
           if (GetLocalInt(oPC, "cutscene")!= 1)
           SendMessageToPC(oPC, "You must wait for the cutscene to be clear.");

           else
             //if there is no pc in the area with the cutscene 1 variable jump them
            {
   oTarget = GetWaypointByTag("wp_st_entry");

   lTarget = GetLocation(oTarget);


   if (GetAreaFromLocation(lTarget)==OBJECT_INVALID) return;

   AssignCommand(oPC, ClearAllActions());

   AssignCommand(oPC, ActionJumpToLocation(lTarget));
          }
   }
  }
 }
}

EO

  • Assistant Head DM/Developer
  • Head DMs
  • Dark Power
  • ******
  • Posts: 17391
  • The one and only, the one everyone wants to be!
Re: Scripting question:
« Reply #4 on: June 09, 2015, 05:39:15 PM »
On a smartphone right now so won't be too detailed:

You need to add a line like this before the end of your while function:

oObject = GetNextObjectInArea(oArea);

Otherwise you have an endless loop (while is always true since you keep referring to the same PC).

Angryvet

  • New to the Mists
  • *
  • Posts: 19
    • C.R.Beaumont
Re: Scripting question:
« Reply #5 on: June 10, 2015, 03:59:19 AM »
Thank eo!
Well, that fixed the tmi error, but I can't quite seem to get the check for a pc in another area to work. So, what I've done is made the trigger a trap, deactivated it when a pc goes into the cutscene and set the timer for reactivation when the cutscene is over, roughly about three minutes. So far with testing it's worked like a charm and was much simpler.

Angryvet

  • New to the Mists
  • *
  • Posts: 19
    • C.R.Beaumont
Re: Scripting question:
« Reply #6 on: June 22, 2015, 04:54:47 PM »
I decided to go with a timer delay on the trigger, set for the duration of my cutscene and that seems to have everything working splendidly with less complication.

On a side note, I have another question regarding scripts.

I've made some custom familiars, some of which can be used as mounts, but there is the small problem that on dismounting the resref creature appears as opposed to the familiar. Any one have any ideas on how this might be remedied?