Aller au contenu

Photo

script gods, once again i implore u!


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

#1
christinetooley

christinetooley
  • Members
  • 58 messages
 im in need of a way to place PLACEABLES at random waypoints in an area and have them regrow after a couple of hours when used. ive been working on this for a few days niw but am not worthy to wash the keyboards of you awesome script gods! please help and remember im no scripter. please explain a little on how the script would work or point me to the right script already in place. Many thanks in advance and praise be to you!

Modifié par christinetooley, 08 mars 2011 - 04:18 .


#2
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 598 messages
I don't have a script for this, sorry. My suggestions are:

To have the "random" placement, create 3 times the number of waypoints as you need in the area and tag them with a number (like "random_1", "random_2", ...). Then, one time only, in the on client enter script of the area randomly spawn your placeable in a third of the locations.

The regrowing part is probably trickier. In the on use script you could hide the placeable and set a variable on it indicating the time that it should be regrown. Then in the on heartbeat script of the area you can loop through the used ones and if the current time is equal to or exceeds the regrown time then unhide the placeable.

Regards

#3
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
Functions to get random locations ( from the csl position library, think it's originally a bioware script )
/**  
* Get the (roughly) center point of an area, can adjust for height.
* @author
* @param 
* @see 
* @return 
*/
location CSLGetCenterPointOfArea(object oArea, float fheightAdjust = 0.0f)
{
	// GetIsObjectValid(oArea);
	
	int iHeight = GetAreaSize( AREA_HEIGHT, oArea );
	if ( iHeight == 0 )
	{
		oArea = GetArea(oArea);
		iHeight = GetAreaSize( AREA_HEIGHT, oArea );
	}
	int iWidth = GetAreaSize( AREA_WIDTH, oArea );
	float fY = 10.0f;
	float fX = 10.0f;

	// convert to meters
	if ( GetIsAreaInterior( oArea ) )
	{
		fY = ( ( (iHeight* 9.0f) / 2) + 0.45f);
		fX = ( ( (iWidth*9.0f) / 2) + 0.45f);
	}
	else
	{
		fY =  ( ( (iHeight*10.0f) / 2) + 0.5f);
		fX =  ( ( (iWidth*10.0f) / 2) + 0.5f);
	}
	return Location(oArea, Vector(fX, fY, 0.0+fheightAdjust), 0.0f );
}

/**  
* Get a random location in a given area based on a given object,
* the specified distance away.
* If no object is given, will use a random object in the area.
* If that is not available, will use the roughly-center point
* of the area.
* If distance is <= to 0.0, a random distance will be used.
* @author
* @param 
* @see 
* @return 
*/
location CSLGetRandomLocation( object oArea, object oSource=OBJECT_INVALID, float fDist=0.0f )
{
	location lStart;
	
	if ( GetIsObjectValid( oSource ) == FALSE )
	{
		lStart = CSLGetCenterPointOfArea( oArea );
	}
	else
	{
		lStart = GetLocation( oSource );
	}
	
	// BMA-OEI 7/13/06 float precision
	if ( fDist <= 0.001f )
	{
		fDist = IntToFloat( Random( FloatToInt( SC_DISTANCE_HUGE - SC_DISTANCE_TINY ) * 10 ) ) / 10;
	}	
	
	float fAngle = IntToFloat( Random( 360 ) );
	float fOrient = IntToFloat( Random( 360 ) );
	location lRandLoc = CSLGenerateNewLocationFromLocation( lStart, fDist, fAngle, fOrient );
	
	return ( lRandLoc );
	
//    if (fDist == 0.0) {
//        int iRoll = Random(3);
//        switch (iRoll) {
//        case 0:
//            fDist = SC_DISTANCE_MEDIUM; break;
//        case 1:
 //           fDist = SC_DISTANCE_LARGE; break;
 //       case 2:
 //           fDist = SC_DISTANCE_HUGE; break;
 //       }
 //   }
//
//    fAngle = IntToFloat(Random(140) + 40);

}



#4
El Condoro

El Condoro
  • Members
  • 148 messages
Will the placeables all be the same (have the same resref) or be different?

#5
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
Will the player get something when the object is used? Is the object supposed to be destroyed after use? Maybe if you could explain what you want to happen exactly this could be a bit easier.
What I get from your post is something like... a plant, that when used by a player, gives the player an herb or berry or something an then the plant disappears.
If this is the case it can be done in the OnUsed event with a DelayCommand.

This is an example script(Note: This was done in NWN1 and is working):

const float RESPAWN_TIME = 10.0;//seconds till object respawns in rand location
const int NUM_OF_WPS = 3;//amount of random waypoints
const string WP_TAG = "PLANT_WP_";//this is the tag of your waypoints without the
                                 //number at the end. Example: if you give your
                                 //waypoints the tag "PLANT_WP_1", "PLANT_WP_2",
                                 //etc.., then WP_TAG should be "PLANT_WP_".
const string ITEM_GET = "nw_it_msmlmisc12";//NWN1 default fenberry res ref

void RespawnMe(string sResRef, location lLocation, string sNewTag)
{
    CreateObject(OBJECT_TYPE_PLACEABLE, sResRef, lLocation, FALSE, sNewTag);
}
void main()
{
    object oPC = GetLastUsedBy();
    string sMyResRef = GetResRef(OBJECT_SELF);
    object oArea = GetArea(OBJECT_SELF);
    int iRandom = Random(NUM_OF_WPS) + 1;
    string sWaypoint = WP_TAG + IntToString(iRandom);
    location lNewLoc = GetLocation(GetWaypointByTag(sWaypoint));
    string sMyTag = GetTag(OBJECT_SELF);

    AssignCommand(oArea, DelayCommand(RESPAWN_TIME, RespawnMe(sMyResRef, lNewLoc, sMyTag)));
    CreateItemOnObject(ITEM_GET, oPC);
    DestroyObject(OBJECT_SELF, 0.1);
}


Hopefully this is what you are looking for or at least gets things moving in the right direction.
Also not: If i remember correctly the function "GetWaypointByTag" wasn't working in NWN2? If it isn't then this function would just have to be replaced with "GetObjectByTag".

Modifié par GhostOfGod, 09 mars 2011 - 10:46 .


#6
Morbane

Morbane
  • Members
  • 1 883 messages
AFAIK GetWaypointByTag() works fine.

#7
christinetooley

christinetooley
  • Members
  • 58 messages
LOL! I used pieces of all of these and modified it a little. I'm no scripter but its working! Thank-you SOOO much!