Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

We need your feedback on the new forum text editor switch.
Neverwinter Nights: Enhanced Edition has been released! Visit nwn.beamdog.com to make an order. NWN:EE FAQ is available.
Soundtracks for BG:EE, SoD, BG2:EE, IWD:EE, PST:EE are now available in the Beamdog store.
Attention, new and old users! Please read the new rules of conduct for the forums, and we hope you enjoy your stay!

[Help] Script StartingConditional, if TRUE then..

KrazenpoxKrazenpox Member Posts: 12
edited March 10 in Builders - Scripting
Hello, I need some help with a script, during a dialog I'd like to check if the player has an item in his inventory, if TRUE then destroy it and reward the player. With the script wizard I have created the simple conditional script:
#include "nw_i0_tool"

int StartingConditional()
{

    // Make sure the PC speaker has these items in their inventory
    if(!HasItem(GetPCSpeaker(), "teteproprio"))

        return FALSE;



    return TRUE;

}
I don't know how to add the fact that if the player has the item, it will destroy it and give him reward. Is it possible? Thanks for your help :)


PS: Is there an active community or forum about scripting help for newbies like me?

Comments

  • Sylvus_MoonbowSylvus_Moonbow Member Posts: 951
    edited March 10
    When you are in a conversation use the red scripting hat (scripts wizard) that appears under the actions taken portions of the convo. Check give rewards and take from the player together. Go through the sets involved for giving a reward (gold, xp, item) and then the next option will be what you want to take. Then save the script so it does both of these things for you.

    It looks like you only checked take from the player to make that script.

    squattingmonk
  • KrazenpoxKrazenpox Member Posts: 12
    edited March 10
    The solution was so simple! I was thick headed with that script I didn't thank there was other solutions, thank you Sylvus_Moonbow :)
    (Sorry for my approximative english :blush: ).

  • squattingmonksquattingmonk Member Posts: 56
    Krazenpox said:

    PS: Is there an active community or forum about scripting help for newbies like me?

    Certainly! For a script reference, see the NWN Lexicon. And for the most community help, see the Neverwinter Vault.

  • BalkothBalkoth Member Posts: 111
    If you want to learn how to get that result without using the script wizard, let us know. I know I at a minimum would be happy to help explain how it works.

    squattingmonk
  • KrazenpoxKrazenpox Member Posts: 12
    Yes, I'd like to know how to have the same result with one script, what have I to add in the script to get something like: if the condition is TRUE then reward and destroy object, if FALSE nothing happen..? Thanks.

  • BalkothBalkoth Member Posts: 111
    edited March 12
    I'm going to give the simple version and then a more complicated one. Also, please don't get all "YOU'RE BEING INEFFICIENT!" on me. I know this can be done more cleanly with less code -- but I'm trying to be very explicit for someone new at this.

    Simple Version

    Your goal is: if the condition is true then reward and destroy object, if false then nothing happens. For this we'll use the actions taken condition (aka, this happens when you trigger this part of the conversation).

    First, our "pseudocode"...

    if PC has item then
    reward PC
    destroy item

    else
    nothing

    Now, our real code...
    void main()
    {
        // Who are we checking?
        object oPC = GetPCSpeaker();
    
        // What are we checking?
        object oItem = GetItemPossessedBy(oPC, "teteproprio");
    
        // If the item is valid, then the PC must have it
        if (oItem != OBJECT_INVALID)
        {
            // What are we doing if the PC has the thing?
    
            // First we'll reward
            // This gives the PC 10,000 gold
            GiveGoldToCreature(oPC, 10000);
            // This gives the PC 500 XP
            GiveXPToCreature(oPC, 500);
            // This needs a valid blueprint reference to work but then creates a
            // reward item on the PC
            CreateItemOnObject("awesomereward", oPC);
    
            // Now we'll destroy the item
            DestroyObject(oItem);
        }
    
        // Since we don't need to do anything special if the PC lacks the item,
        // that's the end of our code -- nothing will happen at this point
    }
    }
    Now let's get fancier.

    Complicated Version

    What if we don't want the reward script to fire UNLESS the PC has the item? We're going to use the "Text Appears When" tab for this and make a new script there:
    int StartingConditional()
    {
        // Who are we checking?
        object oPC = GetPCSpeaker();
    
        // Get a value of true (1) or false (0) for whether the PC has the item
        int nHasItem = GetIsObjectValid(GetItemPossessedBy(oPC, "teteproprio"));
    
        // return our value -- if it's false, the PC can't ever claim to have the item
        return nHasItem;
    }
    We put this script on a line (in the Text Appears When section) the PC gets like "Hey, I found that thing for you" and it won't appear as an option unless the PC has actually done so. Then put the first script on the Actions Taken to strip the item from the PC and reward the PC appropriately.

    If you'd like a clearer example, I can whip up a simple module showing a basic conversation like this if you want to poke around in it (though probably not tonight, busy rewriting the Aielund Saga's weapon enchanted scripts to be cleaner and work with up to four henchmen).

    Post edited by Balkoth on
    squattingmonk
  • DazDaz Member Posts: 15
    int nHasItem = GetItemPossessedBy(oPC, "teteproprio");

    should be

    int nHasItem = GetIsObjectValid(GetItemPossessedBy(oPC, "teteproprio"));

    squattingmonkBalkoth
  • BalkothBalkoth Member Posts: 111
    That's what I get for typing that up in a rush without testing it in the toolset. Had another error or two in the main script as well. Was busy rewriting the enchanting scripts for Aielund, in my defense >.>

  • squattingmonksquattingmonk Member Posts: 56
    Balkoth said:

    We put this script on a line (in the Text Appears When section) the PC gets like "Hey, I found that thing for you" and it won't appear as an option unless the PC has actually done so. Then put the first script on the Actions Taken to strip the item from the PC and reward the PC appropriately.

    This leaves you open to an exploit, though: the PC can have the item and get the prompt, then drop the item while still in conversation, then select the conversation option and obtain the reward. Then pick the item back up and do it all over again.

    A way around this would be to make the script that does the item removal and reward actually be placed on the Text Appears When node for the NPC:
    int StartingConditional() { object oPC = GetPCSpeaker(); object oItem = GetItemPossessedBy(oPC, "teteproprio"); if (GetIsObjectValid(oItem)) { GiveGoldToCreature(oPC, 10000); GiveXPToCreature(oPC, 500); CreateItemOnObject("awesomereward", oPC); DestroyObject(oItem); return TRUE; } return FALSE; }
    So you're looking at:
    NPC: Have you got the foo?
    |-> PC: I sure do have the foo! (item check as StartingConditional)
    | |-> NPC: Thanks for bringing me the foo. (reward script as StartingConditional)
    | |-> NPC: Sorry, it looks like you don't actually have the foo.
    |-> PC: No, I don't have the foo.

    Balkoth
  • KrazenpoxKrazenpox Member Posts: 12
    Thanks for these explanations guys! I will try this last script in my next quest :)

  • BalkothBalkoth Member Posts: 111
    Let us know if you have any problems. I can throw together a small module to show how to do it if you'd like.

    This leaves you open to an exploit, though: the PC can have the item and get the prompt, then drop the item while still in conversation, then select the conversation option and obtain the reward.

    Fair point.

    That said, unless this is for a PW (which wasn't said) I wouldn't worry too much about a deliberate exploit like this. If someone is determined to cheat, DebugMode is a hell of a lot easier. So if it's a major pain to fix a deliberate exploit, better to spend your time being productive. This isn't too bad of a case, though, and I wasn't thinking with security in mind since it seemed unnecessary.

    squattingmonk
  • TarotRedhandTarotRedhand Member Posts: 477
    FWIW I included a pdf document that lists 230+ starting conditional scripts that are already part of NwN, as part of my TR's Basics - Variables, Types and Functions (TBC) tutorial package on the vault.

    TR

    Sylvus_Moonbowsquattingmonk
Sign In or Register to comment.