Forum

> > CS2D > Scripts > Weapon exeption
Forums overviewCS2D overview Scripts overviewLog in to reply

English Weapon exeption

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

old Weapon exeption

Mechanolith
User Off Offline

Quote
I was making my first script (i know it already exists, but i liked it, so i remaked it) (thanks for FN_Linkin Park)

And i wanted to make your screen shake if you shoot with a specified weapon, like, if i shoot with RPG, the shake should be 7, if i shoot with USP, the shake would be 2.
Can someone explain me how to make that?

Actually, mi script is like that:
1
2
3
4
5
6
7
8
9
addhook ("hit","damageshake")
  function damageshake(id)
    parse("shake "..id.." 2")
end

addhook("attack","attackshake")
  function attackshake(id)
    parse("shake "..id.." 2")
end

old Re: Weapon exeption

J4x
User Off Offline

Quote
Im glad to inspire u Well i tried to make this a months ago this can maybe help:

1
2
3
4
5
6
7
weapons_table = {1,2,3,4}
addhhook("hit","shake")
function shake(id,source,weapon,hpdmg,apdmg)
	if weapon == weapons_table then
	parse("shake "..id.." 2")
	end
end
edited 1×, last 07.04.11 01:32:21 am

old Re: Weapon exeption

Mechanolith
User Off Offline

Quote
So, the weapons table is the weapons ID that will shake X value?

Like:
1
2
3
4
5
6
7
weapons_table = {Weapon IDs that will shake the "parse" value}
addhook("hit","shake")
function shake(id,source,weapon,hpdmg,apdmg)
     if weapon == weapons_table then
     parse("shake "..id.." 2")
     end
end

And i think source, hpdmg and apdmg are not needed, am i right?

old Re: Weapon exeption

J4x
User Off Offline

Quote
Yeah the tables are the weapons id that "parse" will shake, and no apdmg and hpdmg are not needed.

So if u like rifle u just make another table:
1
2
3
4
5
6
7
8
9
10
11
12
weapons_table_pistols = {1,2,3,4}
weapons_table_rifles = {30,31,32,33,34,35,36}

addhook("hit","shake")
function shake(id,source,weapon,hpdmg,apdmg)
	if weapon == weapons_table_pistols then
	parse("shake "..id.." 2")
end
	elseif weapon == weapons_table_rifles then
parse("shake "..id.." 4") 
	end
end
edited 2×, last 07.04.11 01:47:38 am

old Re: Weapon exeption

J4x
User Off Offline

Quote
explain urself im a noob at lua, don't act like: OMG U ARE IGNORANT!, if im wrong just correct me, it is annoying that u act like that....

old Re: Weapon exeption

Starkkz
Moderator Off Offline

Quote
Yes you have to know it because i told it to you before, and you did it again.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
weapons_table_pistols = {1,2,3,4}
weapons_table_rifles = {30,31,32,33,34,35,36}
 
addhook("hit","shake")
function shake(id,source,weapon,hpdmg,apdmg)
	for _, w in pairs(weapons_table_pistols) do
		if weapon == w then
			parse("shake "..id.." 2")
			break
		end
	end
	for _, w in pairs(weapons_table_rifles) do
		if weapon == w then
			parse("shake "..id.." 4") 
			break
		end
	end
end

old Re: Weapon exeption

Mechanolith
User Off Offline

Quote
Yeah... i got console message:

LUA ERROR: sys/lua/weapons shake.lua:18: 'end' expected (to close 'function' at line 14)
near 'elseif'



Bad... so, how to i code the script? because i really don't got what you say'd so, can you explain better? Like, my script is like that now:
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
weapons_table_shake2 = {1,2,4,6}
weapons_table_shake3 = {3,5,21,23,32,38,39,74,88}
weapons_table_shake4 = {20,22,24,30,31,33,34,40,46,54,75,86}
weapons_table_shake5 = {10,11,35,36,37,45,47,49,51,52,53,69,72,73,76,77,78,85,87}

addhook("attack","attackshake")
function attackshake(id)
   if weapon == weapons_table_shake2 then
   parse("shake "..id.." 2")
end
   elseif weapon == weapons_table_shake3 then
parse("shake "..id.." 3") 
   end
elseif weapon == weapons_table_shake4 then
parse("shake "..id.." 4") 
   end
elseif weapon == weapons_table_shake5 then
parse("shake "..id.." 5") 
   end
end

addhook("hit","hitshake")
function hitshake(id)
   parse("shake "..id.." 3")
end

From what i understood, this message means that i need a line space between the 'elseif' and the end that come before it?

old Re: Weapon exeption

J4x
User Off Offline

Quote
yeah i was wrong use Starks code..
edited 1×, last 07.04.11 02:31:17 am

old Re: Weapon exeption

Mechanolith
User Off Offline

Quote
So, it must be like that huh? Im gonna test 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
30
31
32
33
34
35
36
37
weapons_table_shake2 = {1,2,4,6}
weapons_table_shake3 = {3,5,21,23,32,38,39,74,88}
weapons_table_shake4 = {20,22,24,30,31,33,34,40,46,54,75,86}
weapons_table_shake5 = {10,11,35,36,37,45,47,49,51,52,53,69,72,73,76,77,78,85,87}

addhook("attack","attackshake")
function attackshake(id)
    for _, w in pairs(weapons_table_shake2) do
        if weapon == w then
            parse("shake "..id.." 2")
                break
            end
    end
    for _, w in pairs(weapons_table_shake3) do
        if weapon == w then
            parse("shake "..id.." 3")
                break
            end
    end
    for _, w in pairs(weapons_table_shake4) do
        if weapon == w then
            parse("shake "..id.." 4")
                break
            end
    end
    for _, w in pairs(weapons_table_shake2) do
        if weapon == w then
            parse("shake "..id.." 5")
                break
            end
    end
end

addhook("hit","hitshake")
function hitshake(id)
    parse("shake "..id.." 3")
end

Well, thanks for all the help
Im happy to start with lua, it seems to be really interesting.
edited 2×, last 07.04.11 02:37:23 am

old Re: Weapon exeption

Mechanolith
User Off Offline

Quote
All the code is written without any bugs/error, but when o shoot with the weapons, the screen doesn't shake, what's the problem with the code?

old Re: Weapon exeption

J4x
User Off Offline

Quote
let me check it, and i will try to fix it.
EDIT: i can't help u sorry man
edited 1×, last 07.04.11 03:04:22 am

old Re: Weapon exeption

Starkkz
Moderator Off Offline

Quote
@FN_Linking Park: The pairs function is called for each value in the table position, for example

1
2
3
4
My_Tab = {1,5,3,4,8}
for position, value in pairs(My_Tab) do
	print("Position: "..position.." Value: "..value)
end

You get the position of the value in the table. It's similar to this:

1
2
3
4
5
My_Tab = {1,5,3,4,8}
for position = 1, #My_Tab do
	local value = My_Tab[position]
	print("Position: "..position.." Value: "..value)
end

But the position parameter can be string.

@Joaopcvcastro: I can recomend you to use Notepad++ or Lua Scite. It's very useful to find errors in scripts. You can search the line with the bug.. , you can find a word (with notepad too), Notepad let you script in 54 scripting languages.. (Or lower than that).

old Re: Weapon exeption

J4x
User Off Offline

Quote
i cheked it in scite, it hasn't bugs, just "attemp to calll global addhook a nil value", which is a normal bug, becuase hooks arent real lua parts..

old Re: Weapon exeption

EngiN33R
Moderator 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
weapons_table_shake2 = {1,2,4,6}
weapons_table_shake3 = {3,5,21,23,32,38,39,74,88}
weapons_table_shake4 = {20,22,24,30,31,33,34,40,46,54,75,86}
weapons_table_shake5 = {10,11,35,36,37,45,47,49,51,52,53,69,72,73,76,77,78,85,87}

function contains(table, element)
    for _, value in pairs(table) do
        if value == element then
            return true
        end
    end
    return false
end

addhook("attack","attackshake")
function attackshake(id)
    if contains(weapons_table_shake2,player(id,"weapon")) then
        parse("shake "..id.." 2")
    end
    if contains(weapons_table_shake3,player(id,"weapon")) then
        parse("shake "..id.." 3")
    end
    if contains(weapons_table_shake4,player(id,"weapon")) then
        parse("shake "..id.." 4")
    end
    if contains(weapons_table_shake5,player(id,"weapon")) then
        parse("shake "..id.." 5")
    end
end

addhook("hit","hitshake")
function hitshake(id)
    parse("shake "..id.." 3")
end
The thing can't read my Tabs so the code is untabbed.

old Re: Weapon exeption

Mechanolith
User Off Offline

Quote
Yeah, thanks for all this help
@Starkkz, i already have Notepad ++, but i forgot, :S
I never tough i would start with lua.

And EngiN33R, tabs can't be inserted in comments, you have to use "alt+0160"
[Alt+0160] = " "


P.S.: Thanks for all you, and your code worked perfectly EngiN33R, thanks
What about publishing? this was all your work, can i publish it with your credits? (FN_Linkin Park, Starkkz, EngiN33R)
edited 2×, last 07.04.11 10:33:38 pm
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview