Skip to content

Help with circuit system

I've been trying to exercise my scripting by writing my own circuit system. It's basically a walkway system which allows random/non-random animations to be added as the creature reaches a waypoint. Everything goes in a single OnHeartBeat function and, up to now, it's been working great.

As soon as the creature starts moving from one waypoint to the other, an integer is checked so that the function won't override itself. When the movement and the animation is over, the integer resets and the next OnHB will trigger it again.

The thing is, if the creature is disturbed during the circuit, the integer will not reset and the system will just stop working. Is there simple way to replace this integer with another kind of check? Such as "is the creature moving/performing an animation"?

Any ideas are welcome.

Comments

  • TerrorbleTerrorble Member Posts: 169
    1. Creature assigned to go to waypoint and an Int is set to indicate they've been told so.
    2. Heartbeat continues to run, but doesn't act on this NPC because it has the Int set.
    3. NPC arrives and does some animation afterwhich the Int is reset so the NPC can accept new commands on future heartbeats.

    If you just need suggestions to get the ideas flowing then I'll throw this idea out. (this is untested, but the idea is there)


    Set the waypoint object the NPC should be going to on the NPC (at the same time you set the Int).
    SetLocalObject(oNPC,"WP_IM_GOING_TO",GetWaypointByTag("TAG_OF_WP"));

    The heartbeat could check the distance between the NPC and the waypoint and set that on the NPC if it hasn't already.
    If it has, then it can monitor if the distance between the two is decreasing.
    If the distance is staying the same or increasing over several iterations (and they aren't in combat), then tell them to get moving again.
    //Make sure we're not in combat and have a WP set that we should be going to
    		//**However you determine your NPC has arrived, be sure to delete the WP object when it has**\\
    if( !GetIsInCombat(oNPC)  && GetIsObjectValid(GetLocalObject(oNPC,"WP_IM_GOING_TO")) )
    {
    	
    	//If we haven't checked/set the distance we still need to go, then set it on the NPC
    	if( !GetLocalFloat(oNPC,"DistanceToGo") )
    	{
    		SetLocalFloat(oNPC,"DistanceToGo",GetDistanceBetween(oNPC,GetLocalObject(oNPC,"WP_IM_GOING_TO")));
    	}
    
    	//Otherwise, if the distance seems to be getting farther away or staying the same then increment an Int to say so.
    	else
    	if( GetDistanceBetween(oNPC,GetLocalObject(oNPC,"WP_IM_GOING_TO") >= GetLocalFloat(oNPC,"DistanceToGo") )
    	{
    		SetLocalInt(oNPC,"NotGettingCloser",	GetLocalInt(oNPC,"NotGettingCloser") + 1	);
    
    		//Update the current distance
    		SetLocalFloat(oNPC,"DistanceToGo",GetDistanceBetween(oNPC,GetLocalObject(oNPC,"WP_IM_GOING_TO")));		
    	}
    
    	
    	
    
    	//After a number of times of the NPC not getting any closer tell them to get back on track
    	if( GetLocalInt(oNPC,"NotGettingCloser") > 5 )
    	{
    		AssignCommand(oNPC, ClearAllActions());
    		DelayCommand(0.1,AssignCommand(oNPC,ActionMoveToObject(GetLocalObject("WP_IM_GOING_TO"))));
    
    		//Clean up this Int so this code segment won't run again right away.
    		DeleteLocalInt(oNPC,"NotGettingCloser");
    	}
    }
    
  • meaglynmeaglyn Member Posts: 149
    The default end conversation script is a call to walkwaypoints for exactly this sort of reason. You interrupt the walker and they need to replan. You can put something in the various handlers to do the same thing. Onconversation, maybe one of the combat events etc. There are various ways to do it.

    [begin shameless plug] You can also checkout my advanced walkwaypoints system which expands the builtin system with among other things the same sort of animation playing at waypoint that you are doing. [end shameless plug] :)

    If you do it in the HB you need to check for !incoversation (and !incombat) to keep them from walking away while you are talking to them.
Sign In or Register to comment.