Jump to content

Teleporting Weapon Script - Not working.


iyumichan

Recommended Posts

This is my script.

 

scn badluck

int targetx
int targety
int targetz
int playerx
int playery
int zwx
int zwy
int betc 
ref thetarget

Begin OnHit

Set thetarget to (GetOwnerLastTarget)
If  (thetarget.IsActor == 1)
Set targetx to (thetarget.getpos x)
Set targety to (thetarget.getpos y)
Set targetz to (thetarget.getpos z)
Set playerx to (player.getpos x)
Set playery to (player.getpos y)
Set targetz to (targetz + 20)
Set zwx to (playerx - targetx)
Set zwy to (playery - targety)
Set betc to (zwx*zwx + zwy*zwy)
Set betc to (sqrt betc)
Set zwx to ((1/betc)*zwx)
Set zwy to ((1/betc)*zwy)
Set targetx to ((1/75)*zwx)
Set targety to ((1/75)*zwy)

Player.SetPos x targetx
Player.SetPos y targety
Player.SetPos z targetz

EndIf

END

 

The problem is that it always teleports to the same location even tho player and target are moving.

Link to comment
Share on other sites

You should use floats for all of these:

int targetx
int targety
int targetz
int playerx
int playery
int zwx
int zwy
int betc

 

((1/betc) * zwx) and ((1/betc)*zwy) will always be zero because betc, being the hypotenuse, will always be larger that zwx and zwy. Int's(shorts) round down to the nearest whole number (0 in this case).

 

Also, betc can be obtained in a simpler manner:

set betc to target.GetDistance Player

Link to comment
Share on other sites

Thanks a lot.

 

I had to change some of the math as well.

Now it is just awesome :D

 

scn badluck

float targetx
float targety
float targetz
ref targetref

Begin OnHit

Set targetref to (GetOwnerLastTarget)
If  (targetref.IsActor == 1)
Set targetz to ((targetref.getpos z) + 10)
Set targetx to ((targetref.getpos x)+((150/(targetref.GetDistance Player))*((player.getpos x) - (targetref.getpos x))))
Set targety to ((targetref.getpos y)+((150/(targetref.GetDistance Player))*((player.getpos y) - (targetref.getpos y))))

Player.SetPos x targetx
Player.SetPos y targety
Player.SetPos z targetz

EndIf

END

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...