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 Image turning around player and changing size

Mami Tomoe
User Off Offline

Quote
Hi
I need Lua help!
Yes!
OK so I need image that will turn around the player and grow bigger and smaller around him if he has cool[id]==true and if not it will disappear!

If you know how plz help me I don't know images how script them plz OK thxy!

old Re: Image turning around player and changing size

Mora
User Off Offline

Quote
user Mami Tomoe has written
and I don't know what to put in image( )

Guy, look for samples in cs2d folder, read some info at www.cs2d.com , search some "how2lua" threads, btw there is one by starkkz. Moreover, such threads about images wroten much times and you can find them easily by using "search" button.

old Re: Image turning around player and changing size

Mami Tomoe
User Off Offline

Quote
I do this:
1
img= {"gfx/cs2d.bmp"}
and
1
image(img,0,0,0)

and this:

1
LUA ERROR: sys/lua/sp-rp-script/main.lua:376: bad argument #1 to 'freeimage' (number expected, got string)

and a few seconds later cs2d stop responding!!

old Re: Image turning around player and changing size

Mora
User Off Offline

Quote
Did you even read what user Rainoth gave to ya?
Image:
Parameters:
• "path"
• x
• y
• mode
• [pl] (optional)
image("path",x,y,mode,[pl(optional])
and example
img=image("gfx/instruments/d**do.png",player(id,"x"),player(id,"y"),200+id,id)

You can do many things to controll your images(make then for each player, add a table with images etc)

old Re: Image turning around player and changing size

Mami Tomoe
User Off Offline

Quote
yes I did read
I have this
rp_wanted_img = {"gfx/cs2d.bmp"}


and this in second hook:
1
2
3
4
5
6
7
if rp_ct[id] and player(id,"health")>0 then
				rp_wanted_img[id] = image(rp_wanted_img,player(id,"x"),player(id,"y"),200+id,id)
				tween_rotateconstantly(rp_wanted_img[id],1)
			else
				freeimage(rp_wanted_img[id])
				rp_wanted_img[id] = nil
			end

and i get this
1
2
3
4
LUA ERROR: sys/lua/sp-rp-script/main.lua:377: bad argument #1 to 'freeimage' (number expected, got
string)
 -> [C]: in function 'freeimage'
 -> sys/lua/sp-rp-script/main.lua:377: in function <sys/lua/sp-rp-script/main.lua:364>

old Re: Image turning around player and changing size

Mora
User Off Offline

Quote
don't know exactly.
Maybe you have to use:
1
2
3
4
5
6
7
PLAYER={}
rp_wanted_img=gfx/cs2d.bmp

addhook("join","_join")
function _join(id)
PLAYER[id]={}
end

and then use:
(i don't remember about
rp_wanted_img
or
rp_wanted_img.."

PLAYER[id].img = image(rp_wanted_img,player(id,"x"),player(id,"y"),200+id,id)

also before you adding the image you can check if it is nil:
1
2
3
4
5
if PLAYER[id].img then
--code
else
--another code
end
also

1
2
3
tween_rotateconstantly(PLAYERS[id].img,1)
freeimage(PLAYER[id].img)
PLAYER[id].img=nil
edited 1×, last 03.12.16 09:11:10 pm

old Re: Image turning around player and changing size

Masea
Super 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
imgs = {}

img = "gfx/example.bmp" -- Path of rotating image
turning_spd = 5, -- Rotation speed

addhook("join","_join")
function _join(id)
	imgs[id] = nil
end

function turning_image(id)
	if cool[id] == true then
		if imgs[id] == nil then
			imgs[id] = image(img,0,0,id+200)
			tween_rotateconstantly(imgs[id],turning_spd)
		end
	else
		if imgs[id] then
			freeimage(imgs[id])
			imgs[id] = nil
		end
	end
end

addhook("ms100","_ms100")
function _ms100()
	for _, i in pairs(player(0,"table")) do
		if player(i,"health") > 0 then
			turning_image(i)
		end
	end
end
Forget the others, just use this one.
edited 3×, last 03.12.16 10:00:57 pm

old Re: Image turning around player and changing size

Rainoth
Moderator Off Offline

Quote
@user Mami Tomoe: I'll give you a step by step guide on how to use cs2d.com.

1. Find the command/lua command that you're looking for. In this case it's cs2d lua cmd image
2. Check the parameters to understand
3. Have no idea what the hell is happening.
4. Look for examples in the forum or
5. Take one of the examples and play around with it. Change numbers for the parameters (in this case, x,y,mode and so on)
6. See what they do and finally start to understand how it works.
7. Use the knowledge you just gained to further your script development.

Simple. If you're trying to learn lua, you'll have to work for it.

@user Masea: You don't free the image on join. You're also constantly calling multiple commands, loops and IFs for something you only need to do once.

old Re: Image turning around player and changing size

Masea
Super User Off Offline

Quote
user Rainoth has written
@user Masea: You don't free the image on join.
I don't. Just nilling that parameter, nothing else. I don't think that if it will cause problems here. Either should I free the image on join? Actually I don't understand what you tried to say to me

user Rainoth has written
You're also constantly calling multiple commands, loops and IFs for something you only need to do once.
I could give him just a function that has rotating image but since he doesn't know how to use functions, even lua itself, I don't think if it'd be good idea.

old Re: Image turning around player and changing size

Rainoth
Moderator Off Offline

Quote
@user Masea: That's what I'm saying. Why do you need to nil the parameter if you don't free the image before it?
The second thing is bad because instead of doing "put on a hat" you do "put on a hat put on a hat put on a hat put on a hat ........."
There's no reason to do it.
Yes, you added an if to not add a hat after it's been added once but why do you even need to attempt to add a hat every 5 frames?
P.S. If for some reason it makes sense, you could use 'tableliving' instead of 'table'+is player alive 'if'.

old Re: Image turning around player and changing size

Masea
Super User Off Offline

Quote
user Rainoth has written
@user Masea: That's what I'm saying. Why do you need to nil the parameter if you don't free the image before it?
Due to I didn't use "leave" hook to nil it after someone left from the server. Using "join" or "leave" hook to nil something totally same, isn't it?

user Rainoth has written
Yes, you added an if to not add a hat after it's been added once but why do you even need to attempt to add a hat every 5 frames?
He doesn't know the Lua. Whatever you should do is make all up ready for him. Don't effort to say something on this, he can remove that hook if he will want so this is why I added there a function instead of coding them all into ms100 hook.

old Re: Image turning around player and changing size

Rainoth
Moderator Off Offline

Quote
@user Masea: Ye but wouldn't you normally use freeimage() too? Unless it automatically does it whenever you leave, which I doubt.
He doesn't know the Lua therefore you'll give him an alternative code that is less efficient? That's how it looks to me.

old Re: Image turning around player and changing size

Masea
Super User Off Offline

Quote
user Rainoth has written
less efficient

1
2
3
4
5
6
7
if cool[id] then     
     img[id] = image( ) -- change settings here
     tween_rotateconstantly(img[id],1)
else
     freeimage(img[id])
     img[id] = nil
end
1
2
3
4
5
6
7
8
9
10
11
if cool[id] == true then
          if imgs[id] == nil then
               imgs[id] = image(img,0,0,id+200)
               tween_rotateconstantly(imgs[id],turning_spd)
          end
     else
          if imgs[id] then
               freeimage(imgs[id])
               imgs[id] = nil
          end
     end
Then yours is also less efficient because I don't see any difference among them for sure. If you were talking about full code, then as I said, he can remove what he doesn't want to see. I don't know what we are on, our both code works fine so let this unnecessary discussion over please. The image removes when he left from server but even I doubt if that image comes back when the player with that id join over.

old Re: Image turning around player and changing size

GeoB99
Moderator Off Offline

Quote
user Masea has written
The image removes when he left from server but even I doubt if that image comes back when the player with that id join over.

The image itself gets faded away however the image ID is still recycled in the stack thus duplicate image IDs might occur and the player which joins in the server might get the same image ID. For this problem it is better to implement cs2d lua hook leave hook and freeimage + obliterate the ID of that image.
The Code >

I also added cs2d lua hook die, cs2d lua hook endround and cs2d lua hook join so nothing weird happens with the management of images. Yeah, it's miserable how CS2D manages these images in a poor way so we have to do these actions manually.
edited 1×, last 04.12.16 10:40:51 am
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview