Forum

> > CS2D > Scripts > Mistake in script because of "p" ?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Mistake in script because of "p" ?

9 replies
To the start Previous 1 Next To the start

old Mistake in script because of "p" ?

Rainoth
Moderator Off Offline

Quote
Hello all. I was making simple script and I added one little detail here in this code :
1
2
3
4
5
6
7
8
9
10
addhook("second","sec")
function sec()
timeit=timeit+1
	if timeit>=90 then
timeit=0
		for p = 1,32 do
			parse("equip "..p.." 65")
		end
	end
end
Gives no error but doesn't do it's function - give item after every 90 seconds. I may be wrong but could it be because I used "for p =1,32 do" ?

old Re: Mistake in script because of "p" ?

wotaan
User Off Offline

Quote
maybe its because u cant equip bandage..
if u want to heal players every 90secs u can use this one-->
1
2
3
4
5
6
7
8
9
10
11
12
13
timeit=0
addhook("second","sec")
function sec()
timeit=timeit+1
	if timeit>=90 then
	timeit=0
		for p = 1,32 do
			if player(p,"exists") then
				parse("sethealth "..p.." "..player(p,"health")+20)
			end
		end
	end
end

old Re: Mistake in script because of "p" ?

Yates
Reviewer Off Offline

Quote
@user wotaan: You can use the command equip with bandages. It simply heals you the amount of heath set by the server.

I always use the following to for players and if they exist:
1
for _,p in pairs(player(0,"table")) do
Your code seems fine. Is that all of it?
edited 1×, last 23.02.13 01:36:55 am

old Re: Mistake in script because of "p" ?

VADemon
User Off Offline

Quote
@user wotaan: you forgot the max. health that's why his solution is pretty good.

@user Rainoth: Learn to insert debug into your script if it doesn't work.


UPDATED CODE (01:49 gmt+1):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
timeit=0 --define the variable first
addhook("second","sec")
function sec()
timeit=timeit+1
     if timeit>=9 then --change the time
		timeit=0
		msg("Bandage timer tick@C")
        for p = 1,32 do
			if player(p,"exists") then
				if player(p, "maxhealth") ~= player(p, "health") then --to prevent annoying noises every X seconds
					msg(player(p,"name").." got a bandage!")
					parse("equip "..p.." 65")
				else
					msg(player(p,"name").." has enough HP!")
				end
			end
        end
     end
end

UPD: @user Yates: the existing player table would be the next step. Let him learn from basics
edited 1×, last 23.02.13 01:49:57 am

old Re: Mistake in script because of "p" ?

Yates
Reviewer Off Offline

Quote
@user Rainoth: Is the timeit actually defined in your whole code? - If this is your whole code or it is not defined then do what VADemon did at line 1. You define timeit to be 0 when the server starts, but I'm pretty sure if you did not define it would come with an error something about trying to do something mathematical with a nil value.

@user VADemon: Ah, I shall not come with my own code then when someone asks for help but simply fix theirs. It took me long to understand some functions in Lua so I guess it is the same for Raining Mammoths and others. Thanks for the note.

old Re: Mistake in script because of "p" ?

Rainoth
Moderator Off Offline

Quote
I spoke with Flacko and it turns out everything was fine. I'm still going to study these examples you gave me (and probably use them in my script because they are more potent) So.. A big thanks
And yes I'm still learning. Today learned about hud and and these "x=x+1 ; if x = y then x=0" .. Well you get the point. One more question. Maybe a bit off topic but still about scripting : I've been to few servers where huds are glowing in rainbow colors, however when it comes to what I learned (from sample) it can only change the color intensity. Like Yellow becomes Red, blurs and alike but can't become Like Yellow > Red > Orange > Green > Random color. Anyone know how to do it ?

old Re: Mistake in script because of "p" ?

Yates
Reviewer Off Offline

Quote
I'm not going to write the whole code for you but here is what you do;

Use second hook;
1
2
3
4
5
6
7
8
9
10
11
12
13
hudtxtchange = 0 -- Don't place in the second hook, this is to define hudtxtchange to 0 so we can add, multiply, devide by etc. You can also set this value to something else so when the server starts the hudtxt will start at green for example instead of red.

-- Second hook begins;
hudtxtchange = hudtxtchange + 1
if hudtxtchange == 1 then
	parse("hudtxtcolorfade 0 1 1000 255 0 0")
elseif hudtxtchange == 2 then
	parse("hudtxtcolorfade 0 1 1000 0 255 0")
elseif hudtxt change == 3 then
	parse("hudtxtcolorfade 0 1 1000 0 0 255")
	hudtxtchange = 0
end
-- Second hook ends

Notice that I changed the value of hudtxt change on my last elseif to 0. This is to repeat the whole cycle again.

Here is some info to show you what all the values mean in the hudtxtcolorfade command;
http://cs2d.com/help.php?cat=all&cmd=hudtxtcolorfade#cmd

I just noticed something about it blurring, if you want to change it instantly then you can either use this command and change the time in which it fades to 0 or configure your hudtxt itself (When you create it, copy/paste that code and change the colour).

old Re: Mistake in script because of "p" ?

Rainoth
Moderator Off Offline

Quote
Thank you very much. It works perfectly. One more thing. Does anyone know the color code for default yellow in CS2D ? For all messages and huds it uses yellow color. I wrote script to fade 255 255 0 (yellow) but it isn't exactly that color. I want the fading to be smooth and no cut-ups when fading (like suddenly another color appears)
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview