Green Bottles Posted August 3, 2008 Author Share Posted August 3, 2008 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 IfEnd Sub``` Link to comment Share on other sites More sharing options...
balliztik1 Posted August 3, 2008 Share Posted August 3, 2008 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 IfEnd Sub``` Link to comment Share on other sites More sharing options...
Green Bottles Posted August 3, 2008 Author Share Posted August 3, 2008 Ok thanks Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now