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

GetScriptedNpcName


pisopower
 Share

Recommended Posts

Hi all,
I've few days with eclipse,
¿there are any way to get name of scripted npc?

I think this function, but i not know if are better way.

Thanks :D

```
Function GetScriptedNpcName(Index) 
            Dim dir
            dir = GetPlayerDir(Index)
            dim masX
            dim masY
            If dir = 1 Then
                masX=0
                masY=1
            Else
                If dir = 2 Then
                    masX=-1
                    masY=0
                Else
                    If dir = 0 Then
                        masX=0
                        masY=-1
                    Else
                        If dir = 3 Then
                            masX=1
                            masY=0
                        End If
                    End If
                End If
            End If
                Dim cc
                cc = 1
                Do While cc < 20             
                If GetNpcX(GetPlayerMap(Index),cc) = (GetPlayerX(Index) + masX) Then
                    If GetNpcY(GetPlayerMap(Index),cc) = (GetPlayerY(Index) + masY) Then
                        GetScriptedNpcName =  GetNpcName(GetMapNpcNumber(1,cc))
                        cc = 20
                        'Exit Sub
                    End If
                End If
                cc = cc + 1
                Loop
End Function
```
(Edit:)
The line: GetScriptedNpcName =  GetNpcName(GetMapNpcNumber(1,cc))

is wrong, the correct is: GetScriptedNpcName =  GetNpcName(GetMapNpcNumber(GetPlayerMap(Index),cc))

down in other post is the correct script
Link to comment
Share on other sites

a ok,

im not sure if not are any function to do,

but, this are for a modification of random messages scripts:

```
Sub RandomNPCMsg(Index, NameNPC)
      Dim total
      total = GetVar("\Scripts\npcextras\RandomMsg.ini", "" & NameNPC & "" ,"total")
      Dim num
      num = rand(1,total)
      Dim msg
      msg = GetVar("\Scripts\npcextras\RandomMsg.ini", "" & NameNPC & "" ,"var" & num)
      Call PlayerMsg(Index,msg, WHITE)
End Sub
```
And RandomMsg.ini :

```
[RandomNpcMsg1]
total=2
var1=message1
var2=message2
...
[RandomNpcMsg2]
total=1
var1=probando1
...
```
But im seeing a fail, if a i have various npc with same name… , then i need GetScriptedNpcNum

Is funny eclipse xD

(The script is for have different npc random message in 1 script and 1 file, i see in tutorials some that are for only one, then for use less scripts)

sorry for my english
Link to comment
Share on other sites

I can understand him fine.

pisopower, is the random message script the only reason you would need to get the NPC's name?

Because you could just call it like this; in scripted NPCs:
```
Case 2
  Call RandomNPCMsg(Index, "Larry")
  Exit Sub
```Then, in the ini:
```
[Bobbie]
total=2
var1=message1
var2=message2
...
[Larry]
total=1
var1=probando1
...

```
Note that I'm passing the name manually, as a string, for that specific NPC.  I understand that it's not as automatic though; I think that is what you were striving for (so you do not have to make a new scripted npc case for each npc).

**EDIT:** Another alternative, and I think this would actually work better, would be something like this:

```
Case 2
  Dim Target
  Dim NpcName
  Target = Int(GetPlayerTargetNpc(Index))
  NpcName = CStr(GetNpcName(Target))
  Call RandomNPCMsg(Index, NpcName)
  Exit Sub

```
In almost every scenario where a scriptedNPC is activated, the player's target is going to be the last thing he attacked, which would be the scripted NPC.  So if you have an NPC named "Larry", and has script#2, and an NPC named "Bobbie" that has the same script, one will execute for Larry, the other for Bobbie.
I think this is what you wanted.
Link to comment
Share on other sites

Hi

but, if i do
```
Case 2
  Call RandomNPCMsg(Index, "Larry")
  Exit Sub
```I must use more than 1 script slot

and with

> Target = Int(GetPlayerTargetNpc(Index))
>             Call PlayerMsg(Index,Cstr(Target),YELLOW)
>             NpcName = CStr(GetNpcName(Target))

GetPlayerTargetNpc returns -1, and not have any result because any npc have -1 number.
¿Is this correct?

Then if this function is fine i can post this but i wanted an opinion before, thanks
Link to comment
Share on other sites

@pabloe:

> Hi
>
> but, if i do
> ```
> Case 2
>   Call RandomNPCMsg(Index, "Larry")
>   Exit Sub
> ```I must use more than 1 script slot

Yes, that is the problem with that method, as I said, you would need to use multiple instances, whereas your method is more automatic.

@pabloe:

> and with
>
> > Target = Int(GetPlayerTargetNpc(Index))
> >             Call PlayerMsg(Index,Cstr(Target),YELLOW)
> >             NpcName = CStr(GetNpcName(Target))
>
> GetPlayerTargetNpc returns -1, and not have any result because any npc have -1 number.
> ¿Is this correct?
>
> Then if this function is fine i can post this but i wanted an opinion before, thanks
> [/quote[
> It returns -1, when used on a scripted npc?
>
> Your function should work, but if a scripted NPC is activated by a player's arrow or if there are several npcs near the player, it may run into some issues.
Link to comment
Share on other sites

The random message is not activated with arrows, is good for me.

And i have found another funcionallity, with GetScriptedNPCName i prevent to activate npcs with arrows.

But, i found an error in the script of the first post, with the map index, that i have put it "1" , and is GetPlayerMap.

Then here is the script

```
Function GetScriptedNpcName(Index) 
            Dim dir
            dir = GetPlayerDir(Index)
            dim masX
            dim masY
            If dir = 1 Then
                masX=0
                masY=1
            Else
                If dir = 2 Then
                    masX=-1
                    masY=0
                Else
                    If dir = 0 Then
                        masX=0
                        masY=-1
                    Else
                        If dir = 3 Then
                            masX=1
                            masY=0
                        End If
                    End If
                End If
            End If
                Dim cc
                cc = 1
                Do While cc < 20             
                If GetNpcX(GetPlayerMap(Index),cc) = (GetPlayerX(Index) + masX) Then
                    If GetNpcY(GetPlayerMap(Index),cc) = (GetPlayerY(Index) + masY) Then
                        GetScriptedNpcName =  GetNpcName(GetMapNpcNumber(GetPlayerMap(Index),cc))
                        cc = 20
                        'Exit Sub
                    End If
                End If
                cc = cc + 1
                Loop
End Function
Sub RandomNPCMsg(Index, NameNPC)
      Dim total
      total = GetVar("\Scripts\npcextras\RandomMsg.ini", "" & NameNPC & "" ,"total")
      Dim num
      num = rand(1,total)
      Dim msg
      msg = GetVar("\Scripts\npcextras\RandomMsg.ini", "" & NameNPC & "" ,"var" & num)
      Call PlayerMsg(Index,msg, WHITE)
End Sub
```
The usage in ScriptedNpc(Index,Script):

```
Case 4
            'RANDOM Messages     
            Dim NameNPC
            NameNPC = GetScriptedNpcName(Index)
Call RandomNPCMsg(Index, NameNPC)
            Exit Sub 
```
Then put script to 4 in all random messages npcs.

The "\Scripts\npcextras\RandomMsg.ini" is this (in total, total of possible messages):
```
[NPCRandom1]
total=2
var1=message1
var2=message2
[NPCRandom2]
total=1
var1=message1
```
The other funcion is to prevent activate ScriptedNpc with arrow:

```
Case X
If GetScriptedNpcName(Index) = "Name_of_Npc" Then
Call PlayerMsg(Index,"This activated only near npc",GREEN)
End If

Exit Sub
```
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...