English Tween_scale (lua)

5 replies
Goto Page
To the start Previous 1 Next To the start
10.06.13 10:44:12 pm
Up
limonata
User
Offline Off
Hello i need help about tween_scale

here is my first test and it worked.

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
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.

Code:
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
11.06.13 12:01:05 am
Up
Rainoth
Moderator
Offline Off
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.
11.06.13 04:15:06 pm
Up
limonata
User
Offline Off
You mean you cant give your id it should be a image?

So how can i do it to myself
11.06.13 05:45:09 pm
Up
DC
Admin
Offline Off
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!
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
11.06.13 06:11:03 pm
Up
Rainoth
Moderator
Offline Off
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

Code:
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.
Code:
1
if player(id,"look") == 0 then -- Looks vary from 0 to 3 if I'm not mistaken
11.06.13 07:48:17 pm
Up
limonata
User
Offline Off
Okay Thanks
To the start Previous 1 Next To the start