Author Topic: Help with Onused script.  (Read 606 times)

Legacy_Arawan

  • Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
Help with Onused script.
« on: September 20, 2010, 12:33:11 pm »


               Greetings all,

I am a complete novice with scripting, and usually I use lilacs to do all my scripting for me, but I am currently trying to create a script, that lilac cant assist me with (or at least I cant figure out how to do it).

Basically what I want to make is this:

OnUsed script of a portal: The module has 4 custom player "factions" in it, and players are assigned to a faction with a nondroppable item (Called tagname: FactionItem1, FactionItem2, FactionItem3, FactionItem4).
When a player without one of these four items attempts to use the portal, the PC should get a message saying he / she needs to first declare loyalty to one of the factions (and thus recieve one of the FactionItems).

Upon using the portal and holding one of the three Factions Items, I want a modulewide reputationadjustment to happen to the player as such:
FactionItem1 =  - 100 adjustment to Faction2 and Faction 3 (at war with Faction 2 and Faction 3, neutral to Faction 4)
FactionItem2 =   - 100 adjustment to Faction1 and Faction 3 (At war with Faction 1 and Faction 3, neutral to faction 4)
FactionItem3 =  - 100 adjustment to Faction1 and Faction 2 (The Hostile Faction everyone is at war with).
FactionItem4 =  - 100 adjustment to Faction 3. (Info: This is the "neutral" PC faction, only at war with Faction 3, which everyone is at war with).


And then teleport them to the corresponding FactionHomeWP. (Faction1HomeWP, Faction2HomeWP, Faction3HomeWP, Faction4HomeWP).

The script lilac gives me is this when I try to create it: 

string sDeny;
/*   Script generated by
Lilac Soul's NWN Script Generator, v. 2.3

For download info, please visit:
http://nwvault.ign.c...=4683&id=625    */

//Put this script OnUsed
void main()
{

object oPC = GetLastUsedBy();

if (!GetIsPC(oPC)) return;

if (GetItemPossessedBy(oPC, "FactionItem1")== OBJECT_INVALID)
   {
   sDeny="You have to declare loyalty to one of the Kingdoms before entering";

   SendMessageToPC(oPC, sDeny);

   return;
   }

object oTarget;
oTarget = GetObjectByTag("FactionNPC2");

AdjustReputation(oPC, oTarget, -100);

oTarget = GetObjectByTag("FactionNPC3");

AdjustReputation(oPC, oTarget, -100);

location lTarget;
oTarget = GetWaypointByTag("Faction1HomeWP");

lTarget = GetLocation(oTarget);

//only do the jump if the location is valid.
//though not flawless, we just check if it is in a valid area.
//the script will stop if the location isn't valid - meaning that
//nothing put after the teleport will fire either.
//the current location won't be stored, either

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

AssignCommand(oPC, ClearAllActions());

DelayCommand(3.0, AssignCommand(oPC, ActionJumpToLocation(lTarget)));

oTarget = oPC;

//Visual effects can't be applied to waypoints, so if it is a WP
//the VFX will be applied to the WP's location instead

int nInt;
nInt = GetObjectType(oTarget);

if (nInt != OBJECT_TYPE_WAYPOINT) ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_UNSUMMON), oTarget);
else ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_UNSUMMON), GetLocation(oTarget));

}


I realise the above is only for one faction, and I am not even sure it works, but I have no idea how to add several checks into it, and do the correct thing based on which of the 4 FactionItems the PC is carrying..

Could anyone help please? 


Thank you
               
               

               


                     Modifié par Arawan, 20 septembre 2010 - 11:48 .
                     
                  


            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
Help with Onused script.
« Reply #1 on: September 20, 2010, 04:07:28 pm »


               Here's a version that was written in NWN2 toolset, does compile there but untested in game. It should work in NWN1 as I think all the functions are the same:

string sDeny;
/*   Script generated by
Lilac Soul's NWN Script Generator, v. 2.3
For download info, please visit:
[url=http://nwvault.ign.com/View.php?view=Other.Detail&id=4683&id=625]http://nwvault.ign.com/View.php?view=Other.Detail&id=4683&id=625[/url]    */
//Put this script OnUsed
void main()
{
object oPC = GetLastUsedBy();
if (!GetIsPC(oPC)) return;
string sLeft;
string sRight;
object oTarget;
location lTarget;
int nInt;
object oItem = GetFirstItemInInventory(oPC);
while(GetIsObjectValid(oItem)) // Search though all the player's items in general inventory
 {
 sLeft = GetStringLeft(GetTag(oItem), 11); // Look at the left end of tag for each item, search for "FactionItem" in tag
 if (sLeft == "FactionItem") // If we have any of the faction items
    {
    sRight = GetStringRight(GetTag(oItem), 1); // Look at the right end of tag for each item
    if(sRight == "1") // If the item tag ends in "1" set reputations towards other factions
      {
   oTarget = GetObjectByTag("FactionNPC2");
   AdjustReputation(oPC, oTarget, -100);
   oTarget = GetObjectByTag("FactionNPC3");
   AdjustReputation(oPC, oTarget, -100);
   }
  
  if(sRight == "2") // If the item tag ends in "2" set reputations towards other factions
      {
   // Code to set faction adjustments here
   }
 
  if(sRight == "3") // If the item tag ends in "3" set reputations towards other factions
      {
   // Code to set faction adjustments here
   }
   
  if(sRight == "4") // If the item tag ends in "4" set reputations towards other factions
      {
   // Code to set faction adjustments here
   } 
  
  // We have set their faction views, so now Jump the player to their starting waypoint after a 3 second delay
  oTarget = GetWaypointByTag("Faction" + sRight + "HomeWP");
  lTarget = GetLocation(oTarget);
  if (GetAreaFromLocation(lTarget)==OBJECT_INVALID) return;
  AssignCommand(oPC, ClearAllActions());
  DelayCommand(3.0, AssignCommand(oPC, ActionJumpToLocation(lTarget)));
  oTarget = oPC;
  nInt = GetObjectType(oTarget);
  if (nInt != OBJECT_TYPE_WAYPOINT) ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_UNSUMMON), oTarget);
  else ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_UNSUMMON), GetLocation(oTarget));
  return; // We have done what we needed, so end the script
   }
 oItem = GetNextItemInInventory(oPC); // Last item we looked at had wrong tag, now look at next item in inventory
 }
     
// We do not have any of the faction items
sDeny="You have to declare loyalty to one of the Kingdoms before entering";
SendMessageToPC(oPC, sDeny);
return;
}

Also, you might find my tutorial useful, linked in signature below.
               
               

               
            

Legacy_420

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Help with Onused script.
« Reply #2 on: September 20, 2010, 05:40:03 pm »


               You may want to consider using the NWN database to keep track of factions instead of items. That way you can just use SetCampaignInt and GetCampaignInt to assign PCs to factions 1, 2, 3 and 4. If it returns 0 then you know they have no faction.



-420
               
               

               
            

Legacy_Mudeye

  • Full Member
  • ***
  • Posts: 238
  • Karma: +0/-0
Help with Onused script.
« Reply #3 on: September 20, 2010, 06:27:27 pm »


               Here's a script for this kind of thing.  This is set for 3 factions that are all at war with each other.  I set it up this way because it is easier to follow than having a 4th faction that is different.  If you need help making your specific case work, please message me.

Some instructions:
1) Make an npc that is a member of each faction  and set their tags to "FactionNPC_1", FactionNPC_2" and "FactionNPC_3".
2) Set their plot flag so they cannot be destroyed and place them in the faction area for that faction.
3) Create a waypoint for each faction where you want the pc to get teleported to.
4) Put tags on these "WP_FAC1", "WP_FAC2" and "WP_FAC3".
5) Put the following script in the OnUsed slot for the portal.

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

    //make sure we have a pc
    if (!GetIsPC(oPC)) return;
   
    //get a representative npc from each faction
    object NPC1 = GetObjectByTag("FactionNPC_1");
    object NPC2 = GetObjectByTag("FactionNPC_2");
    object NPC3 = GetObjectByTag("FactionNPC_3");
   
    //everyone hates you to start,  this should always lower faction to 0 which is the lowest it can go
    AdjustReputation(oPC,NPC1,-100);
    AdjustReputation(oPC,NPC2,-100);
    AdjustReputation(oPC,NPC3,-100);
   
    object destination;

    //if you have a faction item then make that faction love you
    // also get the destination for the faction that loves you
    if( GetItemPossessedBy(oPC, "FactionItem1")!= OBJECT_INVALID)
    {
        AdjustReputation( oPC, NPC1, 100 );
        destination = GetWaypointByTag("WP_FAC1");
    }
    else if( GetItemPossessedBy(oPC, "FactionItem2")!= OBJECT_INVALID)
    {
        AdjustReputation( oPC, NPC2, 100 );
        destination = GetWaypointByTag("WP_FAC2");
    }
    else if( GetItemPossessedBy(oPC, "FactionItem3")!= OBJECT_INVALID)
    {
        AdjustReputation( oPC, NPC3, 100 );
        destination = GetWaypointByTag("WP_FAC3");
    }
    else
    {
        SendMessageToPC( oPC, "You have to declare loyalty to one of the Kingdoms before entering" );
        return;
    }
   
    //script exits before here if there was no FactionItem

   
    //clear all your actions so nothing odd happens
    AssignCommand(oPC, ClearAllActions());
   
    //off you go to your destination, delay 3 seconds so the Clear happens first
    DelayCommand(3.0, AssignCommand(oPC, ActionJumpToObject(destination)));
   
    return;
}
               
               

               


                     Modifié par Mudeye, 20 septembre 2010 - 07:33 .
                     
                  


            

Legacy_Arawan

  • Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
Help with Onused script.
« Reply #4 on: September 20, 2010, 07:55:57 pm »


               Thank you knightmare and Mudeye.



I am not sure what I am doing wrong, but both your scripts only make the Message and the teleport part work.. I do not get the reputation adjustments? I have checked the NPC tags.



               
               

               
            

Legacy_Mudeye

  • Full Member
  • ***
  • Posts: 238
  • Karma: +0/-0
Help with Onused script.
« Reply #5 on: September 20, 2010, 08:26:55 pm »


               Please check that the "Global Effect" toggle button is ON for all of the factions.  That is in the Faction Editor.
               
               

               
            

Legacy_Arawan

  • Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
Help with Onused script.
« Reply #6 on: September 20, 2010, 08:28:45 pm »


               All Factions have the Global effect box checked (ie on)..
               
               

               
            

Legacy_Mudeye

  • Full Member
  • ***
  • Posts: 238
  • Karma: +0/-0
Help with Onused script.
« Reply #7 on: September 20, 2010, 08:36:33 pm »


               I just noticed a typo where the tag on the NPC for faction2 was wrong in the script I put out.  Try loading it again, please. Also verify that the NPCs are members of the correct factions.

               
               

               
            

Legacy_Arawan

  • Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
Help with Onused script.
« Reply #8 on: September 20, 2010, 08:42:06 pm »


               Caught the typo earlier, so not that.  But recompiled script just the same. Have verified the NPCs are members of the correct factions..



Any chance you have msn or yahoo and time for a few minutes of troubleshooting? if so, PM me your adress, ty
               
               

               
            

Legacy_Arawan

  • Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
Help with Onused script.
« Reply #9 on: September 20, 2010, 11:14:17 pm »


               Worked out with the awesome help of Mudeye