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

How can i fix this script?


VitinhooxD
 Share

Recommended Posts

Hi everybody!
I new with SadScript and could someone help me with my first script?
I have trouble with a part of my rank system script.
Here it goes a part of him

Sub OnNPCDeath(Index, Map, NPCNum, NPCIndex)

Call BattleMsg(Index, "You killed a " & getnpcname(NPCNum) & ".", BRIGHTRED, 0)

                  Call PutVar("Accounts\" & GetPlayerName(index) & ".ini" ,"RANKSYSTEM" ,"points",  + 1)
End Sub

' Executes when a player is killed by another.
' Note: Death occurs as normal externally to this script.
Sub OnPVPDeath(Attacker, Victim)

Call GlobalMsg(GetPlayerName(Victim) & " has been killed by " & GetPlayerName(Attacker), BRIGHTRED)

                  Call PutVar("Accounts\" & GetPlayerName(Attacker) & ".ini" ,"RANKSYSTEM" ,"points", - 1)
End Sub

It doesn't works the part that add a point or subtracr a point when the player kills a npc / a player.
COuld someone help me? thanks
Link to comment
Share on other sites

This won't work:
```
Call PutVar("Accounts\" & GetPlayerName(index) & ".ini" ,"RANKSYSTEM" ,"points",  + 1)
```Because you're trying to put the text "+1" into that ini, and sadscript will get confused; if anything, you will always have either the number "1" or the number "-1" in there; it doesn't know what you're trying to do.

Try this:
```
Sub OnNPCDeath(Index, Map, NPCNum, NPCIndex)
  Dim Points

  Points = GetVar("Accounts\" & GetPlayerName(Attacker) & ".ini" ,"RANKSYSTEM" ,"points")
  If Points = "" Then
      Call PutVar("Accounts\" & GetPlayerName(index) & ".ini" ,"RANKSYSTEM" ,"points", "1")
  Else
      Points = Int(Points) + 1
      Call PutVar("Accounts\" & GetPlayerName(index) & ".ini" ,"RANKSYSTEM" ,"points", Points)
  End If
  Call BattleMsg(Index, "You killed a " & GetNpcName(NPCNum) & ".", BRIGHTRED, 0)
End Sub

' Executes when a player is killed by another.
' Note: Death occurs as normal externally to this script.
Sub OnPVPDeath(Attacker, Victim)
  Dim Points

  Points = GetVar("Accounts\" & GetPlayerName(Attacker) & ".ini" ,"RANKSYSTEM" ,"points")
  If Points = "" Then
      Call PutVar("Accounts\" & GetPlayerName(index) & ".ini" ,"RANKSYSTEM" ,"points", "-1")
  Else
      Points = Int(Points) - 1
      Call PutVar("Accounts\" & GetPlayerName(index) & ".ini" ,"RANKSYSTEM" ,"points", Points)
  End If

  Call GlobalMsg(GetPlayerName(Victim) & " has been killed by " & GetPlayerName(Attacker), BRIGHTRED)
End Sub
```
Link to comment
Share on other sites

Yea, I made afew logical errors; try this:
```
Sub OnNPCDeath(Index, Map, NPCNum, NPCIndex)
  Dim Points

  Points = GetVar("Accounts\" & GetPlayerName(index) & ".ini" ,"RANKSYSTEM" ,"points")
  If Points = "" Then
      Call PutVar("Accounts\" & GetPlayerName(index) & ".ini" ,"RANKSYSTEM" ,"points", "1")
  Else
      Points = Int(Points) + 1
      Call PutVar("Accounts\" & GetPlayerName(index) & ".ini" ,"RANKSYSTEM" ,"points", Points)
  End If
  Call BattleMsg(Index, "You killed a " & GetNpcName(NPCNum) & ".", BRIGHTRED, 0)
End Sub

' Executes when a player is killed by another.
' Note: Death occurs as normal externally to this script.
Sub OnPVPDeath(Attacker, Victim)
  Dim Points

  Points = GetVar("Accounts\" & GetPlayerName(Attacker) & ".ini" ,"RANKSYSTEM" ,"points")
  If Points = "" Then
      Call PutVar("Accounts\" & GetPlayerName(Attacker) & ".ini" ,"RANKSYSTEM" ,"points", "-1")
  Else
      Points = Int(Points) - 1
      Call PutVar("Accounts\" & GetPlayerName(Attacker) & ".ini" ,"RANKSYSTEM" ,"points", Points)
  End If

  Call GlobalMsg(GetPlayerName(Victim) & " has been killed by " & GetPlayerName(Attacker), BRIGHTRED)
End Sub
```
Link to comment
Share on other sites

@VitinhooxD:

> Still doesn't working , but i found the error .
>
> Call PutVar("Accounts\" & GetPlayerName(index) & ".ini" ,"RANKSYSTEM" ,"points", Points)
>
> The variable Points need to be called by & i think, but when i test with the "&" it still doesn't work =(

The ampersand is only used when combining multiple variables or strings (e.g. this would work: "Hi " & " there!").

But, you did remind me, that it needs to be a sting in there, so try this, for those:
Call PutVar("Accounts\" & GetPlayerName(index) & ".ini" ,"RANKSYSTEM" ,"points", "" & Points)

Also, is scripting turned on?
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...