Forum

> > CS2D > Scripts > Having trouble with FOR
Forums overviewCS2D overview Scripts overviewLog in to reply

English Having trouble with FOR

4 replies
To the start Previous 1 Next To the start

old Having trouble with FOR

xSkyLordx
User Off Offline

Quote
Hello guys im having a trouble with using FOR
idk how to explain ummm.. if there is 3 Table it deals 3 times DMG. like this.. this is not my problem but its like this i tried to explain more in script with "--" 's thanks

Script:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
addhook("attack","_attack")
function _attack(id)
local dmg = 0
	for _,r in ipairs(robot) do
		if r.owner==id and r.mod==1 then
			dmg = r.dmg
			msg("ROBOOTT") --MSG X Times How many robot table in
		end
	end
	if pmod[id]==1 then
	--for _,id2 in pairs(player(0,"tableliving")) (if i do this it will dmg X how many player in game)
	--DMG scriptt hp-dmg bla bla..
end	
end


i cant speak english that good but i think i explained myself thankkss

ok i edited

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
addhook("attack","_attack")
function _attack(id)
local dmg = 0
	for _,r in ipairs(robot) do
		if r.owner==id and r.mod==1 then
			dmg = r.dmg
			msg("ROBOOTT") --MSG X Times How many robot table in
		end
	end
	if pmod[id]==1 then
	for _,id2 in pairs(player(0,"tableliving")) do
	parse("sethealth "..id2.." "..dmg.."") --if 3 players online it deals 60DMG Robot dmg is 20
	end
    end
end	
end

if 3 player online it deals 3xRobot Dmg == 60 my robot dmg is 20
edited 2×, last 12.04.16 03:22:58 pm

old Re: Having trouble with FOR

Dousea
User Off Offline

Quote
I can't help you enough if you don't provide enough information about your current problem. Also you need to show all your code so we can figure out your problem easily. Basically what you're doing is right in your code.

old Re: Having trouble with FOR

xSkyLordx
User Off Offline

Quote
Spoiler >


Its just nothing more than i show you , you know how "for" works

1
2
3
for a=1,10 do
msg("message")
end
its just message 10 time , i want it to message for 1 time
i want take information,values from table but use it 1 time

im trying to deal dmg to player for one time but it will dmg 5 times (5player=5time) this is just example

in my script if you have 2 robot it messages 2 time i need to fix this so i can code my lua to dmg

im not that good at english sorry for something wrong

ok i edited my script addhook("attack..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
addhook("attack","_attack")
function _attack(id)
local dmg = 0
	for _,r in ipairs(robot) do
		if r.owner==id and r.mod==1 then
			dmg = r.dmg
			msg("ROBOOTT") --MSG X Times How many robot table in
		end
	end
	if pmod[id]==1 then
	for _,id2 in pairs(player(0,"tableliving")) do
	parse("sethealth "..id2.." "..dmg.."") --if 3 players online it deals 60DMG Robot dmg is 20
	end
    end
end	
end

if 3 player online its deals 60dmg robot dmg is 20
20xHow many players are online
edited 2×, last 12.04.16 03:24:08 pm

old Re: Having trouble with FOR

Mami Tomoe
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
addhook("attack","_attack")
function _attack(id)
local dmg = 0
	if r.owner==id and r.mod==1 then
		for _,r in ipairs(robot) do
			robotfunction(dmg)
			break
		end
	end
	if pmod[id]==1 then
		for _,id2 in pairs(player(0,"tableliving")) do
			parse("sethealth "..id2.." "..dmg.."")
		end
    end
end

function robotfunction(dmg)
	dmg = r.dmg
	msg("ROBOOTT")
end

Try this.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview