Aller au contenu

Photo

On Acquire If - Else script not working right


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

#1
Clyordes

Clyordes
  • Members
  • 300 messages
Good evening scripting gods - hope you can help - again.

One of my side quests involves looking for, and hopefully finding two ancient artifacts - a sword & a bow used by a legendary hero called Escatha.  I'm trying to set up scripts that fire on acquiring each of the items. 

Tag of the bow is escathabow
Tag of hte sword is escathaswd

I want the scripts to:
Check if the party already has possession of the other object and
if so:
1. Give 250xp
2. Produce floaty text above the PC saying "Well done - you have both items now" - or similar
3. Update the journal "Ancient Artifacts" to node 40

if not:
1. Give 250xp
2. Produce floaty text above the PC saying "Well done - you've found one of the weapons" - or similar
3. Update the journal "Ancient Artifacts" to node 20 or 30 - depending on which weapon's been found, and which still remains to be found

For some reason I really don't understand, the script for the bow updates the journal to node 20 regardless of whether the sword's in the party's possession or not, but doesn't produce floaty text, or give XP.

The script for the sword doesn't do anything at all.



I've checked the tags of the two weapons, even made a completely seperate area & added them as objects on the ground that a test character can just wander over & pick up - still no change.

Here are the scripts below - created using the updated Lilac Soul script creator - please feel free to point & laugh - as long as you can help me sort them out :blush:

And please remember - in case its not obvious - I'm no scripter - please use short words:


The Bow script:

#include "x0_i0_partywide"


void OnAcquire(object oEventItem, object oAcquiredBy, object oTakenFrom, int nStackSize)
{
    object oPC = oAcquiredBy;

    // Only fire for PCs.
    if ( !GetIsPC(oPC) )
        return;

    // Only fire once per game.
    if ( GetLocalInt(GetModule(), "DOONCE_OnAcquire_" + GetTag(oEventItem)) )
        return;
    SetLocalInt(GetModule(), "DOONCE_OnAcquire_" + GetTag(oEventItem), TRUE);

    // If the PC's party has the item "escathaswd".
    if ( GetIsItemPossessedByParty(oPC, "escathaswd") )
    {
        // Update all players' journals.
        AddJournalQuestEntry("Ancient Artifacts", 40, oPC, FALSE, TRUE);

        // Give 250 experience (to party) to the PC.
        GiveXPToAll(oPC, 250);

        // Have text appear over the PC's head.
        FloatingTextStringOnCreature("you found both artifacts - well done!", oPC);
    }
    else
    {
        // Update all players' journals.
        AddJournalQuestEntry("Ancient Artifacts", 20, oPC, FALSE, TRUE);

        // Give 250 experience to the PC.
        GiveXPToCreature(oPC, 250);

        // Have text appear over the PC's head.
        FloatingTextStringOnCreature("you got the bow - now find the sword!", oPC);
    }
}


The Sword script:

#include "x0_i0_partywide"


void OnAcquire(object oEventItem, object oAcquiredBy, object oTakenFrom, int nStackSize)
{
    object oPC = oAcquiredBy;

    // Only fire for PCs.
    if ( !GetIsPC(oPC) )
        return;

    // Only fire once per game.
    if ( GetLocalInt(GetModule(), "DOONCE_OnAcquire_" + GetTag(oEventItem)) )
        return;
    SetLocalInt(GetModule(), "DOONCE_OnAcquire_" + GetTag(oEventItem), TRUE);

    // If the PC's party has the item "escathaswd".
    if ( GetIsItemPossessedByParty(oPC, "escathabow") )
    {
        // Update all players' journals.
        AddJournalQuestEntry("Ancient Artifacts", 40, oPC, FALSE, TRUE);

        // Give 250 experience (to party) to the PC.
        GiveXPToAll(oPC, 250);

        // Have text appear over the PC's head.
        FloatingTextStringOnCreature("you found both artifacts - well done!", oPC);
    }
    else
    {
        // Update all players' journals.
        AddJournalQuestEntry("Ancient Artifacts", 20, oPC, FALSE, TRUE);

        // Give 250 experience to the PC.
        GiveXPToCreature(oPC, 250);

        // Have text appear over the PC's head.
        FloatingTextStringOnCreature("you got the sword - now find the bow!", oPC);
    }
}

Many thanks in advance folks - you're always awesome & I'm sure you will be here too...

Cly.

#2
MasterChanger

MasterChanger
  • Members
  • 686 messages
Personally, this situation screams "tag-based script!!!" to me (oww oww my ears!). To do this, create a script called "i_<tag_of_item>_aq", so "i_escathabow_aq" and "i_escathaswd_aq". This technique can make the script much easier to read and debug.

I'd also throw in a SendMessageToPC just for testing purposes in every if-else block so that you can trace where the logic is hitting a snag.

#3
kevL

kevL
  • Members
  • 4 078 messages
- fleshing out what 'Changer just said:
Replace

void OnAcquire(object oEventItem, object oAcquiredBy, object oTakenFrom, int nStackSize)
{
object oPC = oAcquiredBy;


with

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


& name the first script
i_escathabow_aq
& the second
i_escathaswd_aq



Lilac's is great, but it still 'thinks' in terms of NwN1 tag-based ... so make sure your module's onAcquireItem script is default or has the default code to fire this up :)

Modifié par kevL, 06 juillet 2012 - 09:15 .


#4
Clyordes

Clyordes
  • Members
  • 300 messages
Apologies MasterChanger - I thought I'd made a tag based script - both scripts are already named as you suggested. Maybe I pressed the wrong buttons in Lilac Soul's creator & chose the 'old' scripting system in error.

I have a similar on acquire tag based script for a medallion the main boss has named i_jade_medallion_aq & that works fine - but all it needs to do is update the journal - no if-else statements.

I see what you mean though - Lilac Soul does seem to struggle with the few differences between NWN2 & 1 scripting, and I'm too clueless to sort out the problems - but that's why I come here :-)

KevL- I'll try those changes when I get an hour free & see what happens.

Cly.

#5
johnbgardner

johnbgardner
  • Members
  • 185 messages
You might try using Journal entry #20 for when you have the sword and not the bow, make another, say #30 for when you have the bow and not the sword, and #40 when you have both. It might help in debugging your if-else logic.

#6
Clyordes

Clyordes
  • Members
  • 300 messages
Right - I've only had time to implement what Kev advised - swapping part of the script for his suggestion - unfortunately, when I try to compile I get this error message:
i_escathaswd_aq.nss(18): ERROR: VARIABLE DEFINED WITHOUT TYPE

Line 18 is: if ( GetLocalInt(GetModule(), "DOONCE_OnAcquire_" + GetTag(oEventItem)) )

Just in case its useful, I checked my module properties & this is the script in the ""On Acquire Iten Script slot: x2_mod_def_aqu

Also just in case its useful, here's the journal entries that are supposed to fire:
Ancient Artifacts 20
You have found the bow of Escatha - one of the long lost weapons of the legendary hero of the Sahuagin Heel! Can you also find his sword?

Ancient Artifacts 30
You have found the sword of Escatha - one of the long lost weapons of the legendary hero of the Sahuagin Heel! Can you also find his bow?

Ancient Artifacts 40
You have found both of the ancient weapons of the hero Escatha - once thought lost to the forces of good!

Unfortunately have to get off to work now - but I'll try & implement the other suggestions later on if I get chance.

Cly.

#7
kevL

kevL
  • Members
  • 4 078 messages
hey Cly,
first, it looks like you should DL Skywing's compiler and toss the plug-in into Plugins


his error messages are way better ( so is the compiled code i believe )

variable defined without type, looks to me like "oEventItem" <-- variable, type should be 'object'

So you'll need another line :

void main()
{
object oPC = GetModuleItemAcquiredBy();
object oEventItem = GetModuleItemAcquired();

// etc.