Forum

> > CS2D > Scripts > ToTable
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch ToTable

27 Antworten
Seite
Zum Anfang Vorherige 1 2 Nächste Zum Anfang

alt ToTable

Obviously Exactly Myself
User Off Offline

Zitieren
It is supposed to make the variable's value into 1 every 1.5 seconds.
The first attack works, but it doesn't the second time.
1
2
3
4
5
6
7
8
9
10
11
12
addhook("attack","tank_attack")
function tank_attack(id)
	if tankatk[id]==1 then
		tankatk[id]=0
		timer(1500,"tank_reload",id)
		parse("spawnprojectile "..id.." 47 "..player(id,"x").." "..player(id,"y").." 300 "..player(id,"rot"))
	end
end

function tank_reload(id)
	tankatk[id]=1
end
Note: This is just a part of the script.
1× editiert, zuletzt 17.02.13 13:51:25

alt Re: ToTable

Suprise
BANNED Off Offline

Zitieren
That's because when you say: 'if tankatk[id]==1 then' then you say that tankatk[id]=0. And because it's 0 the afterwards commands won't work (they would work if tankatk[id]=1)

1
2
3
4
5
6
7
8
9
10
11
12
addhook("attack","tank_attack")
function tank_attack(id)
	if tankatk[id]==1 then
		timer(1500,"tank_reload",id)
		parse("spawnprojectile "..id.." 47 "..player(id,"x").." "..player(id,"y").." 300 "..player(id,"rot"))
		tankatk[id]=0
	end
end

function tank_reload(id)
	tankatk[id]=1
end

I think this is the problem

alt Re: ToTable

Gajos
BANNED Off Offline

Zitieren
This is didn't tested:
1
2
3
4
5
6
7
8
9
10
11
12
addhook("attack","tank_attack")
function tank_attack(id)
     if tankatk[id]==1 then
          tankatk[id]=0
          timer(1500,"tank_reload","id")
          parse("spawnprojectile "..id.." 47 "..player(id,"x").." "..player(id,"y").." 300 "..player(id,"rot"))
     end
end

function tank_reload(id)
     tankatk[id]=1
end

alt Re: ToTable

Flacko
User Off Offline

Zitieren
This
user VADemon hat geschrieben
1
timer(1500,"tank_reload",tostring(id))


And this:
1
2
3
function tank_reload(id)
	tankatk[tonumber(id)]=1
end

alt Re: ToTable

Obviously Exactly Myself
User Off Offline

Zitieren
user Alistaire hat geschrieben
Could only be something else in your script. Or you didn't declare tankatk in the first place.
Checked it, I did.

@user Flacko: Thanks, it works.

--EDIT--

Now the save function doesn't work.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function tank_load(id)
	local l
	if (player(id,"usgn")>0) then
		f=io.open("sys/lua/JeloTanks/Save Data/"..player(id,"usgn")..".sav","r")
		if (f~=nil) then
			for line in f:lines() do
				l=toTable(line)
				uphealth[id]=tonumber(l[1])
				upspeed[id]=tonumber(l[2])
				uprange[id]=tonumber(l[3])
				uprate[id]=tonumber(l[4])
				points[id]=tonumber(l[5])
				break
			end
			f:close()
		end
	end
end
1× editiert, zuletzt 17.02.13 12:25:10

alt Re: ToTable

Alistaire
User Off Offline

Zitieren
user Obviously Exactly Myself hat geschrieben
Now the save function doesn't work.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function tank_load(id)
	local l
	if (player(id,"usgn")>0) then
		f=io.open("sys/lua/JeloTanks/Save Data/"..player(id,"usgn")..".sav","r")
		if (f~=nil) then
			for line in f:lines() do
				l=toTable(line)
				uphealth[id]=tonumber(l[1])
				upspeed[id]=tonumber(l[2])
				uprange[id]=tonumber(l[3])
				uprate[id]=tonumber(l[4])
				points[id]=tonumber(l[5])
				break
			end
			f:close()
		end
	end
end


Can you EVER say what the error is instead of just sending shit saying it's not working? I mean we don't know if ToTable works, if uphealth[id], upspeed[id] etc exist, nothing.

alt Re: ToTable

Flacko
User Off Offline

Zitieren
Then show us how and where you declared toTable.

alt Re: ToTable

Obviously Exactly Myself
User Off Offline

Zitieren
It seems that there was only one line with the word "ToTable".
I forgot how to make a proper load system. BTW, that load part was copied & pasted from my old script that was two years ago.
So actually, I am now trying to ask how to make the load function work.
More Info: I used "tank_load(id)" on the "join" hook to load the USGN User's data.

alt Totable script

UnkN
User Off Offline

Zitieren
Paste it in script.
1
2
3
4
5
6
7
8
function totable(t,match)
     local cmd = {}
     if not match then match = "[^%s]+" end
     for word in string.gmatch(t, match) do
          table.insert(cmd, word)
     end
     return cmd
end

alt Re: ToTable

uaiek
User Off Offline

Zitieren
Use "ToTable" not the "toTable" one.
Declaring function name is 'case-sensative', so write the copy of the declared name function to call it.
Zum Anfang Vorherige 1 2 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht