Forum

> > CS2D > Scripts > Shake lua
Forums overviewCS2D overview Scripts overviewLog in to reply

English Shake lua

17 replies
To the start Previous 1 Next To the start

old Shake lua

J4x
User Off Offline

Quote
Hi, I was making this script, and i end up with this error:
'end' expected (to close 'function' at line 2) near 'elseif'
I know that it means that I should add another end before elseif, but I don't know why it happens...
1
2
3
4
5
6
7
8
9
10
addhook("hit","shake")
function shake(id,source,weapon)
	if itemtype(type,"dmg") >= 20 then
	parse("shake "..id.." 10")
end	
	elseif
	itemtype(type,"dmg") <= 19 then
	parse("shake "..id.." 5")
	end
end
edited 1×, last 04.06.11 02:26:27 am

old Re: Shake lua

kalis
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
addhook("hit","shake")
function shake(id,source,weapon)
     if itemtype(type,"dmg") >= 20 then
     parse("shake "..id.." 10") 
     elseif
     itemtype(type,"dmg") <= 19 then
     parse("shake "..id.." 5")
     end
end
when use else if only need end of last line

old Re: Shake lua

J4x
User Off Offline

Quote
ok, thaks heocon, but try to learn english, don't use translators.

old Re: Shake lua

J4x
User Off Offline

Quote
Now it says me: Number expected got function

old Re: Shake lua

Starkkz
Moderator Off Offline

Quote
Yep, it's truth. type is a function of Lua that returns in a string the type of a value. So, you should put "weapon" and not "type".

1
2
3
4
5
6
7
8
addhook("hit","shake")
function shake(id,source,weapon)
	if itemtype(weapon,"dmg") >= 20 then
		parse("shake "..id.." 10")    
	elseif itemtype(weapon,"dmg") <= 19 then
		parse("shake "..id.." 5")
	end
end

old Re: Shake lua

J4x
User Off Offline

Quote
Thank you so much
EDIT: i think it should be a number value, it says me that the number expected got nil.
EDIT2: I was wrong, this is my code fixed
1
2
3
4
5
6
7
8
9
addhook("hit","shake")
function shake(id,source,weapon)
	if itemtype(id,"dmg") >= 20 then
	parse("shake "..id.." 10")
elseif 
	itemtype(id,"dmg") <= 19 then
	parse("shake "..id.." 5")
		end
	end
edited 3×, last 04.06.11 03:10:44 am

old Re: Shake lua

Starkkz
Moderator Off Offline

Quote
But the weapon with id 0 doesnt exist, how are you sure that it works?

old Re: Shake lua

J4x
User Off Offline

Quote
I fixed it, DC wrote in the info.txt
1
itemtype(type,"value")
so he was wrong, the correct thing is
1
temtype(id,"value")
.

old Re: Shake lua

Starkkz
Moderator Off Offline

Quote
Actually not, if you put ID then it will mean about the id of the weapon in the list of current spawned weapons in the map or the weapon that someone (player) is using it in the moment. So he wrote type to make a difference of item type id.

well, in my opinion. both ways of explaination were wrong.

old Re: Shake lua

J4x
User Off Offline

Quote
but if you use "type" you got an error, if you use "weapon" you also git an error, and actually id works for me.

old Re: Shake lua

Starkkz
Moderator Off Offline

Quote
Ah you were talking about the value to put in there when you call it?. But that shouldn't be incorrect, it's supposed that the weapon is a parameter wich returns the id of the weapon. so when you call the function itemtype, you have to insert the weapon parameter into the first required parameter for itemtype. Also put the second parameter to request the information needed,(dmg parameter). I don't know what goes wrong then.

Edit: maybe the weapon id parameter is wrong, because sometimes returns an id like 253 if is a building the one wich attacked you. That could be caused too in the case of doing slap at the admin panel.

old Re: Shake lua

EngiN33R
Moderator Off Offline

Quote
You have to use weapon type in itemtype(type,"value"), not the weapon ID. The weapon ID is the ID of the object, it can be 91, 253, whatever, while weapon type is actually what people call 'weapon IDs', so 45 for Laser etc. So you need to use the weapon parameter, which is the weapon type. Hope I helped.

old Re: Shake lua

J4x
User Off Offline

Quote
If I use "type" it says me: Bad argument to type#1(number expected got function), But if i use id it works.

old Re: Shake lua

EngiN33R
Moderator Off Offline

Quote
Maybe it's because you don't have a variable called type? You know you have to declare a variable to use it, right? If you didn't declare type then it'll interpret it as the type function. You have to use the weapon argument.

old Re: Shake lua

J4x
User Off Offline

Quote
So you mean like:
1
itemtype(weapon,"dmg").
If that is wht you mean, i tryed it and it says me the that the number expected got nil.
edited 1×, last 04.06.11 09:28:14 pm

old Re: Shake lua

Starkkz
Moderator Off Offline

Quote
that shouldn't be nil. In this case, why don't you try to use the hpdmg parameter of the lua function?
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview