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

Why wont this work?


rboeger93
 Share

Recommended Posts

ok I wrote a script that will basically be an alternate attack that will hit a player and make them spin rapidly to make them stunned and dizzy. I got everything to work fine except for when I tried to make players be "stunned". can you please tell me what I did wrong?

```
sub stun(Index, Damage)
Dim npcnum
Dim target
dim npcx
dim npcy
dim playx
dim playy
dim stuntime

  npcnum = GetPlayerTargetNPC(Index)
npcx = getnpcx(getplayermap(index), npcnum)
npcy = getnpcy(getplayermap(index), npcnum)
playx = getplayerx(index)
playy = getplayery(index)
stuntime = 0

if getplayerdir(index) = 0 then
if playx = npcx or playx = getplayerx(getplayertarget(index)) then
if playy - 1 = npcy or playy - 1 = getplayery(getplayertarget(index)) then
if getplayertarget(index) > 0 then
target = getplayertarget(index)
call damageplayer(index, target, damage)
Call SpellAnim(4, GetPlayerMap(index), playx, GetNpcY(GetPlayerMap(index), npcnum))
Call SpellAnim(4, GetPlayerMap(index), playx, playy - 1)
do while stuntime < 50
stuntime = stuntime + 1
select case getplayerdir(target)
case 0
call setplayerdir(target, 1)
call sendplayerdata(target)
case 1
call setplayerdir(target, 2)
call sendplayerdata(target)
case 2
call setplayerdir(target, 3)
call sendplayerdata(target)
case else
call setplayerdir(target, 0)
call sendplayerdata(target)
end select
call settimer("stuntimer " & index, 100)
loop
else
target = getplayertargetnpc(index)
call damagenpc(index, target, damage)
Call SpellAnim(4, GetPlayerMap(index), playx, GetNpcY(GetPlayerMap(index), npcnum))
Call SpellAnim(4, GetPlayerMap(index), playx, playy - 1)
end if
end if
end if
elseif getplayerdir(index) = 1 then
if playx = npcx or playx = getplayerx(getplayertarget(index)) then
if playy + 1 = npcy or playy + 1 = getplayery(getplayertarget(index)) then
if getplayertarget(index) > 0 then
target = getplayertarget(index)
call damageplayer(index, target, damage)
Call SpellAnim(4, GetPlayerMap(index), playx, GetNpcY(GetPlayerMap(index), npcnum))
Call SpellAnim(4, GetPlayerMap(index), playx, playy + 1)
do while stuntime < 50
stuntime = stuntime + 1
select case getplayerdir(target)
case 0
call setplayerdir(target, 1)
call sendplayerdata(target)
case 1
call setplayerdir(target, 2)
call sendplayerdata(target)
case 2
call setplayerdir(target, 3)
call sendplayerdata(target)
case else
call setplayerdir(target, 0)
call sendplayerdata(target)
end select
call settimer("stuntimer " & index, 100)
loop
else
target = getplayertargetnpc(index)
call damagenpc(index, target, damage)
Call SpellAnim(4, GetPlayerMap(index), playx, GetNpcY(GetPlayerMap(index), npcnum))
Call SpellAnim(4, GetPlayerMap(index), playx, playy + 1)
end if
end if
end if
elseif getplayerdir(index) = 2 then
if playy = npcy or playy = getplayery(getplayertarget(index)) then
if playx - 1 = npcx or playx - 1 = getplayerx(getplayertarget(index)) then
if getplayertarget(index) > 0 then
target = getplayertarget(index)
call damageplayer(index, target, damage)
Call SpellAnim(4, GetPlayerMap(index), GetNpcX(GetPlayerMap(index), npcnum), playy)
Call SpellAnim(4, GetPlayerMap(index), playx - 1, playy(index))
do while stuntime < 50
stuntime = stuntime + 1
select case getplayerdir(target)
case 0
call setplayerdir(target, 1)
call sendplayerdata(target)
case 1
call setplayerdir(target, 2)
call sendplayerdata(target)
case 2
call setplayerdir(target, 3)
call sendplayerdata(target)
case else
call setplayerdir(target, 0)
call sendplayerdata(target)
end select
call settimer("stuntimer " & index, 100)
loop
else
target = getplayertargetnpc(index)
call damagenpc(index, target, damage)
Call SpellAnim(4, GetPlayerMap(index), GetNpcX(GetPlayerMap(index), npcnum), playy)
Call SpellAnim(4, GetPlayerMap(index), playx - 1, playy)
end if
end if
end if
else
if playy = npcy or playy = getplayery(getplayertarget(index)) then
if playx + 1 = npcx or playx + 1 = getplayerx(getplayertarget(index)) then
if getplayertarget(index) > 0 then
target = getplayertarget(index)
call damageplayer(index, target, damage)
Call SpellAnim(4, GetPlayerMap(index), GetNpcX(GetPlayerMap(index), npcnum), playy)
Call SpellAnim(4, GetPlayerMap(index), playx + 1, playy)
do while stuntime < 50
stuntime = stuntime + 1
select case getplayerdir(target)
case 0
call setplayerdir(target, 1)
call sendplayerdata(target)
case 1
call setplayerdir(target, 2)
call sendplayerdata(target)
case 2
call setplayerdir(target, 3)
call sendplayerdata(target)
case else
call setplayerdir(target, 0)
call sendplayerdata(target)
end select
call settimer("stuntimer " & index, 100)
loop
else
target = getplayertargetnpc(index)
call damagenpc(index, target, damage)
Call SpellAnim(4, GetPlayerMap(index), GetNpcX(GetPlayerMap(index), npcnum), playy)
Call SpellAnim(4, GetPlayerMap(index), playx + 1, playy)
end if
end if
end if
end if
End Sub

sub stundelay(index)
stunwait = 0
call battlemsg(index, "You can now use Stun!", white, 0)
call removetimer("stundelay " & index)
end sub

sub stuntimer(index)
call removetimer("stuntimer " & index)
end sub
```
that is my sub for the attack. and I call it like this:

```
Sub HotScript(Index, KeyID)
Select Case KeyID
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Executes when any player presses the PageUp key.
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Case 1
'STUN ATTACK CALLED!
if stunwait = 0 then
Call stun(Index, 5)
call battlemsg(index, "You have used Stun!", white, 0)
stunwait = 1
call settimer("stundelay " & index, 5000)
else
call battlemsg(index, "You must wait to use that skill!", brightred, 0)
end if
'STUN ATTACK ENDED!
' Executes when any player presses the Delete key.
Case 2
Call AreaEffect(index, 2, getplayermap(index))
' Executes when players press the End key.
Case 3
' Executes when players press the PageDown key.
Case 4
End Select
End Sub
```
if you find something wrong can you please tell me? ty :)
Link to comment
Share on other sites

you only gathered info for npcs…
```
npcnum = GetPlayerTargetNPC(Index)
npcx = getnpcx(getplayermap(index), npcnum)
npcy = getnpcy(getplayermap(index), npcnum)
playx = getplayerx(index)
playy = getplayery(index)
stuntime = 0

```
this is fine for "If getplayertarget(index)>1"

you should then do an else and set to player values.
Link to comment
Share on other sites

ik….

you did the smart thing and use a variable for target values throughout the script so that you can change the target whenever and it still would work.

But you only have one option for them.

"npcnum = GetPlayerTargetNPC(Index)"

no where do you do something like
npcnum = GetPlayerTarget(Index)
so the rest of the script would ignore players.

You should really set it up more like this.

```
If GetPlayerTargetNPC(index)>0 Then
    Targetnum = GetPlayerTargetNPC(Index)
    Targetx = getnpcx(getplayermap(index), npcnum)
    Targety = getnpcy(getplayermap(index), npcnum)
Else
    Targetnum = GetPlayerTarget(Index)
    Targetx = GetPlayerX(Targetnum)
    Targety = GetPlayerY(Targetnum)
End If   
    playx = getplayerx(index)
    playy = getplayery(index)

```
Link to comment
Share on other sites

ok ty for the advice, ill be sure to change that. but is that why its not working? like as of right now, it wont even attack anyone, npc nor player. but it worked before I attempted the stun part of it. so its probably something with the changing direction. maybe I forgot to do something, Iunno. but I will try changing the dims.
Link to comment
Share on other sites

well, Ive only tried it on npcs as of now.but it used to work fine on npcs, but once I added the do while loop, it stopped working.

edit: hmmmm I have no idea whats wrong with it. I've looked it over multiple times but it wont work. oh and wulf, It turns out I already changed the target and everything later on in the script, so its fine.
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...