Englisch Move an image away from a player

6 Antworten
Gehe zu Seite
Zum Anfang Vorherige 1 Nächste Zum Anfang
Hoch
Goo
User
Offline Off
Code:
1
2
3
4
5
6
7
8
local x, y, rot = player(id,"x"), player(id,"y"), player(id,"rot")
local Arrow = image('gfx/terraria/equipment/special/Arrow.png', 3, 0, 1)
imagepos(Arrow, x, y, rot)
x = PLAYERS[id].MOUSEX
y = PLAYERS[id].MOUSEY
tween_move(Arrow, 10000, x, y, rot)
tween_alpha(Arrow, 5000, 0)
timer(5000, 'freeimage', Arrow)


Currently this is a code I use inside an attack hook.
• The code is supposed to:
√ Show an image at the player's position.
× Move the image away like a bullet would.
√ Slowly fade away the image.

But the tween_move doesn't move the image to the right position (currently set on a random variable so ignore the
x =
and
y =
below
imagepos
)

Does anyone know what x and y variables I'm supposed to use?
05.12.18 06:07:58
Hoch
-3Jlou_nTu4-
User
Offline Off
You need use
Code:
1
2
player(id_of_player, "mousemapx")
player(id_of_player, "mousemapy")


Because, if you try use that:
Code:
1
2
player(id_of_player, "mousex")
player(id_of_player, "mousey")

then you will get the offset in pixels relative to the upper left corner of the client area of the game window, and not the coordinates of the map, as in the first case
05.12.18 07:17:17
Hoch
Goo
User
Offline Off
I do not want to use the player's mouse rather I want it to move a given amount of pixels away from the player.
05.12.18 08:20:25
Hoch
-3Jlou_nTu4-
User
Offline Off
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
local IM_EFFECT_MSECS = 3000     --how long image will be move in milliseconds
local IM_EFFECT_OFFSETX = 0     --position to which the image will be moved from "center" position
local IM_EFFECT_OFFSETY = -30
local IM_EFFECT_CENTERX = 0     --"center" position, (0, 0) - position of player
local IM_EFFECT_CENTERY = 0

local im = {}

function effectIm(param)
     param = tonumber(param)
     local pImEl = im[param]

     local time = IM_EFFECT_MSECS / 10
     local distX = IM_EFFECT_OFFSETX/time * (time-pImEl.timer)
     local distY = IM_EFFECT_OFFSETY/time * (time-pImEl.timer)

     if pImEl then
          imagepos(pImEl.id,
               player(param, "x") + IM_EFFECT_CENTERX + distX,
               player(param, "y") + IM_EFFECT_CENTERY + distY,
               0
          )
          tween_move(
               pImEl.id,
               IM_EFFECT_MSECS,
               player(param, "x")+IM_EFFECT_OFFSETX,
               player(param, "y")+IM_EFFECT_OFFSETY
          )
          pImEl.timer = pImEl.timer - 1
          if pImEl.timer==0 then
               freeimage(pImEl.id)
               pImEl.id = nil
          end
     end
end

function fillIm(plid)
     if plid and im[plid] then
          if im[plid].id then
               freetimer("effectIm", tostring(plid))
               freeimage(im[plid].id)
               im[plid].id = nil
          end
          im[plid] = {
               id = image("gfx/gametitle.png", 0, 0, 3),
               timer = IM_EFFECT_MSECS / 10,
          }
     end
end

function startImEffect(plid)
     if plid>=#im then
          table.insert(im, {id = nil, timer = 0})
     end

     fillIm(plid)
     timer(10, "effectIm", tostring(plid), IM_EFFECT_MSECS / 10)
end
05.12.18 08:30:45
Hoch
Goo
User
Offline Off
What I mean't is that the image is supposed to move like a bullet would, that means it doesn't stick to player it leaves the player and moves to the direction the player is looking at.

Imagine the image is a bullet that came out of a gun that's how the image is supposed to move.
05.12.18 09:07:59
Hoch
-3Jlou_nTu4-
User
Offline Off
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
addhook("attack", "attack_proc")

local IM_MAXDIST = 8     --the maximum distance(in tiles) the image will go through and then disappear
local IM_PATH = "gfx/cursor.bmp"

function imMoveLikeBullet_free(param)
     local imId = tonumber(param)
     if imId then
          freeimage(imId)
     end
end

function imMoveLikeBullet(plid)
     if plid and player(plid, "exists") and player(plid, "health")>0 then
          local imId = image(IM_PATH, 0, 0, 3)
          local rot = player(plid, "rot")
          local targX = player(plid, "x") + (32 * IM_MAXDIST) * math.sin(math.rad(rot))
          local targY = player(plid, "y") - (32 * IM_MAXDIST) * math.cos(math.rad(rot))
          imagepos(imId, player(plid, "x"), player(plid, "y"), rot)
          tween_move(imId, 100, targX, targY)
          timer(100, "imMoveLikeBullet_free", tostring(imId), 1)
     end
end

function attack_proc(plid)
     imMoveLikeBullet(plid)
end
05.12.18 09:23:37
Hoch
Goo
User
Offline Off
Thanks! It works.
Zum Anfang Vorherige 1 Nächste Zum Anfang