Author Topic: i'm rusty... some help please...  (Read 333 times)

Legacy_zero-feeling

  • Sr. Member
  • ****
  • Posts: 287
  • Karma: +0/-0
i'm rusty... some help please...
« on: October 21, 2012, 08:32:47 pm »


               so it's been a while since i did any kind of building in NWN toolset (3 years), but i'm back at it working on a new project. i've never been all that great at scripting to begin with, so these should be simple enough to fix by anyone here, so if i could get a bit of help with these two scrips, it would be awsome.

script #1

take heavy rope from player and create a hanging rope in front of them:
////////////////////////it_rope_hang////////////////////////
void main(){object oPC;
if (!GetIsPC(GetItemActivatedTarget())){
SendMessageToPC(GetItemActivator(), "Improper use of item!");return;}
object oTarget;object oSpawn;location lTarget;oPC = GetItemActivator();
oTarget = oPC;
lTarget = GetLocation(oTarget);
oSpawn = CreateObject(OBJECT_TYPE_PLACEABLE, "plot_hang_rope", lTarget);
object oItem;oItem = GetItemPossessedBy(oPC, "heavy_rope");
if (GetIsObjectValid(oItem))   DestroyObject(oItem);
}
-this script needs to have a check added so only the player that made the hanging rope can use it, possibly adding some kind of indication it's that players rope (players name on the rope, color change, ect...)




script #2


move the player to new location when they use thier hanging rope:
/////////////////////////it_rope_swing/////////////////////////
//put this OnUsedvoid main(){
object oPC = GetLastUsedBy();
if (!GetIsPC(oPC)) return;
if (GetLocalInt(oPC, "players_name")!= 1)   return;
object oTarget;location lTarget;oTarget = GetWaypointByTag("cliff_west");
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;
SetLocalLocation(oPC, "ls_stored_loc", GetLocation(oPC));
AssignCommand(oPC, ClearAllActions());
AssignCommand(oPC, ActionJumpToLocation(lTarget));
oTarget = GetObjectByTag("plot_hang_rope");
DestroyObject(oTarget, 0.0);
CreateItemOnObject("heavy_rope", oPC);
}
-need to make sure only the player that created the rope can use it-need to make a check so ithe player goes to the cliff_wp opposite of where he is (cliff_west / cliff_east)

also, if anyone wants to do more "involved" scripting, i have a bunch of great ideas i could use the help with.
               
               

               
            

Legacy_Daybringer

  • Newbie
  • *
  • Posts: 22
  • Karma: +0/-0
i'm rusty... some help please...
« Reply #1 on: October 22, 2012, 12:20:03 pm »


               (Sorry, forum issue ignore this post)
               
               

               


                     Modifié par Daybringer, 22 octobre 2012 - 11:25 .
                     
                  


            

Legacy_Daybringer

  • Newbie
  • *
  • Posts: 22
  • Karma: +0/-0
i'm rusty... some help please...
« Reply #2 on: October 22, 2012, 12:25:03 pm »


               O_o;;; uhh it... randomly condensed I'll try ... pasting it in quick reply instead...

script #1

void main()
{
object oPC = GetItemActivator();
location lTarget = GetLocation(oPC);
object oSpawn = CreateObject(OBJECT_TYPE_PLACEABLE, "plot_hang_rope", lTarget);
object oItem = GetItemActivated();
string nName = GetName(oPC);
SetName(oSpawn, GetName(oSpawn)+" "+nName);
SetLocalString(oSpawn, "user", nName);
if (GetIsObjectValid(oItem)) {DestroyObject(oItem);}
}


Right, some excessive lines in your script; cleaned it up for you ^_~ also you need to make it so the item is self targeting only ^_~ the less script and the less chance for confusion, the better off things will be. The placables name will change but this is a buggy feature of nwn and will only work now and again, especially when you leave and re-enter the area. It should otherwise work as you described/wished.


void main()
{
string sActivator = GetLocalString(OBJECT_SELF, "user");
object oPC = GetLastUsedBy();
if (GetName(oPC) == sActivator)
   {
    //object oTarget = GetWaypointByTag("cliff_west"); <-the get waypoint command is module wide - not what you want
   object oTarget = GetNearestObject(OBJECT_TYPE_WAYPOINT, oPC);
   if (oTarget != OBJECT_INVALID)
   {
       string sTag = (GetTag(oTarget));
       if (sTag == "cliff_west" || sTag == "cliff_east")
       {
           if (sTag == "cliff_west")
              {oTarget = GetWaypointByTag("cliff_east");}
           if (sTag == "cliff_east")
              {oTarget = GetWaypointByTag("cliff_west");}
           location lTarget = GetLocation(oTarget);
           //SetLocalLocation(oPC, "ls_stored_loc", GetLocation(oPC)); <- I don't know why you had this line if its just going back and forth
           AssignCommand(oPC, ClearAllActions());
           AssignCommand(oPC, ActionJumpToLocation(lTarget));
       }
   }
   oTarget = GetObjectByTag("plot_hang_rope");
   DestroyObject(oTarget, 0.0);
   CreateItemOnObject("heavy_rope", oPC);
   return;
   }
SendMessageToPC(oPC, "This Rope doesn't belong to you");
}
               
               

               
            

Legacy_zero-feeling

  • Sr. Member
  • ****
  • Posts: 287
  • Karma: +0/-0
i'm rusty... some help please...
« Reply #3 on: October 27, 2012, 02:23:52 am »


               The placables name will change but this is a buggy feature of nwn and will only work now and again, especially when you leave and re-enter the area

well for this, the rope is meant to be a one time thing until called for again. so for example, the player uses the rope in their inventory to create the rope needed to get to the other side of the cliff. the rope gets removed from their invrntory and becomes a hanging rope. (eg: zero's rope) this rope should only be able to be used by the player zero. once that player uses the rope, it is destroyed from the hanging placeable form and placed back in to their inventory as it was before use. this should be the complete cycle.

i haven't had a chance to test the script you have above, but will as soon as i can. if that script is/does something other than the above explination, could you (or anyone else) please make it so?

thanks, zero
               
               

               
            

Legacy_zero-feeling

  • Sr. Member
  • ****
  • Posts: 287
  • Karma: +0/-0
i'm rusty... some help please...
« Reply #4 on: October 28, 2012, 07:23:08 am »


               so got to test it, made the hanging rope "plot_hang_rope" (placeable), made the inventory rope "heavy_rope" (misc medeum), made the scripts above, put the second script in the OnUsed line for the hanging rope "plot_hang_rope" (placeable), compiled both scripts without errors, then tested them out....

my only problem is the hanging rope "plot_hang_rope" (placeable) doesn't spawn next to the player. should it maybe be spawned a foot in front of the player? 3 feet?

i could use some help with this please.
               
               

               
            

Legacy_Pearls

  • Full Member
  • ***
  • Posts: 194
  • Karma: +0/-0
i'm rusty... some help please...
« Reply #5 on: October 28, 2012, 09:58:32 am »


               can you explain in steps what youre trying to do?

is it this

1. player uses placeable, placeable can only be used by 1 player at a time

2. player using rope is moved to waypoint location

3. player spawns placeable at location of their choice
               
               

               
            

Legacy_zero-feeling

  • Sr. Member
  • ****
  • Posts: 287
  • Karma: +0/-0
i'm rusty... some help please...
« Reply #6 on: October 28, 2012, 08:00:53 pm »


               yeah, sorry if my ramblings above aren't clear enough. here is exactly what i want to happen.

1. player moves to the area designated as the "rope area". **this will be a trigger called rope_trigger
2. player uses the rope item in their inventory (tag is heavy_rope). **activate item is used in properties of the item.
3. doing this will fire the first script. when this happens, the rope item in the players inventory should be destroyed and a hanging rope placeable (tag is plot_hang_rope) should be created in front of the player with that players name on it. (ie. zero's rope)
4. once the placeable item has been created, it should only be able to be used by the player that created the rope. (in this case zero)
5. once the player uses the rope (this will fire the second script) **this script is in the OnUsed slot, they will be moved to a waypoint on the opposite side of a cliff from where they stand. **waypoint tags will be cliff_east and cliff_west.
6. once the player has been moved to the opposite waypoint, the placeable rope should be destroyed (zero's rope) and the rope item should be created back in the players inventory (heavy rope).

that is what i want. i hope this explains it in enough detail. i appreciate the help.
               
               

               


                     Modifié par zero-feeling, 28 octobre 2012 - 08:02 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
i'm rusty... some help please...
« Reply #7 on: October 30, 2012, 02:07:09 am »


               I'm also a bit rusty but something like so perhaps?

useable rope item script (tag_based):

#include "x2_inc_switches"
void main()
{
    int iEvent = GetUserDefinedItemEventNumber();
    if (iEvent != X2_ITEM_EVENT_ACTIVATE) return;

    object oPC = GetItemActivator();
    object oRopeItem = GetItemActivated();
    //this is just example of int check. If player enters a trigger and an int
    //named "TRIGGER_ENTER" is set TRUE:
    int iEntered = GetLocalInt(oPC, "TRIGGER_ENTER");

    if (iEntered)//if TRUE
    {
        //These are just example locations but you can define whatever locations
        //you need to create the rope placeable at:
        //location lRopeLoc = GetLocation(oPC);
        location lRopeLoc = GetLocation(GetWaypointByTag("tag of waypoint here"));
        object oRopePlace = CreateObject(OBJECT_TYPE_PLACEABLE, "rope res ref here", lRopeLoc);
        string sName = GetName(oPC);
        SetLocalString(oRopePlace, "USER", sName);
        DestroyObject(oRopeItem, 0.1);
    }
    else
    {
        SendMessageToPC(oPC, "You are not at a valid location to use this item.");
    }
}


and the placeable rope object (OnUsed) script:

void main()
{
    object oPC = GetLastUsedBy();
    string sName = GetName(oPC);
    string sCheck = GetLocalString(OBJECT_SELF, "USER");

    if (sName == sCheck)
    {
        object oDest = GetWaypointByTag("tag of destination wp");
        if (GetIsObjectValid(oDest))
        {
            SetLocalInt(oPC, "TRIGGER_ENTER", FALSE);
            AssignCommand(oPC, ActionJumpToObject(oDest));
            CreateItemOnObject("res ref of rope item here", oPC);
            DestroyObject(OBJECT_SELF, 1.0);//might need to mess with this delay
        }
        else
        {
            SendMessageToPC(oPC, "There is no valid destination.");
            return;
        }
    }
    else
    {
        SendMessageToPC(oPC, "This rope does not belong to you. You can not use it at this time.");
    }
}



You will need to fill in some res refs and mess with the locations of the rope object and the destination but maybe this can get you started in the right direction. I probably forgot something since this is not tested.

Good Luck.
               
               

               


                     Modifié par GhostOfGod, 30 octobre 2012 - 02:10 .
                     
                  


            

Legacy_zero-feeling

  • Sr. Member
  • ****
  • Posts: 287
  • Karma: +0/-0
i'm rusty... some help please...
« Reply #8 on: October 30, 2012, 06:29:24 am »


               *smashes head on desk* hi ghost *continues to smash head*

i realize i didn't mention there will be 2 waypoints to swing to in the second reply, so i apologize. i think that the second script posted by daybringer might be more what i'm looking for on that end, my only problem was no placeable rope was appearing to use/test. i will however test the first script you have made. then maybe i can try daybringers second script.

i will post my findings. thanks again.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
i'm rusty... some help please...
« Reply #9 on: October 30, 2012, 05:05:33 pm »


               So I probably should have read through all the replies more thoroughly before i posted '<img'>. Some of the simplest reasons the ropes not appearing:
-using tag instead of res ref
-misspelled the res ref
-using res ref of a copy that was set down in area instead of the actual palette res ref
-a condition not being met (if/else).

Just some thoughts. Hope you get it working for ya. Good luck.