Author Topic: Looking for some assitance  (Read 421 times)

Legacy_carlosjuero

  • Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
Looking for some assitance
« on: December 13, 2010, 02:11:58 pm »


               Howdy folks, I need some assitance from a script guru.

I am creating a small module right now and want to have a simplified achlemy system (NPC vendor based), the player will be able to "pick" certain environmental items up and use them to get potions/healing kits/etc.

Here is an example, in a cave there are patches of mushrooms (Brown Mushrooms, Large Group), I first tried to give them an inventory and have the item (Brown Toadstool) be in there - the pathing tried to take the PC to the center of the patch though and never opened up the inventory.

I then hit on the idea for using the Click event, this worked but you could be across the map and I wanted the PC to be right next to it so I added a distance check - the problem now is that clicking on it will have the PC run up to it and stop, it has to be clicked again (Sometimes more than once) in order for the script to fire.

Here is the code (Placed in the OnClick object event):


void main()
{
    object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC);
    float fPCDistance = GetDistanceToObject(oPC);
    float fMaxDistance = IntToFloat(4);
    if (fPCDistance <= fMaxDistance)
    {
        SendMessageToPC(oPC, "You gather a toadstool");
        CreateItemOnObject("greentoadstool", oPC, 1);
        DestroyObject(OBJECT_SELF);
    }
}

I have it destroying itself so that it is like you picked the mushroom (and it avoids the need for having a local variable for each patch ). [oh, and ignore the blueprint resref saying "green".. >.> I made a mistake when creating the item.

I know I am likely missing something obvious and would really appreciate some help.

(Also, I want to display a small bit of text above the patch when picked so that there is on screen feedback, other than the message sent to the PC, about the action - the FloatingText function doesn't seem to be what I need (according to the reference) but I think I am wrong.. any insight?)
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Looking for some assitance
« Reply #1 on: December 13, 2010, 02:41:05 pm »


               I am currently not in a spot where I can open the toolset at. 
I would suggest that you look into useing actions from the onclicked event. 
Actions go into the PC's action que and are then done in the order they where recived.
From your on Clicked event. 
* have him walk to the shroom.  Useing the AvtionDoCommand
*Then check to make sure the shroom is still there, If not clear all actions.
*Pick the Shroom and place it in his inventory.
All of the above done with the  Function - ActionDoCommand
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
Looking for some assitance
« Reply #2 on: December 13, 2010, 03:58:54 pm »


               When I want to do something along these lines, I set up a script with a pseudo-heartbeat. If you don't know what that is, its simply a script that has a call to ExecuteScript itself after a certain period of time (DelayCommand).

Here's an example:

void main()
{
object oPC = GetClickingObject();
object oSelf = OBJECT_SELF;
float fDist = GetDistanceBetween(oPC, oSelf);
if(fDist > 2.0f) // Edit the distance you want here
      {
      AssignCommand(oPC, ClearAllActions());
      AssignCommand(oPC, ActionForceMoveToObject(oSelf, TRUE, 1.9f, 45.0f));
      // Begin Pseudo-Heartbeat by Delaying the Executing of this same script
      DelayCommand(1.0f, ExecuteScript("Get_Mushroom", oPC)); // Edit for script name
      return;
      }
else if(fDist <= 2.0f) // Edit the distance you want here
      {
      SendMessageToPC(oPC, "You gather a toadstool");
      CreateItemOnObject("greentoadstool", oPC, 1);
      DestroyObject(OBJECT_SELF);
      return;
      }
}

What it does is check the distance between the placeable (oSelf) and the PC. If that distance is greater than 2.0 (meters) then it will move the PC towards the shrooms. 1 second later the script will ExecuteScript itself and again check the distance between. If still greater than 2.0, continue moving PC towards shrooms and again ExecuteScript itself after 1 second. Rinse/repeat until the PC is within 2.0 meters of the placeable and at that point it will do the "give shrooms item" part.

Sorry, can't answer the "have it float a message" part of your question. I forget what you need to do in NWN1 to have placeables speak float strings.

Script above not tested in game but does compile.
               
               

               
            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Looking for some assitance
« Reply #3 on: December 13, 2010, 04:13:46 pm »


               When building, a vision that seems good may not if the amount of work involved for such a simple thing takes one the long way around.



Using the Fungus placeable is just as well and it won't give you these rewrites of clicking a placeable because its center point can't be accessed due to the walkmesh getting in the way.



Use SpeakString to parlay your message to the player. SendMessage goes to the HUD and if the player has it hidden, like I normally do when I play NWN, they'll never see it. FloatingText is just as bad because it zips by and if you miss it, you have to go and read it in the HUD screen. SpeakString stays above the character's head for much longer AND if the player wants to clean it off, TAB will do so.



If you're set on doing it the OnClick way, may I suggest not checking the distance but rather, a variable set on a trigger AROUND the placeable. This way the player can access the placeable OnClick even when they enter the trigger, regardless of direction or distance. You preset the distance on the trigger you draw around the placeable. OnEnter - set var to 1. OnExit - set var to 0. Only when the var is equal to 1 will the OnClick even fire and give the player the item.



Do you want the item they picked to respawn after a day or two? Something else to think about if you're having the player trek back through this area. They could pick a few more the next time around.



FP!
               
               

               
            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
Looking for some assitance
« Reply #4 on: December 13, 2010, 04:36:49 pm »


               Just make a invisible placeable right near where you want to have it and make that the spot the PC goes to pick it up is the easier fix for this.


Another way to do it is just make the placeable have inventory and when the player picks it have it destroy itself on closed. This too is a simple way to do it.

void main()
{
    object oPC = GetLastOpenedBy();
    if (!GetIsPC(oPC) || GetIsDM(oPC)) return;
    object oTarget = OBJECT_SELF;
    DestroyObject(oTarget, 0.0);
}



If you want to respawn it just add in a respawn timer.

void CreateMe(location lLocation)
{
    CreateObject(OBJECT_TYPE_PLACEABLE, "uz_skelbones1", lLocation, TRUE);
}
void main()
{
    object oPC = GetLastOpenedBy();
location lLoc = GetLocation(OBJECT_SELF);
    if (!GetIsPC(oPC) || GetIsDM(oPC)) return;
    object oTarget = OBJECT_SELF;
    DestroyObject(oTarget, 0.0);

float fSeconds = 6000.0; //container respawn time
   AssignCommand(GetArea(OBJECT_SELF), DelayCommand(fSeconds, CreateMe(lLoc)));
}

This is done out of memory and not been checked in the compiler using Uz's old placeable scripts
               
               

               


                     Modifié par TSMDude, 13 décembre 2010 - 04:49 .
                     
                  


            

Legacy_carlosjuero

  • Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
Looking for some assitance
« Reply #5 on: December 13, 2010, 04:40:19 pm »


               Thanks for all the tips folks '<img'>



@Lightfoot8 - Thanks, I didn't even think of a move action *doh*

@_Knightmare_ - Never thought about doing a pseudo heartbeat and I haven't played with the ExecuteScript function before - didn't think about the possibilities of combining them.



@FesterPot - Honestly I didn't even notice the Fungus placeable, guess that will teach me to not pay attention. I think I like the idea of using the mushroom patches (if I can get it working decently) so that it fits in with the surrounding decor (thoug I may use fungus as another item). I can't believe I didn't consider using a trigger, or even think about re-spawning after a certain amount of time. Good thing I don't do this professionally eh? '<img'> - How would the respawn work? Checking the time past with the area's OnEnter?



Thanks again to those who have given some insight - guess I may be trying to over-reach my bounds for a small module :/
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Looking for some assitance
« Reply #6 on: December 13, 2010, 05:10:26 pm »


               FP and TSM have what I regard as the only proper fix for this, because of how much easier it is than any other alternative. Placeables default to having their use nodes in the center of the model, unless the maker thought to put them closer to one side. As a result, many will not be reachable when a pc makes the attempt. In such cases, if you have your heart set on that particular appearance, simply use an invisible object placeable placed on top - they ARE useable, and the player can't tell the difference. This is by FAR the lowest time-cost alternative, and is very simple, both of which, in my eyes, make it the best solution.



That said, I recently coded a !search command, which uses on OnActivate item and looks for nearby waypoints. I can share that code, if you like.



Funky
               
               

               
            

Legacy_eeriegeek

  • Jr. Member
  • **
  • Posts: 75
  • Karma: +0/-0
Looking for some assitance
« Reply #7 on: December 13, 2010, 05:21:10 pm »


               I have to second TSMDude's advice. Using the small invisible placeable with an inventory is very easy. It lets you use any placeable and place the invisible object near the edge and oriented so the player can access it easily. It highlights nicely when the player presses the tab key and you can change the description to describe the fungus. Another nice thing you can do with this approach is make a tileset feature behave like a placeable. Just place the invisible placeable carefully with the x,y,z location and you can make the shrooms in the caves tileset or the crypts in the crypts tileset useable and so on.

               
               

               
            

Legacy_carlosjuero

  • Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
Looking for some assitance
« Reply #8 on: December 13, 2010, 05:28:04 pm »


               Thanks again, I am going to try the trigger idea but am liking the idea of the invisible object - I tried having one in the beginning of the module for acting as a DM speaking to the PC but I couldn't get it working (figured out later it might just have been a typo on my part in a script call).



Gotta love that the NWN builder community is so danged helpful even after so many years of the game being out.



I am sure I will have more questions on topics, I really want to get a module together after having tons of false starts [mainly just to prove to myself I can do it but also to add another play module out there for folks]
               
               

               
            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
Looking for some assitance
« Reply #9 on: December 13, 2010, 10:53:47 pm »


               I have found that the onused event works better than the onclick event.. (double click symtoms) for scripts.  



e.g. there is a rain barrel script on the vault that goes in the onopen event..it would do a speak string when opened but  need to be opened twice for it to fire .I reworked it with what little script knowledge I have and put it in the onused.No more double clicking ..
               
               

               
            

Legacy_carlosjuero

  • Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
Looking for some assitance
« Reply #10 on: December 13, 2010, 11:34:10 pm »


               @Knight_Shield - the OnUsed event won't work for the large mushroom patch due to the use "node" being dead center of the mass with the surrounding being NoPass area.