Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Chatty NPC Help


KDawg08
 Share

Recommended Posts

Hey i am using a code that is old but the newer one doesn't work for me… I'm running on EE 2.7 but i'm trying to get my random NPC's i choose to Script 1 to chat with a random answer from Words.ini

Here is the script
```
          Case 1
            Dim Words
            Words=Rand(10,1)
            Call playermsg(index, GetVar("Words.ini", "Words", ""& Words &""), WHITE)
            Exit Sub

```
I have set all values in my npc as 1 as told before. But when i hit CTRL to talk to the npc it comes up with a blank response…
Basically if i type something and hit enter mine shows up, but when i try to get the NPC to respond via CTRL(Talk Control) it just gives me a blank space...

Any suggestions?

Here is what i did in Words.ini
[Words]
Words1= Test1
Words2= Test2
Words3= Test3
(I did this up to 10)
Link to comment
Share on other sites

That worked perfectly thank you…

now it says stuff like...

```
Hello
*Crys*
I lost my bracelet somewhere.
```
How do i get it to show up like this…
for example... NPC's NAME IS NPC1
```
NPC1: Hello
NPC1: *Crys*
NPC1: I lost my bracelet somewhere.
```
Basically make it show the npc's name before the text?
Link to comment
Share on other sites

You got me curious about this.  So far, I can tell that GetNpcName(NPCNum) is used to get the NPC's name, and GetMapNpcNum(mapnum, NPCindex) is used to get the NPC's number for the GetNpcName command, but I can't figure out how to get the NPC's index on that map, since it's not included in Sub ScriptedNpc, and attacking a scripted NPC won't make it your target, apparently…

If anyone has any ideas on the last bit, feel free to step in here.
Link to comment
Share on other sites

@DarkMazer:

> You got me curious about this.  So far, I can tell that GetNpcName(NPCNum) is used to get the NPC's name, and GetMapNpcNum(mapnum, NPCindex) is used to get the NPC's number for the GetNpcName command, but I can't figure out how to get the NPC's index on that map, since it's not included in Sub ScriptedNpc, and attacking a scripted NPC won't make it your target, apparently…
>
> If anyone has any ideas on the last bit, feel free to step in here.

Lol sweet i don't feel like a loner now :)
Link to comment
Share on other sites

It's a long process to determine the NPC, but it's possible.

Get the x and y coordinate of the space you are facing, run the coordinates against the coords of each of the NPCs on the map. If there is a match, get that NPC's index and plug in in through the GetNPCName function.

I'll throw some code down here in a sec.

```
x = GetPlayerX(index)
y = GetPlayerY(index)
m = GetPlayerMap(index)
Select Case GetPlayerDir(index)
Case 0
y = y - 1
Case 1
y = y + 1
Case 2
x = x - 1
Case 3
x = x + 1
End Select

z = 1
Do While z < 16
If GetNPCX(m, z) = x Then
If GetNPCY(m, z) = y Then
NpcName = GetNpcName(GetMapNpcNum(m, z))
End If
End If
z = z + 1
Loop
```
As a side note, it's an easy addition to the source to add an NPCNum parameter. I did this to my ScriptedNPC and ScriptedItems to make things more versatile.
Link to comment
Share on other sites

No, that merely sets the variable. You'd still have to add that variable to the message. This would all go in ScriptedNpcs.

Like so:

```
Case 1
x = GetPlayerX(index)
y = GetPlayerY(index)
m = GetPlayerMap(index)
Select Case GetPlayerDir(index)
Case 0
y = y - 1
Case 1
y = y + 1
Case 2
x = x - 1
Case 3
x = x + 1
End Select

z = 1
Do While z < 16
  If GetNPCX(m, z) = x Then
    If GetNPCY(m, z) = y Then
      NpcName = GetNpcName(GetMapNpcNum(m, z))
    End If
  End If
  z = z + 1
Loop

Words=Rand(1,10)
Call playermsg(index, Trim(NpcName) & ": " & GetVar("Words.ini", "Words", "Words"& Words), WHITE)
Exit Sub
```
Link to comment
Share on other sites

@KDawg08:

> so with this script it'll be Case 1 as it is now, BUT the extra case #'s on there are for each seperate NPC? and they walk around so… would that be a problem also?

The "extra cases", as you call them, is for "Select Case GetPlayerDir(index)"
Link to comment
Share on other sites

@KDawg08:

> so with this script it'll be Case 1 as it is now, BUT the extra case #'s on there are for each seperate NPC? and they walk around so… would that be a problem also?

They're nested select case statements.  The ones on the inside don't affect the ones on the outside at all.

The script executes the moment you hit them with an attack, so the only reasons this script shouldn't work are if you're attacking them from a distance, or if your server has really bad lag.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...