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

Scripting error.


Recommended Posts

This is the first script I've had problems with in a long time.
Can someone help?

Script:
```
' Executes when a player presses the CONTROL key.
Sub OnAttack(Index, Damage)
Dim Target

If Int(Damage) > 0 Then
If GetPlayerClass (Target) = GetPlayerClass (Index) Then
Call PlayerMsg (Index, "Don't attack your allies")
Else
If Int(GetPlayerTarget(Index)) > 0 Then
Target = GetPlayerTarget(Index)
Call DamagePlayer(Index, Target, Damage)
Else
Target = GetPlayerTargetNpc(Index)
Call DamageNPC(Index, Target, Damage)
End If
End If
End If
End Sub
```
Link to comment
Share on other sites

First, don't put spaces between the sub name and the parameters. For example, this:

```
If GetPlayerClass (Target) = GetPlayerClass (Index) Then
```
Should be:

```
If GetPlayerClass(Target) = GetPlayerClass(Index) Then
```

Secondly, you forgot the color parameter on the PlayerMsg call.

```
Call PlayerMsg(index, "Don't attack your allies.", 4)
```

Third, you are using the variable "target" before it is given value, and before we know if the target even has a class (meaning that they are not an NPC, but a player). You need to restructure the sub like so:

```
' Executes when a player presses the CONTROL key.
Sub OnAttack(Index, Damage)
Dim Target

If Int(Damage) > 0 Then
If Int(GetPlayerTarget(Index)) > 0 Then
Target = GetPlayerTarget(Index)
If GetPlayerClass(Target) = GetPlayerClass(Index) Then
Call PlayerMsg(Index, "Don't attack your allies", 4)
Else
Call DamagePlayer(Index, Target, Damage)
End If
Else
Target = GetPlayerTargetNpc(Index)
Call DamageNPC(Index, Target, Damage)
End If
End If
End 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...