Forum

> > CS2D > Scripts > Explosion not working
Forums overviewCS2D overview Scripts overviewLog in to reply

English Explosion not working

13 replies
To the start Previous 1 Next To the start

old Explosion not working

Louie
User 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
35
36
37
38
39
40
41
addhook("menu","Special")
function Special(id,title,button)
if title == "Special" then
    if button == 1 and gold[id] > 75 then
      supplydrop[id] = supplydrop[id] + 1
      gold[id] = gold[id] - 75
elseif button == 2 and gold[id] > 180 then
    parse("equip "..id.." 76")
      gold[id] = gold[id] - 180
elseif button == 3 and gold[id] > 220 then
      f18s[id] = f18s[id] + 1
      gold[id] = gold[id] - 220
      end
   end
end

addhook("menu","itemstrike")
function itemstrike(id,title,button)
if title == "Use Specials" then                         
     if button == 1 and supplydrop[id] > 0 then
       timer(1000,"parse","spawnitem 61 "..player(id,"tilex").." "..player(id,"tiley"))
       timer(1500,"parse","spawnitem 62 "..player(id,"tilex").." "..player(id,"tiley"))
       timer(2000,"parse","spawnitem 65 "..player(id,"tilex").." "..player(id,"tiley"))
       timer(3000,"parse","spawnitem 58 "..player(id,"tilex").." "..player(id,"tiley"))
supplydrop[id] = supplydrop[id] - 1

elseif button == 2  then
Pos = {{math.random(-5,5),math.random(-5,5)},{math.random(-5,5),math.random(-5,5)},{math.random(-5,5),math.random(-5,5)}}
for i = 1,#Pos do
local ExplX = x + Pos[i][1]
local ExplY = y + Pos[i][2]
      timer(1000,"parse","explosion "..ExplX.." "..ExplY.." 112 100 "..id)
      timer(2000,"parse","explosion "..ExplX.." "..ExplY.." 112 100 "..id)
      timer(3000,"parse","explosion "..ExplX.." "..ExplY.." 112 100 "..id)
f18s[id] = f18s[id] - 1
               end
            end
         end
      end
   end
end
This is part of my script(the part thats not working),i wanted it to be that when u bought a certain item your gold will get decreased and u will get an item and when u use the F18 strike then random explosions around the player who used the item will happen(thats why i used the math.random),but my problem the gold doesn't decrease(when i buy an item) and when i try to use the F18 strike i get an error in the console: attempt to perform arimethic on global 'x'(a nil value),how can i fix it?

old Re: Explosion not working

Angel Montez
BANNED 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
35
36
37
38
39
addhook("menu","Special")
function Special(id,title,button)
if title == "Special" then
    if button == 1 and gold[id] > 75 then
      supplydrop[id] = supplydrop[id] + 1
      gold[id] = gold[id] - 75
elseif button == 2 and gold[id] > 180 then
    parse("equip "..id.." 76")
      gold[id] = gold[id] - 180
elseif button == 3 and gold[id] > 220 then
      f18s[id] = f18s[id] + 1
      gold[id] = gold[id] - 220
      end
   end
end

addhook("menu","itemstrike")
function itemstrike(id,title,button)
if title == "Use Specials" then                         
     if button == 1 and supplydrop[id] > 0 then
       timer(1000,"parse","spawnitem 61 "..player(id,"tilex").." "..player(id,"tiley"))
       timer(1500,"parse","spawnitem 62 "..player(id,"tilex").." "..player(id,"tiley"))
       timer(2000,"parse","spawnitem 65 "..player(id,"tilex").." "..player(id,"tiley"))
       timer(3000,"parse","spawnitem 58 "..player(id,"tilex").." "..player(id,"tiley"))
supplydrop[id] = supplydrop[id] - 1

elseif button == 2  then
Pos = {{math.random(-5,5),math.random(-5,5)},{math.random(-5,5),math.random(-5,5)},{math.random(-5,5),math.random(-5,5)}}
for i = 1,#Pos do
local ExplX = x + Pos[i][1]
local ExplY = y + Pos[i][2]
      timer(1000,"parse","explosion "..ExplX.." "..ExplY.." 112 100 "..id)
      timer(2000,"parse","explosion "..ExplX.." "..ExplY.." 112 100 "..id)
      timer(3000,"parse","explosion "..ExplX.." "..ExplY.." 112 100 "..id)
f18s[id] = f18s[id] - 1
		    end
	    end
    end
end

old Re: Explosion not working

Louie
User Off Offline

Quote
@user Angel Montez: Um, i tried that but i get LUA ERROR:end expected to close if at line 166,i think it means it needsa more "end"s,so i put in 2 more ends and i didn't any error now,but its still not working

old Re: Explosion not working

DC
Admin Off Offline

Quote
The line number of the error is not helpful if we only have a part of the script and therefore don't know what line 166 actually is in that part.

• Indent your code properly so you see which end belongs to which if / function / whatever

• Please post the full script if this doesn't help

old Re: Explosion not working

Louie
User Off Offline

Quote
@user DC: Ok here is my full script:
More >

old Re: Explosion not working

DC
Admin Off Offline

Quote
Why did you split it into multiple code boxes? This way we still can't see the real line number unless we add the lines together ourselves...

If the code is too long to be posted in one piece use pages like http://nomorepasting.com

old Re: Explosion not working

Yates
Reviewer Off Offline

Quote
http://pastebin.com/kwHcgUJM

Oh how I love ctrl+alt+l in my code editor.

The function
1
function Weapons(id,title,button)
Was missing two ends:
Trouble maker >

And the two you added at the end of the code were useless so I got rid of them for you.

Copy the whole code from pastebin and replace yours with it. Should work.

old Re: Explosion not working

Louie
User Off Offline

Quote
@user Yates: Thx Yates,now the gold gets decreased when i buy an item ,though sorry to say this but my original problem is still not solved when i use the F18 Strike(from the menu) it still doesn't work
EDIT: @user DC: Now i used Yates code.
And also for more info, when i click the menu button for the F18 strike it should be that explosion in random locations near the player would happen but even when i already have the F18 Strike item it still doesn't work

old Re: Explosion not working

DC
Admin Off Offline

Quote
Do you get any Lua errors in the console when trying the F18 Strike? If yes: Please post them.

If no: Add additional debug output to your code to see if the stuff is triggered correctly.

For example: I would add the line
1
print("trying to start firestrike...")

right after your line 248
1
elseif button == 2 then

Then try again and check the console. If you find the message then you know that this code part is reached. If not you know that something is going wrong even before that part.

Such messages are the easiest way to debug Lua scripts as there is no real debugger for Lua scripts in CS2D.

old Re: Explosion not working

Louie
User Off Offline

Quote
@user DC:
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
elseif button == 2 then
            Pos = { { math.random(-5, 5), math.random(-5, 5) }, { math.random(-5, 5), 

math.random(-5, 5) }, { math.random(-5, 5), math.random(-5, 5) }, { math.random(-5, 5), 

math.random(-5, 5) } }
            for a = 1, #Pos do
                local ExplX = player(id, "tilex") + Pos[a][1]
                local ExplY = player(id, "tiley") + Pos[a][2]
                timer(1000, "parse", "explosion " .. ExplX .. " " .. ExplY .. " 112 100 " 

.. id)
                timer(2000, "parse", "explosion " .. ExplX .. " " .. ExplY .. " 112 100 " 

.. id)
                timer(3000, "parse", "explosion " .. ExplX .. " " .. ExplY .. " 112 100 " 

.. id)
                timer(4000, "parse", "explosion " .. ExplX .. " " .. ExplY .. " 112 100 " 

.. id)
                f18s[id] = f18s[id] - 1
msg("YAY BOOM!!")
print("succesfully exploded!!!")
            end
        end
    end
end
So when i pressed the button the message appeared and the "succesfully exploded!!!" message got sent into the console but no explosion happened,and theres no error happening when i try to use the F18 Strike,i'm completely clueless on why its not working

old Re: Explosion not working

DC
Admin Off Offline

Quote
I guess I got it: "tilex" and "tiley" give you the position in tiles. You need the position in pixels for explosion though (see cs2d cmd explosion). So either Use cs2d lua cmd player with just "x" and "y" instead or multiply the tile position with 32 and add 16 (for x and y coordinates).

old Re: Explosion not working

Louie
User Off Offline

Quote
Thx so much @user DC: it worked
EDIT: WAIT!!! CS2D is crashing after i use the F18 Strike wtf???
i edited the code so that the airstrike would be more better but after the first explosion then it suddenly crashes
heres 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
elseif button == 2 and f18s[id] > 0 then
            Pos1 = {{math.random(-128,128),math.random(-128,128)},{math.random(-128,128), math.random(-128,128)}}
            for a = 1, #Pos1 do
                local ExplX = player(id,"x") + Pos1[a][1]
                local ExplY = player(id,"y") + Pos1[a][2]
                timer(2000, "parse", "explosion " .. ExplX .. " " .. ExplY .. " 160 "..math.random(120,180).." "..id)
                timer(3000, "spawnprojectile "..id.." 73 "..ExplX.." "..ExplY.." 5 0")
                end
            Pos2 = {{math.random(-128,128),math.random(-128,128)},{math.random(-128,128), math.random(-128,128)}}
            for a = 1, #Pos2 do
                local ExplX = player(id,"x") + Pos2[a][1]
                local ExplY = player(id,"y") + Pos2[a][2]
                timer(3000, "parse", "explosion " .. ExplX .. " " .. ExplY .. " 160 "..math.random(120,180).." "..id)
                timer(4000, "spawnprojectile "..id.." 73 "..ExplX.." "..ExplY.." 5 0")
                end
            Pos3 = {{math.random(-128,128),math.random(-128,128)},{math.random(-128,128), math.random(-128,128)}}
            for a = 1, #Pos3 do
                local ExplX = player(id,"x") + Pos3[a][1]
                local ExplY = player(id,"y") + Pos3[a][2]
                timer(4000, "parse", "explosion " .. ExplX .. " " .. ExplY .. " 160 "..math.random(120,180).." "..id)
                timer(5000, "spawnprojectile "..id.." 73 "..ExplX.." "..ExplY.." 5 0")
                f18s[id] = f18s[id] - 1
            end
        end
    end
end
edited 1×, last 09.02.15 05:11:11 pm

old Re: Explosion not working

DC
Admin Off Offline

Quote
Wrong usage of timer. You have to use parse as second parameter and spawnprojectile with its parameters as third parameter. Just like you did with explosion.

e.g.:
1
timer(3000, "parse", "spawnprojectile "..id.." 73 "..ExplX.." "..ExplY.." 5 0")
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview