View previous topic :: View next topic |
Author |
Message |
NintendoZACHERY Newbie
Joined: 07 Feb 2008 Posts: 8
|
Posted: Sat May 24, 2008 1:48 am Post subject: While Hitting (Hard Challange) |
|
|
Hello, I have a idea for A Brick Script Where:
1. You Tuch it (Keep Tuching)
2.While hitting the brick You loose 2 health
3. If not hitting the brick you stop lossing health.
By my understanding this is Very difficult. I asked ICE128 he didn't know how, and i even asked Telamon, He didn't know.
as you can see this is a hard challange. |
|
Back to top |
|
|
SirGelatina Site Admin
Joined: 01 Mar 2008 Posts: 116 Location: Behind you
|
Posted: Sat May 24, 2008 2:47 am Post subject: |
|
|
Not sure if it will work
Code: | local damagepercycle = 2
local delaybetweendmg = 1 -- In Seconds
function returnInverse(num)
if num == 2 or num == 4 or num == 6 then
return num - 1
else
return num + 1
end
end
function checkIfTouching(part)
local one = {}
local one[1] = part.Position.y + ( part.Size.y / 2 )
local one[2] = part.Position.y - ( part.Size.y / 2 )
local one[3] = part.Position.x + ( part.Size.x / 2 )
local one[4] = part.Position.x - ( part.Size.x / 2 )
local one[5] = part.Position.z + ( part.Size.z / 2 )
local one[6] = part.Position.z - ( part.Size.z / 2 )
local two = {}
local obj = script.Parent
local two[1] = obj.Position.y + ( obj.Size.y / 2 )
local two[2] = obj.Position.y - ( obj.Size.y / 2 )
local two[3] = obj.Position.x + ( obj.Size.x / 2 )
local two[4] = obj.Position.x - ( obj.Size.x / 2 )
local two[5] = obj.Position.z + ( obj.Size.z / 2 )
local two[6] = obj.Position.z - ( obj.Size.z / 2 )
for x=1, #one do
if one[x] - two[returnInverse(x)] > -1 then
return false
end
end
return true
end
function onTouched(Toucher)
local humanoid = Toucher.Parent:findFirstChild("Humanoid")
if humanoid ~= nil then
repeat
humanoid.Health = humanoid.Health - damagepercycle
wait(delaybetweendmg)
until checkIfTouching(Toucher) == false
end
end
script.Parent.Touched:connect(onTouched) |
|
|
Back to top |
|
|
NintendoZACHERY Newbie
Joined: 07 Feb 2008 Posts: 8
|
Posted: Wed May 28, 2008 7:17 pm Post subject: |
|
|
Daaaaang but it didnt work sorry =P |
|
Back to top |
|
|
SirGelatina Site Admin
Joined: 01 Mar 2008 Posts: 116 Location: Behind you
|
Posted: Wed May 28, 2008 7:29 pm Post subject: |
|
|
It works only for non-collidable bricks. �t checks if any of your bodyparts or another brick is IN the script's Parent. For collidable bricks, it would be needed another script. |
|
Back to top |
|
|
SirGelatina Site Admin
Joined: 01 Mar 2008 Posts: 116 Location: Behind you
|
Posted: Wed May 28, 2008 8:25 pm Post subject: |
|
|
I made some mistakes on the script. Try this:
Code: | local damagepercycle = 2
local delaybetweendmg = 1 -- In Seconds
function returnInverse(num)
if num == 2 or num == 4 or num == 6 then
return num - 1
else
return num + 1
end
end
function checkIfTouching(part)
local one = {}
one[1] = part.Position.y + ( part.Size.y / 2 )
one[2] = part.Position.y - ( part.Size.y / 2 )
one[3] = part.Position.x + ( part.Size.x / 2 )
one[4] = part.Position.x - ( part.Size.x / 2 )
one[5] = part.Position.z + ( part.Size.z / 2 )
one[6] = part.Position.z - ( part.Size.z / 2 )
local two = {}
local obj = script.Parent
two[1] = obj.Position.y + ( obj.Size.y / 2 )
two[2] = obj.Position.y - ( obj.Size.y / 2 )
two[3] = obj.Position.x + ( obj.Size.x / 2 )
two[4] = obj.Position.x - ( obj.Size.x / 2 )
two[5] = obj.Position.z + ( obj.Size.z / 2 )
two[6] = obj.Position.z - ( obj.Size.z / 2 )
local countIn = 0
for x=1, #one do
if x == 1 or x == 3 or x == 5 then
if one[x] > two[returnInverse(x)] then
countIn = countIn +1
end
else
if one[x] < two[returnInverse(x)] then
countIn = countIn +1
end
end
end
print (countIn)
if countIn == 6 then
return true
end
return false
end
function onTouched(Toucher)
local humanoid = Toucher.Parent:findFirstChild("Humanoid")
if humanoid ~= nil then
repeat
humanoid.Health = humanoid.Health - damagepercycle
wait(delaybetweendmg)
until checkIfTouching(Toucher) == false
end
end
script.Parent.Touched:connect(onTouched) |
|
|
Back to top |
|
|
NintendoZACHERY Newbie
Joined: 07 Feb 2008 Posts: 8
|
Posted: Wed May 28, 2008 8:54 pm Post subject: |
|
|
Yay It Works, Thanks. But uh. Also. Could You Make It Slightly Simplifyed To Where Theres a Section in the script you can make it do other things? and also, it works. but not All the time. |
|
Back to top |
|
|
SirGelatina Site Admin
Joined: 01 Mar 2008 Posts: 116 Location: Behind you
|
Posted: Wed May 28, 2008 9:08 pm Post subject: |
|
|
But there IS a section to do that! It's:
function onTouched(Toucher)
local humanoid = Toucher.Parent:findFirstChild("Humanoid")
if humanoid ~= nil then
repeat
humanoid.Health = humanoid.Health - damagepercycle
wait(delaybetweendmg)
until checkIfTouching(Toucher) == false
end
end |
|
Back to top |
|
|
NintendoZACHERY Newbie
Joined: 07 Feb 2008 Posts: 8
|
Posted: Wed May 28, 2008 11:10 pm Post subject: |
|
|
well ok |
|
Back to top |
|
|
|