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

What am I doing wrong - Scripted Spell


Recommended Posts

Well, I have to face the fact that I'm going to have to get spells working one way or another, and I figured, why not just script them?
Now, I'm at a loss….

What's wrong with this scripted spell?  It's just suppose to take 3 HP away from a player or NPC... It can target a player fine, and zap the player fine, but it doesn't show the animation.
I don't think it's doing anything for the NPC at all...
```
'~~~~~~~~~~~~~~~~~
' Spells
'~~~~~~~~~~~~~~~~~
Sub epicspell(index)
dim mp
mp = 5
dim target
if getplayermp(index) >= mp then
if getplayertarget(index) > 0 then
target = getplayertarget(index)
call DamagePlayer(index, target, 3)
call spellanim(getplayermap(target), getplayerX(target), getplayerY(target), 61)
mp = getplayermp(index) - 5
call setplayermp(index, mp)
else
if getplayertarget(index) < 0 then
target = getplayertargetnpc(index)
Call DamagePlayer(index, target, 3)
call spellanim(getplayermap(target), getplayerx(target), getplayery(target), 61)
mp = getplayermp(index) - 5
call setplayermp(index, mp)
end if
end if
else
call playermsg(index, "You need 5 MP!", 1)
end if
end sub
```
EDIT: Crap, I just realized that I'm trying to deduct the NPC's HP with a damagePlayer command… That wouldn't work, would it?
If that's the case, what command can I use to dmg the NPC?  And what am I doing wrong with the animation (I think I need to change the animation command for the NPC, but the player one isn't working either)
Link to comment
Share on other sites

Admiral, look around this area:

if getplayertarget(index) < 0 then
            target = getplayertargetnpc(index)
            Call DamagePlayer(index, target, 3)
            call spellanim(getplayermap(target), **getplayerx(target), getplayery(target)**, 61)
            mp = getplayermp(index) - 5
            call setplayermp(index, mp)

try replacing that with something like this:

getplayertarget(Map, X, Y)

or you can try this:

X = GetVar("Classes\Class" & ClassID & ".ini", "CLASS", "x")
Y = GetVar("Classes\Class" & ClassID & ".ini", "CLASS", "y")

try replacing that, and if it does not work, please reply.
Link to comment
Share on other sites

you need to call this to damage a npc

```
DamageNPC(index, target, 3)
```

then to call the spell animation you would need to do something like this instead

```
Call SpellAnim(GetPlayerMap(index),GetNpcX(mapnum,npcnum) , GetNpcY(mapnum,npcnum), 61)
```
mapnum = the map the npc is on

npcnum = the number of the npc

Try to "Dim" everything in your Call SpellAnim(whatever) so it looks like Call SpellAnim(1, 2, 3, 4, 61) of course "1,2,3,4" being what you want them to be.. and 61 is the spellanim as you already know ;)

hope that helps you out

btw just wondering 2 things:
1:can this spell kill the player?
2: and does it take away the 5 mp ?
Link to comment
Share on other sites

Thanks for all your help so far!
Also Nubbs, yes it can kill players (I just used it on myself lol), and it does take away 5 mp (or whatever the var "mp" is).

You can now successfully attack the NPCs, but it's still not showing the animation.

Though, I did find that I was calling the animation wrong, and it should be:
Call SpellAnim(61, map, x, y)
But it's still not working (not for the npc, or the player)
Here's the updated spell:
```
'~~~~~~~~~~~~~~~~~
' Spells
'~~~~~~~~~~~~~~~~~
Sub epicspell(index)
   dim mp
   dim dmg
   dim anm
   dim target
   dim x
   dim y
   dim npc
   mp = 5
   map = getplayermap(index)
   dmg = 3
   anm = 61
   if getplayermp(index) >= mp then
      if getplayertarget(index) > 0 then
         target = getplayertarget(index)
         y = getplayerY(target)
         x = getplayerX(target)
         call DamagePlayer(index, target, dmg)
         Call SpellAnim(map, x, y, anm)
         mp = getplayermp(index) - mp
         call setplayermp(index, mp)
      else
         if getplayertarget(index) < 0 then
            target = getplayertargetnpc(index)
            npc = GetMapNPCnumber(map, target)
            y = GetNpcY(map, npc)
            x = GetNpcX(map, npc)
            Call DamageNPC(index, target, dmg)
            Call SpellAnim(map, x, y, anm)
            mp = getplayermp(index) - mp
            call setplayermp(index, mp)
         end if
      end if
   else
      call playermsg(index, "You need 5 MP!", 1)  
   end if
end sub
```
So I guess ~~two~~ a question~~s~~…
~~I **know** I'm not calling the animation correctly for the NPCs; I don't think I'm using the getmapnpcnumer right, nor am I using the GetNpcX or GetNpcY right…
How would I call the animation on the NPC correctly (since I don't know how to get the number)?~~

And of course, why isn't the spell animation working at all (player or npc)?

**EDIT:** I don't think I was calling the spell animation wrong…
**EDIT2:** I updated the spell abit
Link to comment
Share on other sites

you have target dimmed as target = GetPlayerTarget {which get the (enemy player) not the enemy npc you would need something like

target2 = getplayertargetnpc(index)

your (target) wont work since you have it dimmed twice as 2 different things let me see if i can write this for you..
Link to comment
Share on other sites

ok so if you have spell animation 61 then this should work on players but the npc part im still not sure about but it might work here's what i got .. sorry i havent tested it

```
~~~~~~~~~~~~~~~~~
' Spells
'~~~~~~~~~~~~~~~~~
Sub epicspell(index)

  Dim mp
  Dim dmg
  Dim anm
  Dim target
  Dim y
  Dim x
  Dim npcx
  Dim npcy
  Dim l
  Dim mob

  mp = 5
  dmg = 3
  anm = 61
  target = GetPlayerTarget(index)
  y = GetPlayerY(target)
  x = GetPlayerX(target) 
  npcx = GetNpcX(l , mob)
  npcy = GetNpcY(l , mob) 
  l = GetPlayerMap(index)
  mob = GetPlayerTargetNpc(index)

  If GetPlayerMP(index) >= mp Then
      If GetPlayerTarget(index) > 0 Then

        Call DamagePlayer(index, target, dmg)
        Call SpellAnim( anm, l, x, y))
        mp = GetPlayerMP(index) - mp
        Call SetPlayerMP(index, mp)
      Else
        If GetPlayerTargetNpc(index) < 0 Then           
            Call DamageNPC(index, mob, dmg)
            Call SpellAnim(map, npcx,npcy, anm)
            mp = GetPlayerMP(index) - mp
            Call SetPlayerMP(index, mp)
        End If
      End If
  Else
      Call PlayerMsg(index, "You need 5 MP!", 1) 
  End If
End Sub

```
Link to comment
Share on other sites

I was able to get it working correctly with the one you posted (had to swap afew vars), but the animation still isn't working.

Hmm… I wonder if the bugged spells is preventing the animation from showing...  Because both versions of those spells (mine and yours) work flawless (excluding the animation).
Link to comment
Share on other sites

@[SB:

> Nubbs aka mR. FahREnhEIT link=topic=40091.msg391910#msg391910 date=1236541854]
> a bug with scripted spell animations>? have you tried making yourself the target of the spell animation besides the player/npc ?

Yep
I take dmg, I loose MP, but I the animation doesn't show
Link to comment
Share on other sites

**I GOT IT WORK!**

Okay, finally, scripted spell script!

To figure out what I was doing wrong, I actually started using PlayerMsg to read the the vars, to make sure everything was saving right…
See the script below (fully works!)
```
'~~~~~~~~~~~~~~~~~
' Spells
'~~~~~~~~~~~~~~~~~
Sub epicspell(index)
  Dim mp
  Dim dmg
  Dim anm
  Dim target
  Dim x
  Dim y
  Dim npc
  mp = 1
  map = GetPlayerMap(index)
  dmg = 50
  anm = 3
  If GetPlayerMP(index) >= mp Then
      If GetPlayerTarget(index) > 0 Then
        target = GetPlayerTarget(index)
        y = GetPlayerY(target)
        x = GetPlayerX(target)
        Call DamagePlayer(index, target, dmg)
        Call SpellAnim(anm, map, x, y)
        Call PlaySound(index, "magic1.wav")
        mp = GetPlayerMP(index) - mp
        Call SetPlayerMP(index, mp)
      Else
        If GetPlayerTarget(index) < 0 Then
            target = GetPlayerTargetNpc(index)
            npc = GetMapNpcNumber(map, target)
            y = GetNpcY(map, target)
            x = GetNpcX(map, target)
            Call PlayerMsg(index, "Map is " & map & " Npc x is " & x & " Npc y is " & y & " npc number is " & npc & " okay", 1)
            Call DamageNPC(index, target, dmg)
            Call SpellAnim(anm, map, x, y)
            Call PlaySound(index, "magic1.wav")
            mp = GetPlayerMP(index) - mp
            Call SetPlayerMP(index, mp)
        End If
      End If
  Else
      Call PlayerMsg(index, "You need 5 MP!", 1) 
  End If
End Sub
```Once I make sure all the magic numbers are gone, I'll paste it in the script database!
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...