Forum

> > CS2D > Scripts > timer script
Forums overviewCS2D overview Scripts overviewLog in to reply

English timer script

10 replies
To the start Previous 1 Next To the start

old closed timer script

Powermonger
User Off Offline

Quote
So, again I am TRYING to make a script, but I don't know how to make one thing in it.

So here's the thing:

I have a hook that reduces money when he moves (like a fuel in f1).
Hook "pitstop" will still player, calculate his "tmr" and suspend him.
After the time his speed will be set to his own "sped[id]" and he will get full "tank" (16000$).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
for i=1,15,1 do
sped[i] = 0
end
fuel = player(id,"money")
tmr = 16000-fuel

addhook("move","pitstop")
function pitstop(id,x,y)
	if (player(id,"tilex")==27) then
		if (player(id,"tiley")==52) then
			parse("speedmod "..id.." -150")
			parse("setmaxhealth "..id.." 101")
			timer(tmr,"parse","speedmod "..id.." "..sped[id].."")
			timer(tmr,"parse","setmoney "..id.." 16000")
		end
	end
end

There's something wrong in the script, could you guys please pinpoint the error for me.
I would appreciate it.

...again : )

old Re: timer script

Apache uwu
User Off Offline

Quote
If that's the full script, then you should probably get an error about id being nil.

Is this the full script?

old Re: timer script

Powermonger
User Off Offline

Quote
Nope, there's like hundred lines more in it, but they are not connected to this.

True, id gets a nill value, but I don't know how to fix it : /
Can you please tell me how to fix it?

But...

...is the rest okay? Can I use variable "tmr" in the timer?

old Re: timer script

Apache uwu
User Off Offline

Quote
Please place

fuel=player(id,"money")
tmr=16000-fuel


inside of the move hook function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
for i=1,15 do
	sped[i]=0
end

addhook("move","pitstop")
function pitstop(id,x,y)
	if player(id,"tilex")~=27 then
		return
	end
	if player(id,"tiley")~=52 then
		return
	end
	parse("speedmod "..id.." -150")
	parse("setmaxhealth "..id.." 101")
	fuel=player(id,"money")
	tmr=16000-fuel
	timer(tmr,"parse","speedmod "..id.." "..sped[id].."")
	timer(tmr,"parse","setmoney "..id.." 16000")
end

Please try this.

I have made it not more efficient but more pleasing to the eye.

old Re: timer script

Powermonger
User Off Offline

Quote
Dam still doesn't work.

I also tested to replace "..sped[id].." to just a number.

It worked.

But then I tried again to "pit", but it didn't set my speed to -150.


Is there a way to just still player, and have him suspended till he gots total 16000$ (I will ofcourse make a dispenter next to the player).

I would only need something like:

Check if player has 16000$.
If false => hold him
If true => parse("speedmod "..id.." "..sped[id].."")

That would be so simple, but is it possible?

old Re: timer script

Apache uwu
User Off Offline

Quote
Try this:

1
2
3
4
5
if player(id,"money")==16000 then
	parse("speedmod "..id.." "..sped[id].."")
else
	parse("speedmod "..id.." -50")
end

Please place this in the appropriate area.

old Re: timer script

Powermonger
User Off Offline

Quote
But if I ain't wrong, it'll check it only one time.

It takes a while to "pit" and this case, I thought to have "mp_dispenser_money 500".

It needs to check the money multiple times.

I could use a "Second" hook, but is there an easier way?

old Re: timer script

EngiN33R
Moderator Off Offline

Quote
Hmm, I elaborated on user Apache uwu's code a little and tested this piece:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
sped={}

for i=1,15 do
    sped[i]=0
end

addhook("movetile","pitstop")
function pitstop(id,x,y)
    if x==27 and y==52 then
		parse("speedmod "..id.." -100")
		parse("setmaxhealth "..id.." 101")
		tmr=(16000-player(id,"money"))/game("mp_dispenser_money")*1000
		msg(tmr)
		timer(tmr,"parse","speedmod "..id.." "..sped[id])
		timer(tmr,"parse","setmoney "..id.." 16000")
    end
end

If I understood the concept correctly, you hold the player there (near a dispenser) until they have 16000, correct? Correct my thinking if it's wrong.

This code is flexible, so with any dispenser money quota it will function correctly - I tested with 500 and 4000.

old Re: timer script

Powermonger
User Off Offline

Quote
EngiN33R you understood it correctly!

Thank you both kaesuruto and EngiN33R!
That part of my script now works like a dream!

This thread can be now closed, I am very happy of the results, big thanks to you guys again!

More threads will be opened for lots of my scripting problems.
Sorry, it's sad but true. I hope you are able to help me in the future
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview