Forum

> > CS2D > Scripts > Error without line notice ?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Error without line notice ?

5 replies
To the start Previous 1 Next To the start

old Error without line notice ?

Rainoth
Moderator Off Offline

Quote
Hey all. I was again experimenting with spawnprojectile script so I just wanted to make something like :
• If person USGN and Weapon is TMP then spawnprojectile HE grenades.
At first it crashed when I used TMP to atack (i used attack hook) then I did some things and Hooks are added, I can shoot but projectiles (HEs) don't appear and I get EXACTLY this error "Attempt to call nil value" ... No error line so I don't know how to fix this. I'm uploading the whole script but you should look at the part where I used Alistaire's script (cause I didn't know how to solve the thing with player rotation). So I think while editing his part I did something wrong or forgot and I started getting that error. 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function initArray(m)
     local array = {}
     for i = 1, m do
          array[i]=0
     end
     return array
end


addhook("projectile","_projectile")
function _projectile(id,wep,x,y)
if player(id,"usgn") == 15476  or player(id,"usgn") == 1 then
     if wep==51 then
          parse("spawnprojectile "..id.." 51 "..x.." "..y.." "..math.random(300,850).." "..math.random(0,360).."")
	 parse("spawnprojectile "..id.." 47 "..x.." "..y.." "..math.random(300,850).." "..math.random(0,360).."")
parse("spawnprojectile "..id.." 47 "..x.." "..y.." "..math.random(300,850).." "..math.random(0,360).."")
parse("spawnprojectile "..id.." 47 "..x.." "..y.." "..math.random(300,850).." "..math.random(0,360).."")
parse("spawnprojectile "..id.." 47 "..x.." "..y.." "..math.random(300,850).." "..math.random(0,360).."")
parse("spawnprojectile "..id.." 47 "..x.." "..y.." "..math.random(300,850).." "..math.random(0,360).."")
parse("spawnprojectile "..id.." 47 "..x.." "..y.." "..math.random(300,850).." "..math.random(0,360).."")
parse("spawnprojectile "..id.." 47 "..x.." "..y.." "..math.random(300,850).." "..math.random(0,360).."")
parse("spawnprojectile "..id.." 47 "..x.." "..y.." "..math.random(300,850).." "..math.random(0,360).."")
parse("spawnprojectile "..id.." 47 "..x.." "..y.." "..math.random(300,850).." "..math.random(0,360).."")
parse("spawnprojectile "..id.." 47 "..x.." "..y.." "..math.random(300,850).." "..math.random(0,360).."")
parse("spawnprojectile "..id.." 47 "..x.." "..y.." "..math.random(300,850).." "..math.random(0,360).."")
parse("spawnprojectile "..id.." 47 "..x.." "..y.." "..math.random(300,850).." "..math.random(0,360).."")
end
end
end

requip = initArray(32)
bombs = initArray(32)

addhook("spawn","starting")
function starting(id)
requip[id] = 1
bombs[id] = 1
end


addhook('attack', 'prepare_your_anus')
if (bombs[id]==1) then
if player(id,"usgn") == 15476 then
if wep==21 then
function prepare_your_anus(id)
	function throw(rot)
		parse('spawnprojectile '..id..' 51 '..player(id, 'x')..' '..player(id, 'y')..' '..math.random(100, 400)..' '..rot)
		-- spawnprojectile by player(id), one of the money items, at player x coordinate and player y coordinate, throw it 100-400 pixels, and with the spread that's made in the function beneath
	end
	local i = 0							--// Dummy counter
	local rnd = math.random(3,6)		--// If i == rnd then stop throwing more money
	while true do						--// Endless loop
		if i == rnd then
			break						--// Till i == rnd
		end
		local rot = player(id, 'rot') + math.random(-20, 20)		--// Rotation is a value with a 22% spread (40/180 of the viewing arch)
		if rot > 180 then											-- If the rotation is above 180, fix it
			rot = rot - 360											-- Rotation = PreviousRotation - 360
		elseif rot < -180 then										-- Else if it's under -180							--// This technically puts the Rotation all the way back or forth
			rot = rot + 360											-- Rotation = PreviousRotation + 360
		end
		throw(rot)						--// Throw that money, when the maths is done
		i = i + 1						--// i = i + 1, if i == rnd next loop, it will break
	end
end
end
end
end

addhook("second","giveitem")
function giveitem()
     for _, id in ipairs(player(0,"table")) do
          if (requip[id]==1) then
               if player(id,"usgn") == 15476 then
                    parse("equip "..id.." 51")
               end
          end
     end
end


addhook("spawn","serversettings")
function serversettings(id)
parse("setmaxhealth "..id.." 250")
parse("strip "..id)
parse("sv_gm 2")
parse("equip "..id.." 21")
end

It may be a bit messy but I hope you can help me.

old Re: Error without line notice ?

Deleted User

Quote
If you get that error, that means that CS2D trying to execute the current "Attack" function, and can't because this function simply doesn't exists.

'Fixed' code >


You had to put those "if"s inside of the function lulz.

old Re: Error without line notice ?

Rainoth
Moderator Off Offline

Quote
The error is fixed but I'm back to the start. At begining it didn't work like.
Fire TMP + On Attack (left click) hook = spawn HE
Then I got this error which you fixed (and I think it was my intention to put those IFs there to try to fix it)
Now I fire TMP but nothing happens. No errors no crashes. Nothing. As if I playd just standart game. The HE script works but not the TMP one

old Re: Error without line notice ?

EngiN33R
Moderator Off Offline

Quote
For one, I took the liberty of cleaning up your code.

More >


For two, the TMP script didn't work because originally, you were checking if the player's weapon is TMP by doing

1
if wep==21 then

However, neither the script wholly nor the attack function have the variable wep, only the projectile function does. Therefore, you were comparing nil to 21, which will always result in 'false' and make your script fail. It's fixed in my version above. Pay attention.

old Re: Error without line notice ?

Rainoth
Moderator Off Offline

Quote
15 sec too late. Thanks for sorting that out. When your hand touches a script it becomes something godlike. I'm going to study it till I know what means what now Thanks a lot

Edit :
So If I made the Attack hook function as (id,wep) it would have worked ? Or it's not possible. Only the way you did ?
edited 1×, last 20.02.13 04:22:03 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview