Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Actor Detector
Actor Detector
2005-09-05, 6:57 PM #1
I posted a question similar to this before, but I realized that the provided solution, though answered my question, was not what I needed.

I basically need to have a COG that will, on a timer, detect if there is an actor within a certain distance - this is so that a wandering actor will, if it passes any other wandering actor, will detect it. Is there a way to do this outside of arrays and for loops?
the idiot is the person who follows the idiot and your not following me your insulting me your following the path of a idiot so that makes you the idiot - LC Tusken
2005-09-05, 8:04 PM #2
In MotS there's a SendMessageExRadius or something like that which is really useful for that sort of thing. There's also enterBubble and exitBubble which can be used for detecting a space around an object. In JK I don't think there's any way to do it other than pulse a check on all actors in the other actor's sector. But, I'm a bit rusty, maybe someone else can do better.
Dreams of a dreamer from afar to a fardreamer.
2005-09-05, 8:32 PM #3
Code:
timer:
   player = GetLocalPlayerThing();
   thing= FirstThingInView(player, 45, 50, 0x404);
   CertainDistance = 10;
   distance = VectorDist(GetThingPos(player), GetThingPos(thing));

   if(distance < CertainDistance)
   {
       jkStringClear();                      
       jkStringConcatPlayerName(thing);
       jkStringConcatAsciiString(" is within ");
       jkStringConcatInt(CertainDistance);     
       jkStringConcatAsciiString(" JKU's, run for your life.");
       jkStringOutput(player, -1);
    }

Return;


Thing is the actor in question.
CertainDistance is whatever distance you want.

This could just as easily be put in a pulse, too.

I have not tested the above code but I believe it would work fine.

ReT
2005-09-06, 5:53 AM #4
That works for the actor; however, I want two wandering pedestrians to stop and "talk" to each other. Perhaps inserting code (adapted for the actor) into the actor COG?
the idiot is the person who follows the idiot and your not following me your insulting me your following the path of a idiot so that makes you the idiot - LC Tusken
2005-09-06, 8:25 AM #5
This would require triggers, because each actor needs to know what to say, which would probally be something different than the other person, because if you didn't use triggers, the two actors would be saying the same thing to each other, you know what I'm saying?
Code:
   if(distance < CertainDistance)
   {
       jkStringClear();                      
       jkStringConcatPlayerName(player);
       jkStringConcatAsciiString(" says 'Hello, ");
       jkStringConcatInt(thing);     
       jkStringConcatAsciiString(" how are you today?' ");
       jkStringOutput(-3, -3);
    }

Return;

Something like that is gonna be the best you can do, unless you figure out some sorta Trigger system. What you could do tho is, use IsServer() to find out of the local player is host, and then the conversation would change based on that, for example:
Code:
   if(distance < CertainDistance)
   {
       jkStringClear();                      
       jkStringConcatPlayerName(player);
       jkStringConcatAsciiString(" says 'Hello, ");
       jkStringConcatInt(thing);     
       jkStringConcatAsciiString(" how are you today?' ");
       if(IsServer())
       {
          Sleep(2.0);
          jkStringConcatPlayerName(player);
          jkStringConcatAsciiString(" says 'I am the host, and you are my slave.' ");
          jkStringConcatPlayerName(player);
          jkStringConcatAsciiString(" says 'Now I will ramble about my greatness.' ");
       }
       else
       {
          Sleep(4.0);
          jkStringConcatPlayerName(player);
          jkStringConcatAsciiString(" says 'Well since you are the host, I guess so' ");
          jkStringConcatPlayerName(player);
          jkStringConcatAsciiString(" says 'lol' ");
       }
       jkStringOutput(-3, -3);
   }
   
Return;


I dunno if that works or not ;) Just an idea though.
2005-09-06, 9:01 AM #6
I was thinking of simply generating a random number and then using some if/then statements to determine what's to be said. But would the code you first posted, when modified to suit an actor and inserted into the actor's COG, work?
the idiot is the person who follows the idiot and your not following me your insulting me your following the path of a idiot so that makes you the idiot - LC Tusken
2005-09-06, 9:35 AM #7
I thought about the random number idea too. ;) But yeah, that code should work just fine. Just stick it in a pulse somewhere.

[EDIT]I'm assuming you are referring the first bit of code in my last post? Yeah that should work. The Timer or Pulse will look like this:

Code:
timer:
   player = GetLocalPlayerThing();
   thing = FirstThingInView(player, 45, 50, 0x404);
   CertainDistance = 10;
   distance = VectorDist(GetThingPos(player), GetThingPos(thing));

   if(distance < CertainDistance)
   {
       jkStringClear();                      
       jkStringConcatPlayerName(player);
       jkStringConcatAsciiString(" says 'Hello, ");
       jkStringConcatInt(thing);     
       jkStringConcatAsciiString(" how are you today?' ");
       jkStringOutput(-3, -3);
    }

Return;


Until you implement the randomizing, they will just say the same thing to each other at the same time I think.
ReT

↑ Up to the top!