Forum

> > CS2D > Scripts > Sleep Script
Forums overviewCS2D overview Scripts overviewLog in to reply

English Sleep Script

16 replies
To the start Previous 1 Next To the start

old Sleep Script

Bobakrome
User Off Offline

Quote
Hi all, can someone help me with a script? If you do there is what i want:

If player stands on a Trigger_Use called "Sleep" if press e then he go fade to sleep i mean:

Sleep

Screen fades to black, then it will be black for a 5,10 sec idk, then when screen fades to normal after 5,10 sec the player will have full health.

cookie For help..

old Re: Sleep Script

EngiN33R
Moderator Off Offline

Quote
user itsoxymoron has written
What if you make a Trigger_use/move - Trigger delay and Env - sprite?


That will make it visible to all people, he asks it to be visible for one player only.

1
2
3
4
5
6
7
8
9
10
11
12
13
sleepx,sleepy = 1,1 -- coordinates of the button

addhook("usebutton","sleepbut")
function sleepbut(id,x,y)
	if x==sleepx and y=sleepy then
		local sleepi=image("gfx/sprites/block.bmp",320,240,2,id)
		imagealpha(sleepi,0)
		tween_alpha(sleepi,1000,1)
		timer(6000,"parse","lua tween_alpha("..sleepi..",1000,0)") --delay of 6 seconds because fading takes up 1
		timer(6000,"parse","sethealth "..id.." "..player(id,"maxhealth"))
		timer(7000,"parse","lua freeimage("..sleepi..")") --delay of 7 seconds because both fades take up 2
	end
end

I think this should work.

old Re: Sleep Script

itsoxymoron
User Off Offline

Quote
user EngiN33R has written
user itsoxymoron has written
What if you make a Trigger_use/move - Trigger delay and Env - sprite?


That will make it visible to all people, he asks it to be visible for one player only.

1
2
3
4
5
6
7
8
9
10
11
12
13
sleepx,sleepy = 1,1 -- coordinates of the button

addhook("usebutton","sleepbut")
function sleepbut(id,x,y)
	if x==sleepx and y=sleepy then
		local sleepi=image("gfx/sprites/block.bmp",320,240,2,id)
		imagealpha(sleepi,0)
		tween_alpha(sleepi,1000,1)
		timer(6000,"parse","lua tween_alpha("..sleepi..",1000,0)") --delay of 6 seconds because fading takes up 1
		timer(6000,"parse","sethealth "..id.." "..player(id,"maxhealth"))
		timer(7000,"parse","lua freeimage("..sleepi..")") --delay of 7 seconds because both fades take up 2
	end
end

I think this should work.


Oh, sorry, i understood.

old Re: Sleep Script

Bobakrome
User Off Offline

Quote
I want if the Trigger_Use is called "Sleep" or if have at "Trigger": "sleep"

Because i need every bed in my happy town to do that so, its really much..

old Re: Sleep Script

EngiN33R
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
addhook("usebutton","sleepbut")
function sleepbut(id,x,y)
	if entity(x,y,"name")=="sleep" then
		local sleepi=image("gfx/sprites/block.bmp",320,240,2,id)
		imagealpha(sleepi,0)
		tween_alpha(sleepi,1000,1)
		timer(6000,"parse","lua tween_alpha("..sleepi..",1000,0)") --delay of 6 seconds because fading takes up 1
		timer(6000,"parse","sethealth "..id.." "..player(id,"maxhealth"))
		timer(7000,"parse","lua freeimage("..sleepi..")") --delay of 7 seconds because both fades take up 2
	end
end

old Re: Sleep Script

Bobakrome
User Off Offline

Quote
user EngiN33R has written
1
2
3
4
5
6
7
8
9
10
11
addhook("usebutton","sleepbut")
function sleepbut(id,x,y)
	if entity(x,y,"name")=="sleep" then
		local sleepi=image("gfx/sprites/block.bmp",320,240,2,id)
		imagealpha(sleepi,0)
		tween_alpha(sleepi,1000,1)
		timer(6000,"parse","lua tween_alpha("..sleepi..",1000,0)") --delay of 6 seconds because fading takes up 1
		timer(6000,"parse","sethealth "..id.." "..player(id,"maxhealth"))
		timer(7000,"parse","lua freeimage("..sleepi..")") --delay of 7 seconds because both fades take up 2
	end
end


Thinking of that may work but idk, when i start my server

"EXCEPTION_ACCESS_VIOLATION"

Uh when i edited from

1
dofile(htdirectory .. 'GoSleep.lua')
to
1
--dofile(htdirectory .. 'GoSleep.lua')
It worked then..
Maybe is something wrong with script

old Re: Sleep Script

DC
Admin Off Offline

Quote
dofile crashes the game as soon as the script has a bug. this will be fixed.

old Re: Sleep Script

Bobakrome
User Off Offline

Quote
user DC has written
dofile crashes the game as soon as the script has a bug. this will be fixed.


Uhh then it will be hard to see script's bugs...

old Re: Sleep Script

Obviously Exactly Myself
User Off Offline

Quote
user Bobakrome has written
user EngiN33R has written
1
2
3
4
5
6
7
8
9
10
11
addhook("usebutton","sleepbut")
function sleepbut(id,x,y)
	if entity(x,y,"name")=="sleep" then
		local sleepi=image("gfx/sprites/block.bmp",320,240,2,id)
		imagealpha(sleepi,0)
		tween_alpha(sleepi,1000,1)
		timer(6000,"parse","lua tween_alpha("..sleepi..",1000,0)") --delay of 6 seconds because fading takes up 1
		timer(6000,"parse","sethealth "..id.." "..player(id,"maxhealth"))
		timer(7000,"parse","lua freeimage("..sleepi..")") --delay of 7 seconds because both fades take up 2
	end
end


Thinking of that may work but idk, when i start my server

"EXCEPTION_ACCESS_VIOLATION"

Uh when i edited from

1
dofile(htdirectory .. 'GoSleep.lua')
to
1
--dofile(htdirectory .. 'GoSleep.lua')
It worked then..
Maybe is something wrong with script

*facepalm*

Putting "--" will make the line unreadable.

old Re: Sleep Script

Bobakrome
User Off Offline

Quote
Okay, the scripts allow you to walk, its possible to freeze you until you sleep? and oh yeah! the "block" it covers just the player 32x32 pixels, not the full screen
edited 1×, last 03.03.12 01:35:25 pm

old Re: Sleep Script

EngiN33R
Moderator Off Offline

Quote
Oh, whoops. Add these lines before tween_alpha in the if statement:

1
2
3
4
local speed=player(id,"speedmod")
imagescale(sleepi,20,15)
parse("speedmod "..id.." -100")
timer(7000,"parse","speedmod "..id.." "..speed)
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview