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

So, what is the problem with this Scripts for my NPC's? [Sloved]


adr990
 Share

Recommended Posts

Hello everyone,

I've been struggling with this for a while now.
I can't get my NPC's to work if they are Scripted:
```
End Sub

' Executes whenever a scripted NPC does an action.
Sub ScriptedNPC(Index, Script)
Select Case Script
Case 0
Call PlayerMsg(Index, "This scripted NPC has no apparent use.", WHITE)
Exit Sub

Case Else
Call PlayerMsg(Index, "No NPC script found. Please contact an admin to solve this problem.", WHITE)   

        Case 1
            Call PlayerMsg (Index, "Hello " & GetPlayerName(Index) & ", how are you?", WHITE)

        Case 2
            Dim Words
            Words=Rand(27,1)
            Call playermsg(index, GetVar("Words.ini", "Words", ""& Words &""), 14)
            Exit Sub
End Select
End Sub

' Executed whenever a slash command is sent to the server.
```
Case 0 = Script 0
Case 1 = Script 1 -Etc, right?

Words.ini is in the Sever folder Root. by the way.

If I put the NPC on Friendly and put some text into Speak, they do work. (Have things set to 1 instead of 0, as supposed to get them to work as Friendly.)

Now, can anyone see what's wrong with the scripts?
If I need to post my whole Main.txt, that's no problem.

Thanks in advance,
Adr990
Link to comment
Share on other sites

Hello

I have had a quick look at your script, I haven't had a chance to test this, I just fixed some obvious mistakes

```
    Sub ScriptedNPC(ByVal Index, ByVal Script)
        Select Case Script
            Case 0
                Call PlayerMsg(Index, "This scripted NPC has no apparent use.", WHITE)
                Exit Sub

            Case 1
                Call PlayerMsg(Index, "Hello " & GetPlayerName(Index) & ", how are you?", WHITE)
                Exit Sub

            Case 2
                Dim Words
                Words = Rand(27, 1)
                Call playermsg(index, GetVar("Words.ini", "Words", "" & Words & ""), 14)
                Exit Sub

            Case Else
                Call PlayerMsg(Index, "No NPC script found. Please contact an admin to solve this problem.", WHITE)
                Exit Sub
        End Select
    End Sub

```
You had missed out several "Exit Sub" terminators and you also had your "Case Else" statement before your other cases. The "Case Else" statement must be the last case statement in your "Select case" statement. This is because the "Case Else" statement is called if none of the other case statements conditions are met.

Please let me know if this works!

Yours sincerely
cloudwolf00
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...