Modifié par Daimondheart, 28 août 2010 - 08:41 .
Climbing a ladder script
Débuté par
Daimondheart
, août 28 2010 08:40
#1
Posté 28 août 2010 - 08:40
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.
#2
Posté 29 août 2010 - 12:55
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.
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
Posté 30 août 2010 - 09:39
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.
Regards
// 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





Retour en haut






