Forum

> > CS2D > Scripts > Explosion in corner not on my position ?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Explosion in corner not on my position ?

7 replies
To the start Previous 1 Next To the start

old Explosion in corner not on my position ?

Rainoth
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
addhook("menu","explosion")
function explosion(id,title,button)
sx = player(id,"x")
sy = player(id,"y")
st = player(id,"team")
	if title=="Explosion Menu" then
	  		if button==1 then
				parse("explosion "..sx.." "..sy.." 96 100 "..id)
				elseif button==2 then
				parse("explosion "..sx.." "..sy.." 192 160 "..id)
				elseif button==3 then
				parse("explosion "..sx.." "..sy.." 192 280 "..id)
				elseif button==4 then
				parse("explosion "..sx.." "..sy.." 512 350 "..id)
				elseif button==5 then
				parse("explosion "..sx.." "..sy.." 512 500 "..id)
				elseif button==6 then
				parse("msg "..player(id,"name").." is nuking in 3 seconds@C")
				timer(3000,"parse",'explosion "..sx.." "..sy.." 2048 1000 "..id.." ')
			end
	end
end

All explosions work except for timer one. It spawn explosion on Left Top Corner of the map. What might be wrong here ?

old Re: Explosion in corner not on my position ?

Rainoth
Moderator Off Offline

Quote
Works. Thanks.

Edit : So I've been working on a sprint script and I believe it's fine until player runs out of energy. He starts recharging and losing "Energy" at the same time. Did I forget anything in this code (sorry if it's messy and that hud is another second hook but I copy-pasted that one so don't be mad)
Here's the 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
function initArray(m)
     local array = {}
     for i = 1, m do
          array[i]=0
     end
     return array
end

walkpt = initArray(32)
recha = initArray(32)
run = initArray(32)

addhook("second","boom")
function boom()
     for _, id in pairs(player(0,"table")) do
          if player(id,"exists") then
		if recha[id]==1 then
			walkpt[id] = walkpt[id] + 4
		end
		if walkpt[id] == 100 then
			recha[id] = 0
		end
		if run[id] == 1 then
			if walkpt[id] > 4 then
				parse("speedmod "..id.." 5")
				recha[id] = 0
				walkpt[id] = walkpt[id] - 5
			else recha[id] = 1
				parse("speedmod "..id.." 0")
			end
		end
	  end
     end
end

addhook("second","movepthuk")
function movepthuk()
     for _, id in pairs(player(0,"table")) do
          if player(id,"exists") then
               parse('hudtxt2 '..id..' 3 "©000000255Energy: '..walkpt[id]..'%" 155 155')
          end
     end
end

addhook("serveraction","actions")
function actions(id,b)
	if b==1 then
	run[id] = 1
	end
	if b==2 then
		recha[id] = 1
	end
end
If you point out mistake or fix the code I'd be very thankful.

On a completely different note : Is it allowed to make one thread (for myself) and post ALL problems that occur to me instead of making a new thread everytime I don't find anything in forum and have to make it ? (Even now it looks dumb when I'm posting this under "Explosion in corner")
edited 1×, last 10.03.13 08:07:54 pm

old Re: Explosion in corner not on my position ?

Rainoth
Moderator Off Offline

Quote
user Alistaire has written
1. Don't hook multiple functions to the same hook
2. Don't use a second hook if you don't need it
3. Don't hook multiple functions to a second hook, if you don't need it anyways


1.Where did I hook multiple functions ?
2.But I really need the energy to recharge every second (and how would I update hud if not with second)
3.So I should just make tons of second hooks so all function would get separate hook ? No. So how the hell do I do it then ?

I really don't understand why I shouldn't need a second hook

old Re: Explosion in corner not on my position ?

Rainoth
Moderator Off Offline

Quote
user Alistaire has written
Dude. Addhook should be used only once for every hook. You use the second hook twice.

I'm not even gonna try to explain further cause you obviously don't understand.


I apologized when posting the code for that. And yes it may seem dumb to add same hook but I didn't know about such stuff until a while ago and yet even If I made 10 menu hooks or 5 movetile hooks it worked fine... I get it. It should be one hook for one type. But please bear with it.

Could anyone please tell me what part is wrong and makes the script to mis-work ?

old Re: Explosion in corner not on my position ?

Alistaire
User Off Offline

Quote
user Rainoth has written
Could anyone please tell me what part is wrong and makes the script to mis-work ?


Both are on a second hook. The exact second the energy stuff goes up, it goes down because it was high enough to be drained. If you put the subtraction before adding energy, it would work fine.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview