Forum

> > CS2D > Scripts > What is wrong in this script?
Forums overviewCS2D overview Scripts overviewLog in to reply

English What is wrong in this script?

11 replies
To the start Previous 1 Next To the start

old What is wrong in this script?

Avo
User Off Offline

Quote
It's my new gamemode script:
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
54
55
56
57
58
59
60
zones=1				
cz=math.random(1,zones) --currentzone
inzone=array(32)
zonetime=0
zonetimelimit=30
zonedrop=0
zonedroplimit=10
zonetiles=9			--default 3x3=9
items={76,76,89,47,79,79,76}

dz_x=	{	
		zonex1={0,1,2,0,1,2,0,1,2}		
	}

dz_y=	{	
		zoney1={0,0,0,1,1,1,2,2,2}		
	}


addhook('move','checkpos')
function checkpos(id,x,y)
	x=math.floor(x/32)
	y=math.floor(y/32)
	for i=1,zonetiles do
		if x==dz_x[cz][i] then		--here is error
			for s=1,zonetiles do
				if y==dz_y[cz][s] then
					inzone[id]=1
				else
					inzone[id]=0
				end
			end
		end
	end
end

addhook('second','second')
function second()
	for i=1,32 do
		if inzone[i]==1 then
			local mn=player(i,'money')+50
			parse('setmoney '..i..'' ..mn..'')
		end
	end

	zonetime=zonetime+1
	zonedrop=zonedrop+1
	if zonetime==zonetimelimit then
		zonetime=0
		currentzone=math.random(1,zones)
	end
	if zonedrop==zonedroplimit then
		local t=math.random(1,zonetiles)
		local x=dz_x[cz][t]
		local y=dz_y[cz][t]
		local i=math.random(1,#items)
		parse('spawnitem '..i..' '..x..' '..y..'')
		zonedrop=0
	end
end
I think everthing should works, but it not. When I run the script I see in a cosole:

'dropzone_gamemode.lua:40: attempt to index field '?'(a nil value)'

What does it mean? And what is incorrect?
edited 1×, last 10.03.12 12:49:28 am

old Re: What is wrong in this script?

Avo
User Off Offline

Quote
So how can I call first value of 'zonex1' in 'dz_x'?
I mean: if currentzone is 1 I want to get a values of first array in array 'dz_x' ('zonex1').
edited 1×, last 10.03.12 12:07:09 am

old Re: What is wrong in this script?

Avo
User Off Offline

Quote
It will be script for example for map de_dust.
In tables dz_x & dz_y you write coordinatives of tiles of Drop Zone. Every 30s drop zone is changed to one of added to the tables. Each Drop Zone has got 9 tiles(3x3). You can add many Drop Zones...

When player get to the current Drop Zone, he'll get 50$/s (when he is still in Drop Zone). Every 10 s on the Drop Zone will spawn random items from array 'items'.

It's like mode in Call of Duty Modern Warfare 3 'Drop Zone'.
edited 1×, last 10.03.12 12:37:05 am

old Re: What is wrong in this script?

EngiN33R
Moderator Off Offline

Quote
user Anders4000 has written
Typing "dz_x[cz][i]" is not possible.
A table can't have two indexes i guess.


A table can have up to lots and lots of indices. Study tables more closely before saying such things.

@user Avo: Never use
1
for i=1,32 do
to iterate through players. Use
1
for _,i in pairs(player(0,"table"))
at least.

Also, what the hell is with that coordinates table? Does it have a value for each tile? You could make it like so:

1
dz_pos = {0,0,2,2} --x beginning, y beginning, x end, y end

Then change your move hook and its function to this:

1
2
3
4
5
6
7
8
9
10
11
12
addhook('movetile','checkpos')
function checkpos(id,x,y)
     for xx=dz_pos[1],dz_pos[3] do
           for yy=dz_pos[2],dz_pos[4] do
                if x==xx and y==yy then
                     inzone[id]=true
                else
                     inzone[id]=false
                end
           end
      end
end

And then change
1
if inzone[i]==1 then
to
1
if inzone[i] then

Try and tell me if it works.

old Re: What is wrong in this script?

Avo
User Off Offline

Quote
user EngiN33R
Eeee... Can you explain me how 'pairs' works? Becouse I don't understand...

Note:there would be more than 1 zone in table. If I want get values of current zone(current zone is changed every 30s)? Only players in current zone will get money. For example:
1
2
3
4
5
6
7
8
dz_x=	{
		zonex1={}
		zonex2={}
	}
dz_y=	{
		zoney1={}
		zoney2={}
	}
I think it could be easier if one zone has got only 1 tile(1x1), not 9(3x3).

old Re: What is wrong in this script?

Apache uwu
User Off Offline

Quote
@user EngiN33R: Actually there are times when you need to loop through every player--existent or not, it depends on the context.

I'm still unsure what you are trying to do, the code looks broken, if you can describe the idea maybe we can make it. √

old Re: What is wrong in this script?

EngiN33R
Moderator Off Offline

Quote
user Apache uwu has written
@user EngiN33R: Actually there are times when you need to loop through every player--existent or not, it depends on the context.


Well, yes, you're right, but when you know Lua good enough to understand when such context is - it'll come to you that you need to use that exact loop.

@user Avo: It's a long and a little bit complicated a script, so I think you should start off doing some easier things and then come onto this kind of mods, no offence.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview