Aller au contenu

Photo

Climbing a ladder script


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

#1
Daimondheart

Daimondheart
  • Members
  • 3 messages
Hello. I have a friend creating an area that has an indoor pool and she liked the idea of players using ladders to get into and out of the pool. The idea is to make the ladders useable items and attach a script that ports the player from one ladder to the other. I've been messing around with scripts for her since I know C language, but this is my first time scripting using the tool set and I'm lost. I've been trying to use the ga_jump function with little success. Can anyone help me out? Thank you for your time.

Modifié par Daimondheart, 28 août 2010 - 08:41 .


#2
Orion7486

Orion7486
  • Members
  • 161 messages
First put variables on each useable ladder.  This can be done within the placeables properties window in the variable field.  For the variable name use whatever you like.  In this example I use laddername.  In the value int field put 1.  For all other ladders, use the same variable name, but increase the int to 2, 3, etc.
In the onused script example:
void main()
{
    object oUser = GetLastUsedBy();
    object oWP1 = GetWaypointByTag("wp_ladder1");
    object oWP2 = GetWaypointByTag("wp_ladder2");
    object oWP3 = GetWaypointByTag("wp_ladder3");
    location lWP1 = GetLocation(oWP1);
    location lWP2 = GetLocation(oWP2);
    location lWP3 = GetLocation(oWP3);
    int nVar = GetLocalInt(OBJECT_SELF, "laddername");
 
   switch (nVar)
  {
     case 1:
     AssignCommand(oUser, ClearAllActions());
     AssignCommand(oUser, ActionJumpToLocation(lWP1));
   
    case 2:
     AssignCommand(oUser, ClearAllActions());
     AssignCommand(oUser, ActionJumpToLocation(lWP2));
   
    case 3:
     AssignCommand(oUser, ClearAllActions());
     AssignCommand(oUser, ActionJumpToLocation(lWP3));
   }
 
}
Thus the script will get the ladder's variable int of laddername is 1, it would jump the user to waypoint
wp_ladder1.  If the ladder variable was 2, it would jump user to wp_ladder2.
Have as many case lines as you have ladders.
Hope this works for you.

#3
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 585 messages
I use this script. The advantage over the prior script is that you don't need to keep track of ladders. Each ladder does require two waypoints, one at the top and one at the bottom. The script jumps the entire party, so you would have to change the JumpPartyToArea line to use ActionJumpToLocation if you wanted to just jump one character.



// bb_onused_climb
// by Brendan Bellina
// April, 2010

// Set to the onused OR onLeftClick script of an object to climb up or down.
// If set to both it will not work properly.
// If set to the OnLeftClick script it will work if either clicked or Used.
// Transports the player and party to the farther of two waypoints specified.
// The PC has to be within 3 meters of one of the waypoints.
// The waypoints are in variables sTopWP and sBottomWP.

#include "ginc_transition"

const float MINIMUM_TO_JUMP = 1.5;

void main()
{
     // Get the last user or clicker
     object oPC = GetLastUsedBy();
     object oClicker = GetPlaceableLastClickedBy();
     if (GetIsObjectValid(oClicker))
          oPC = oClicker;

     if (GetIsPC(oPC))
     {
          string sTopWP = GetLocalString(OBJECT_SELF,"sTopWP");
          string sBottomWP = GetLocalString(OBJECT_SELF,"sBottomWP");
     
          object oTopWP = GetObjectByTag(sTopWP); // GetWaypointByTag won't work here
          object oBottomWP = GetObjectByTag(sBottomWP); // GetWaypointByTag won't work here
     
          // Verify the waypoints are valid - if not do nothing
          if(GetIsObjectValid(oTopWP) && GetIsObjectValid(oBottomWP))
          {               
               float fDistanceToTopWP = GetDistanceBetween(oPC, oTopWP);
               float fDistanceToBottomWP = GetDistanceBetween(oPC, oBottomWP);
               
               if (fDistanceToTopWP <= MINIMUM_TO_JUMP || fDistanceToBottomWP <= MINIMUM_TO_JUMP)
               {
                    // Jump to the WP that is farthest away
                    object oTarget = (fDistanceToTopWP > fDistanceToBottomWP ? oTopWP : oBottomWP);
               //     AssignCommand(oPC, SpeakString("Jumping to " + GetTag(oTarget)));
                    JumpPartyToArea(oPC, oTarget);
               }
          }
     }
}



Regards