Forum

> > CS2D > Scripts > Explosion not working
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Explosion not working

13 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Explosion not working

Louie
User Off Offline

Zitieren
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?

alt Re: Explosion not working

Angel Montez
BANNED Off Offline

Zitieren
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

alt Re: Explosion not working

Louie
User Off Offline

Zitieren
@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

alt Re: Explosion not working

DC
Admin Off Offline

Zitieren
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

alt Re: Explosion not working

Louie
User Off Offline

Zitieren
@user DC: Ok here is my full script:
Mehr >

alt Re: Explosion not working

DC
Admin Off Offline

Zitieren
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

alt Re: Explosion not working

Yates
Reviewer Off Offline

Zitieren
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.

alt Re: Explosion not working

Louie
User Off Offline

Zitieren
@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

alt Re: Explosion not working

DC
Admin Off Offline

Zitieren
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.

alt Re: Explosion not working

Louie
User Off Offline

Zitieren
@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

alt Re: Explosion not working

DC
Admin Off Offline

Zitieren
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).

alt Re: Explosion not working

Louie
User Off Offline

Zitieren
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
1× editiert, zuletzt 09.02.15 17:11:11

alt Re: Explosion not working

DC
Admin Off Offline

Zitieren
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")
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht