Aller au contenu

Photo

Heartbeat floaty text not working


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

#1
Morbane

Morbane
  • Members
  • 1 883 messages
 I am trying to get random floaty text to appear when the pc is close to a npc:

#2
Morbane

Morbane
  • Members
  • 1 883 messages
void main()
{
object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC);

string sGreet;
int nRand = Random(5);

switch(nRand)
{
case 0: sGreet = "Hello " + GetName(oPC);
break;
case 1: sGreet = "Nice day huh?";
break;
case 2: sGreet = "Heya " + GetName(oPC);
break;
case 3: sGreet = "Excuse me " + GetName(oPC) + "I didn't see you.";
break;
case 4: sGreet = "Morbannon is looking for you.";
break;
case 5: sGreet = GetName(oPC) + " spread that gold around a bit huh?";
break;
}


if(GetDistanceToObject(oPC) <= 8.0f)
{
FloatingTextStringOnCreature(sGreet, OBJECT_SELF, FALSE);
}
}

But nothing happens. What am I missing?

Modifié par Morbane, 07 avril 2011 - 12:53 .


#3
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
Try it with GetFirstPC(), just to see if it works.

#4
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
FloatingTextStringOnCreature() doesn't work on non-PCs, use SpeakString() instead. Also, case 5 for you will never show. Random() is # -1, so Random(5) produces numbers between 0 and 4. Change this to Random(6) for generating numbers between 0 and 5. Lastly, you might want to set this up as a pseudo-heartbeat, a PC can go quite a distance in a 6 second heartbeat round. So as it is, they could walk up and it might take like 5 seconds for the NPC to say something depending on the timing. When I am checking distance like this, I run a 1 or 2 second pseudo-heartbeat.

Modifié par _Knightmare_, 07 avril 2011 - 02:17 .


#5
Morbane

Morbane
  • Members
  • 1 883 messages
SpeakString() did the trick - the pseudo hb was a bit much - the hit or miss randomness is fine....

Thanks KM!

#6
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 598 messages
I use this user-defined event script to have animals bark out lines. You could also use it with a merchant. The lines are pulled from a conversation rather than being hard-coded in the script. This way you can use the same script with multiple NPC's and have unique conversations. I use a slightly more complicated script for my merchants so that they can equip a torch at night if they have one in inventory.

Regards

// bb_barker_animal_ud
// by Brendan Bellina
// June, 2008
//
// User Defined script to allow a creature to callout barkstrings

// Useful for animals

void DoBark(object oSpeaker=OBJECT_SELF)
{
// if bb_barkConv is specified then use that
// else if ConversationPrefix is specified use ConversationPrefix + SpeakerTag
// else use "00_bark_" + SpeakerTag
// The reason the NPC's conversation is not used is because it is reserved for
// non-barking.
string sConversation = GetLocalString(oSpeaker, "bb_barkConv");
if (sConversation == "")
{
string sConversationPrefix = GetLocalString(oSpeaker, "ConversationPrefix");
if (sConversationPrefix == "")
sConversationPrefix = "00_bark_";

sConversation = sConversationPrefix + GetTag(oSpeaker);
}
AssignCommand(oSpeaker, SpeakOneLinerConversation(sConversation));
}

void main()
{
int nEvent = GetUserDefinedEventNumber();

switch(nEvent)
{
case EVENT_HEARTBEAT: // 1001
if (GetAILevel(OBJECT_SELF) == AI_LEVEL_VERY_LOW)
return;
if (Random(3) == 1) DelayCommand(IntToFloat(Random(4)), DoBark());
break;
}

ExecuteScript("nw_c2_defaultd", OBJECT_SELF);
}

Modifié par Kaldor Silverwand, 07 avril 2011 - 08:25 .


#7
Dann-J

Dann-J
  • Members
  • 3 161 messages
If you put the distance check near the top of the HB script, then you can 'return' immediately on a failed check (>8.0). If you have a lot of NPCs running the same HB then it might just speed performance up very slightly.

Also - int nRand = Random(5)+1; will get you numbers 1 to 5.