Forum

> > CS2D > Scripts > ToTable
Forums overviewCS2D overview Scripts overviewLog in to reply

English ToTable

27 replies
Page
To the start Previous 1 2 Next To the start

old ToTable

Obviously Exactly Myself
User Off Offline

Quote
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.
edited 1×, last 17.02.13 01:51:25 pm

old Re: ToTable

Suprise
BANNED Off Offline

Quote
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

old Re: ToTable

Gajos
BANNED Off Offline

Quote
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

old Re: ToTable

Flacko
User Off Offline

Quote
This
user VADemon has written
1
timer(1500,"tank_reload",tostring(id))


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

old Re: ToTable

Obviously Exactly Myself
User Off Offline

Quote
user Alistaire has written
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
edited 1×, last 17.02.13 12:25:10 pm

old Re: ToTable

Alistaire
User Off Offline

Quote
user Obviously Exactly Myself has written
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.

old Re: ToTable

Flacko
User Off Offline

Quote
Then show us how and where you declared toTable.

old Re: ToTable

Obviously Exactly Myself
User Off Offline

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

old Totable script

UnkN
User Off Offline

Quote
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

old Re: ToTable

uaiek
User Off Offline

Quote
Use "ToTable" not the "toTable" one.
Declaring function name is 'case-sensative', so write the copy of the declared name function to call it.
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview