Forum

> > CS2D > Scripts > Image turning around player and changing size
Forums overviewCS2D overview Scripts overviewLog in to reply

English Image turning around player and changing size

35 replies
Page
To the start Previous 1 2 Next To the start

old Re: Image turning around player and changing size

Mami Tomoe
User Off Offline

Quote
I tried @user GeoB99: 's code on a brand new (!) cs2d folder and I got this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
UDP socket initialized using port 65024
U.S.G.N.: Your game version is up to date!
starting server...
UDP socket initialized using port 36963
load map 'de_dust'
----- Server started -----
parsing Lua server script (mp_luaserver = 'server.lua')
parsing Lua autorun script 'sys/lua/autorun/test.lua'
Lua: Adding function 'JoinHook' to hook 'join'
Lua: Adding function 'RoundEnd' to hook 'endround'
Lua: Adding function 'DieHook' to hook 'die'
Lua: Adding function 'LeavePlayer' to hook 'leave'
LUA ERROR: sys/lua/autorun/test.lua:2: attempt to index global 'Player' (a nil value)
 -> sys/lua/autorun/test.lua:2: in function <sys/lua/autorun/test.lua:1>
 -> in Lua hook 'join', params: 1
U.S.G.N.: Sending serverlist ADD-request...
U.S.G.N.: Server added to serverlist

And where do I check if rp_wanted[id]==true?

old Re: Image turning around player and changing size

Yates
Reviewer Off Offline

Quote
Please, please, PLEASE! Stop putting things in autorun!

If you keep on doing this eventually you will lead to errors because CS2D has NO IDEA in what order things should be loaded. Start using
dofile
in the
server.lua
file like a normal human being.

old Re: Image turning around player and changing size

Nekomata
User Off Offline

Quote
For the error generated on user GeoB99's script just add this to the top:
1
Player = {}

And yes, make use of dofile(). Autorun doesn't even output most of the errors which makes debugging frustrating.

All you need to do is put the script file in the same folder as server.lua and then open server.lua and dofile that script.
1
dofile('fraizeraustscript.lua')

old Re: Image turning around player and changing size

Mami Tomoe
User Off Offline

Quote
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
function Array(size,value) 
	local array = {}
	for i = 1, size do
		array[i]=value
	end
	return array
end

Player = {}
Player = Array(32,{})
test=true

function JoinHook(id)
   Player[id] = {} -- This table must be empty, do not change it!
end

function RotatingImage()
   if ( test==true ) then
      Player[id].image = image('gfx/cs2d.bmp', 10, 10, 200 + id) -- "gfx/cs2d.bmp" is only an example, you can change that with another image path
      tween_rotateconstantly(Player[id].image, 1)
   else
      freeimage(Player[id].image)
      Player[id].image = nil
   end
end

function RoundEnd()
   for _, All in pairs( player(0, 'tableliving') ) do
      if ( Player[All].image ) then
         freeimage(Player[All].image)
         Player[All].image = nil
      end
   end
end

function DieHook(victim)
   freeimage(Player[victim].image)
   Player[victim].image = nil
end

function LeavePlayer(id)
   freeimage(Player[id].image)
   Player[id].image = nil
end

addhook('join', 'JoinHook')
addhook('endround', 'RoundEnd')
addhook('die', 'DieHook')
addhook('leave', 'LeavePlayer')

I have no clue what I'm doing but this does nothing except adding the hooks...

@user Rainoth: I want a circle (image) around a player who has rp_wanted[id]==true, the image will rotate and grow bigger and smaller around him
Example:
IMG:https://i.imgur.com/RDdfjqo.png

old Re: Image turning around player and changing size

Masea
Super User Off Offline

Quote
user Mami Tomoe has written
@user Rainoth: I want a circle (image) around a player who has rp_wanted[id]==true, the image will rotate and grow bigger and smaller around him
Example:
IMG:https://i.imgur.com/RDdfjqo.png
Which can be done only with ms100, second or even always just because there is no actually scheduled hook, user Rainoth. Either when player get the "rp_wanted" parameter true but we don't know where we'll get it so.

old Re: Image turning around player and changing size

Gaios
Reviewer Off Offline

Quote
You all doing this wrong .. you should learn a CS2D's engine. Let me write the code.

It could be put in sys/lua/autorun .
Spoiler >


ms100 hook doesn't lags server, because in this case it's server-sided.
edited 3×, last 04.12.16 09:21:07 pm

old Re: Image turning around player and changing size

Mami Tomoe
User Off Offline

Quote
Thanks @user Gaios: I did the rest on my own like doing this:

Changing:
1
2
local imagePath = 'gfx/player/marker.bmp'
local resizeUpTo = 2.0

Adding (in cl.drawImage):
1
2
tween_alpha(cl.imageid, 0, 0.8)
tween_color(cl.imageid, 0, 255, 128, 128)

And now it works exactly how I want

Edit: OH NO
when restart script no work! its gone! plz help!

i try adding this but its no work!
1
2
3
4
5
addhook("startround","rp_startround")
function rp_startround()
	rp.variableCapture()
	rp.rotateImage(1)
end
what to do plz

old Re: Image turning around player and changing size

Gaios
Reviewer Off Offline

Quote
It works only for 1 player with
cool[id] = true
. Mad, forgot about other players .

Replace it:
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
addhook('ms100', 'gajos_coolImage.variableCapture')
function cl.variableCapture()
	for _, id in pairs(player(0, 'table')) do
		if cool then
			if cool[id] and not cl.var_cool then
				cl.var_cool = true
				cl.drawImage(id)
				return
			elseif not cool[id] and cl.var_cool then
				cl.var_cool = false
				cl.removeImage(id)
				return
			end
		end
	end
end

addhook('startround', 'gajos_coolImage.reload')
function cl.reload()
	for _, id in pairs(player(0, 'table')) do
		if cool then
			if cool[id] then
				cl.removeImage()
				cl.drawImage(id)
				return
			end
		end
	end
end
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview