Forum

> > CS2D > Scripts > Tween_scale (lua)
Forums overviewCS2D overview Scripts overviewLog in to reply

English Tween_scale (lua)

5 replies
To the start Previous 1 Next To the start

old Tween_scale (lua)

limonata
User Off Offline

Quote
Hello i need help about tween_scale

here is my first test and it worked.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
local img = image("gfx/npc6.png",250,100,2)


knt = 0
function small()
tween_scale(img,1500,1.0,1.0)
end

function big()
tween_scale(img,1500,5.0,5.0)
end

addhook("serveraction","ts")
function ts(id,act)
	if act == 1 then
		if knt == 0 then
			big()
			knt = 1
		elseif knt == 1 then
			small()
			knt = 0
		end
	end
end

I can control my gfx with f2 but i want to control myself i tried this script but failed

Error is: LUA ERROR: sys/lua/tw.lua:10: bad argument #1 to 'tween_scale' (number expected, got nil)

Line 10: tween_scale(id,1500,5.0,5.0)

Here is the script, please fix it and please tell me my mistake.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
knt = 0
function small(id)
tween_scale(id,1500,1.0,1.0)
end

function big(id)
tween_scale(id,1500,5.0,5.0)
end

addhook("serveraction","ts")
function ts(id,act)
	if act == 1 then
		if knt == 0 then
			big(id)
			knt = 1
		elseif knt == 1 then
			small(id)
			knt = 0
		end
	end
end

Thanks
edited 3×, last 10.06.13 11:44:16 pm

old Re: Tween_scale (lua)

Rainoth
Moderator Off Offline

Quote
I'm pretty sure you could figure it out from the error.

Argument 1 that you provide is wrong for tween_scale.
Meaning that it needs id of an image.
So normally it would get e.g. "img" and where the image is but in your case you just give it a player id e.g. 7. Nothing more. Then it gives you an error. You could fix this by checking how player looks then assigning ID's for player images with correct image paths and then using those IDs.

This is my guess why your script doesn't work. I hope you will understand.

old Re: Tween_scale (lua)

DC
Admin Off Offline

Quote
Why did you post (nearly) the same script twice? The error you posted
Quote
Error is: LUA ERROR: sys/lua/tw.lua:10: bad argument #1 to 'tween_scale' (number expected, got nil)

is caused by your first version of the script. You called your functions big and small without passing the id parameter. That leads to the error because id is nil (nil = does not contain a value).

In your second version you are passing an id to the functions but its a player id (click here to see the parameters of cs2d lua hook serveraction). All tween commands expect image ids. They do not work with player ids! You can only tween images!

old Re: Tween_scale (lua)

Rainoth
Moderator Off Offline

Quote
user limonata has written
You mean you cant give your id it should be a image?

So how can i do it to myself


Didn't you read what I wrote ? I basically said what DC said but in less descriptive way and I gave a solution.

Just like you made "local img" you can make image IDs for images of players. You just have to create some separate images since player images come in sets of 6. So you have to divide them. Then you write

1
local img1 = image("gfx/players/dividedimagename.png,250,100,2)

and use it just like any other image.

edit : forgot to mention that you have to check which image to take on each look.
1
if player(id,"look") == 0 then -- Looks vary from 0 to 3 if I'm not mistaken
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview