Aller au contenu

Photo

Quick question on local variables and scripts


  • Veuillez vous connecter pour répondre
37 réponses à ce sujet

#1
Alassirana

Alassirana
  • Members
  • 55 messages
Ok, I'm going to have 2 factions, each with faction appropriate gear.  However, I want to have a dm wand that can be used on the rare occasion that a player wants to change factions, that will not only change the faction in the deity field, but will also loop through the items to check to see if they have a local variable (1 for fate, 2 for chance), and if they have the variable for the faction that you're changing from, the object will be destroyed (so that no one can have opposing faction gear).  I can do most of this (from looking at other scripts), but I don't know how to check variables on possessed objects.  If you can show me this, I can use it in a couple of other scripts, to make things work more nicely.  Thank you in advance for the information.

Alassirana

#2
Thayan

Thayan
  • Members
  • 244 messages
Like this?

void main()
{
  object oPC = GetItemActivatedTarget();
  if (!GetIsPC(oPC)) return; //End if this isn't a PC

  object oInvItem = GetFirstItemInInventory(oPC);
  while (GetIsObjectValid(oPC)) {
    if (GetLocalInt(oInvItem, "YourFactionVariable")) {
      SetPlotFlag(oInvItem, FALSE);
      DestroyObject(oInvItem);
    }
    oInvItem = GetNextItemInInventory(oPC);
  }
}

Modifié par Thayan, 01 août 2011 - 04:49 .


#3
Alassirana

Alassirana
  • Members
  • 55 messages
Thank you very much. That will work wonders.

#4
Axe_Murderer

Axe_Murderer
  • Members
  • 279 messages
You don't have to turn off the plot flag to destroy an item.

#5
_Knightmare_

_Knightmare_
  • Members
  • 643 messages

Axe_Murderer wrote...

You don't have to turn off the plot flag to destroy an item.


I'm guessing that is meant as a failsafe in case the item was marked as plot. Turning off the plot flag on a non-plot marked item won't do anything.

#6
GhostOfGod

GhostOfGod
  • Members
  • 863 messages

_Knightmare_ wrote...

Axe_Murderer wrote...

You don't have to turn off the plot flag to destroy an item.


I'm guessing that is meant as a failsafe in case the item was marked as plot. Turning off the plot flag on a non-plot marked item won't do anything.


It doesn't matter if it's checked as plot though. Like Axe said you don't have to set plot to false. You can destroy any plot item, object, or creature via scripting without having to uncheck it's plot flag using the "DestroyObject" function. You just can't destroy them in game via spells or damage. So that is just an unnecessary line in the script. The Lexicon doesn't really clarify this.

Modifié par GhostOfGod, 02 août 2011 - 08:22 .


#7
Alassirana

Alassirana
  • Members
  • 55 messages
Ok, I tested out the wand (had to wait until I had a friend available that could test it for me), and ran into an error, saying that there were 'too many instructions'. I removed the plot tag line, and it's compiled properly, but it compiled before. I'll show you the script for your perusal so that you can help me figure out what I'm doing wrong. The script is called from a conversation, and this is where I'm having the problem (I have 2 versions of this script, one for each faction, but they're just reversed in faction names/item prop names).

void main()
{
object oPC = GetItemActivatedTarget();
if (!GetIsPC(oPC)) return; //End if this isn't a PC
SetDeity(oPC, "Fate");

object oInvItem = GetFirstItemInInventory(oPC);
while (GetIsObjectValid(oPC)) {
if (GetLocalInt(oInvItem, "fate")) {
DestroyObject(oInvItem);
}
oInvItem = GetNextItemInInventory(oPC);
}
}

#8
Alassirana

Alassirana
  • Members
  • 55 messages
Ok, I finally got to test my wand, and recieved an error of 'too many instructions'.  I have since removed the 'plot tag' line, but haven't had a chance to retest it yet.  However, I'm fairly sure that's not the reason why it didn't work.  The first part of the script worked (changing the faction), it's the part that should have removed my faction armor that did not.  I'll post the script below.  Please help me figure out what I'm doing wrong.  (there are actually 2 nearly identical scripts; I'm only posting one, because the other is only different in which faction it changes you into, and which local variable it calls).

 void main()
{
  object oPC = GetItemActivatedTarget();
  if (!GetIsPC(oPC)) return; //End if this isn't a PC
  SetDeity(oPC, "Fate");

  object oInvItem = GetFirstItemInInventory(oPC);
  while (GetIsObjectValid(oPC)) {
    if (GetLocalInt(oInvItem, "fate")) {
        DestroyObject(oInvItem);
    }
    oInvItem = GetNextItemInInventory(oPC);
  }
}

#9
Axe_Murderer

Axe_Murderer
  • Members
  • 279 messages
While loop needs to check for valid inventory item, not valid pc. The pc will never be invalid at the while loop, since earlier in the script it would have ended if that was the case and oPC is never assigned a different value inside the loop, so the loop never ends and eventually you run out of instructions. Since it is the inventory item that changes inside the while loop, that's what you should be checking for to end the loop.

[nwscript]void main()
{ object oPC = GetItemActivatedTarget();
   if( !GetIsPC( oPC )) return; // End if this isn't a PC
   SetDiety( oPC, "Fate" );

   object oInvItem = GetFirstItemInInventory( oPC );
   while( GetIsObjectValid( oInvItem ))
   { if( GetLocalInt( oInvItem, "Fate" )) DestroyObject( oInvItem );
      oInvItem = GetNextItemInInventory( oPC );
   }
}
[/nwscript]

Modifié par Axe_Murderer, 04 août 2011 - 12:53 .


#10
Alassirana

Alassirana
  • Members
  • 55 messages
Thanks for catching that.

#11
Alassirana

Alassirana
  • Members
  • 55 messages
Once I corrected the spelling in setDeity, it seems to be ok...though I'll have to wait until later (when a friend is on) to fix it).

#12
Thayan

Thayan
  • Members
  • 244 messages
Whoops. Sorry about that.

#13
Alassirana

Alassirana
  • Members
  • 55 messages
Ok, I've been looking at the scripts so far, and want to modify my 'teleporter' script to use local variables on the panic button (that takes you back to the teleporation nexus) to bring up options on the portal through conversation (text appears when)...but, although I've looked at the scripts you've shown me, I'm not sure how to have it look at the specific object (I want to do this so I don't have to make the players carry around a half dozen place tokens by the end of the game, and it's multiplayer, so local variables on characters get reset when the server does). Can you show me how to call the specific variables (such as 'fokual' for fokual city)?

Thanks in advance.

Alassirana

#14
Alassirana

Alassirana
  • Members
  • 55 messages
*thinks on it a bit* would the part to check it be: int GetLocalInt("panicbutton", oPC, "fokual") for example?

#15
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
Are you talking about a different script now? Not sure what you are asking..

#16
Alassirana

Alassirana
  • Members
  • 55 messages
Yes, it's a different script, but a similar question, which is why I put it back in here...I'm just trying to figure out how to retrieve local variables (originally so I could destroy items with the variables, now so that I can retrieve the variables for a conversation node check...for a teleporter with several possible locations, depending on where you've been before)

#17
Alassirana

Alassirana
  • Members
  • 55 messages
The variables, in both cases are on objects carried by pc's. I'd do Lilac soul stuff with it, but she doesn't have the option for retrieving local variables on objects.

#18
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
Ahh I think I gotcha. So you just want to check out a variable on a specific item that the player has? Maybe something like so:

object oPButton = GetItemPossessedBy(oPC, "PanicButton");
int iFokual = GetLocalInt(oPButton, "Fokual");

if (iFokual == TRUE)
{
    //do something
}


If I'm understanding correctly. haha. Hope it helps.

P.S. It is also good practice to specify "items" as apposed to "objects" when talking about items in player inventory. "Objects" are usually going to be placeables. While they are all objects, it just gets confusing when talking about these things sometimes.

Modifié par GhostOfGod, 18 août 2011 - 07:06 .


#19
Alassirana

Alassirana
  • Members
  • 55 messages
Ok, thanks, that should work nicely...I'll save that so that I can use it in other scripts as needed too.

#20
Alassirana

Alassirana
  • Members
  • 55 messages
Hrm, I thought it was working right, but when I brought in a brand new character (who did not have the local variables set on her panic button), I'm still getting the options for those cities she has not visited...Here's one of the scripts, set as a starting conditional to bringing up that option from the Nexus.  Please tell me what I'm doing wrong (and yes, I've checked to make sure that the variable names and object names are correct).

int StartingConditional()
{
    // Get the PC who is involved in this conversation
    object oPC = GetPCSpeaker();
    object oPButton = GetItemPossessedBy(oPC, "panicbutton");
    int iFokual = GetLocalInt(oPButton, "Fokual");
    if (iFokual == TRUE)
        return FALSE;

    // If we make it this far, we have passed all tests.
    return TRUE;
}

I've tried making iFokual != TRUE, and that makes it disappear for my character with the variables...so I'm doing something wrong here..

Alassirana

#21
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
 int StartingConditional()
{
    // Get the PC who is involved in this conversation
    object oPC = GetPCSpeaker();
    object oPButton = GetItemPossessedBy(oPC, "panicbutton");
    int iFokual = GetLocalInt(oPButton, "Fokual");
    if (iFokual == TRUE || oPButton == OBJECT_INVALID)
        return FALSE;

    // If we make it this far, we have passed all tests.
    return TRUE;
}

 
 

#22
Rolo Kipp

Rolo Kipp
  • Members
  • 2 791 messages
<counts on his fingers...>

Lightfoot8 wrote...
...
    object oPButton = GetItemPossessedBy(oPC, "panicbutton");
    int iFokual = GetLocalInt(oPButton, "Fokual");
    if (iFokual == TRUE || oPButton == OBJECT_INVALID)
        return FALSE;
...
 

So... if PC *has* oPButton and iFokual is *not* set, it will return true...

But, if I read Alassirana correctly, her problem is that it is still returning TRUE, i.e. iFokual is SET, regardless of  "who did not have the local variables set"...

Try having the PC speak the value of iFokual to see if it has somehow been set somewhere along the line?

<...sighs and takes off his boots>

#23
Alassirana

Alassirana
  • Members
  • 55 messages
I've gone into Leto, looked at the item in question, and it did not have the variables. I've also gone into the toolset, verified that the variables were not set in the toolset...and still it comes up in the game as ringing true to having the variables, though she does not have them. I'm really very, very confused by all of this, and don't know how to fix it...it's almost enough to make me go back to using tokens that the player will complain about filling up their inventory, just to make it necessary to walk to a town before being able to port to it.

#24
WhiZard

WhiZard
  • Members
  • 1 204 messages

Alassirana wrote...

I've gone into Leto, looked at the item in question, and it did not have the variables. I've also gone into the toolset, verified that the variables were not set in the toolset...and still it comes up in the game as ringing true to having the variables, though she does not have them. I'm really very, very confused by all of this, and don't know how to fix it...it's almost enough to make me go back to using tokens that the player will complain about filling up their inventory, just to make it necessary to walk to a town before being able to port to it.


Are there any other items by the same tag?

#25
Alassirana

Alassirana
  • Members
  • 55 messages
No, there aren't...and I made sure that the version of the panic button that is in the toolset is updated across the entire module, so it shouldn't have any old/wrongly set up versions floating around...