Scripts / script help neeeded crate opens at damage

Author
Message
HarryWever
3D Media Maker
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location: below Sea level
Posted: 3rd Apr 2015 08:45
Hello,
Is it possible to play a animation on a entity when taken a amount off damage?
So that my crate opens ( play the animation) when i take two shot at it.
Can anybody help me with this and explain step by step how that is done and why.
It is for me a learning process, i don't know anything about coding, and trying to learn things.
I can make several things, but with scripting the things come alive.

So many thanks
harry


Harry
PM
HarryWever
3D Media Maker
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location: below Sea level
Posted: 3rd Apr 2015 10:20
I did it.... yeeeee.. I am so proud of myself...



The script.

Harry
PM
AuShadow
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 3rd Apr 2015 10:28 Edited at: 3rd Apr 2015 10:35
nice job, and congrats, you'll be making some excellent scripts soon if this is how quick you found your own solution

just as a heads up the player distance math work isn't really needed anymore, there is a function call to get player distance:

PlayerDist = GetPlayerDistance(e)

with that you can the just check PlayerDist < whatever distance

sorry just read your script a bit more properly and you dont use the player distance math at all so that can all be removed



I also moved the set health otherwise if you do less then 100 damage everytime the script cycles i think it would reset the health to 100 again, havent tested but i think thats what would happen, and think it should mwork in the init, dont have time to test it myself but hope that helps you see how to make your code a bit cleaner
PC Specs: Windows 7 home 64-bit, Amd 7900 3gb DDR5 graphics, 8gb DDR3 Ram, Intel i7 3.4ghz
HarryWever
3D Media Maker
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location: below Sea level
Posted: 3rd Apr 2015 15:32
Oke thank you.
and your right with the reset of the health, if i choose a smaller weapon then i can't destroy the entity anymore.
So i will give a look at this.
Thanks
Oh yeah. is it possible that the destroyed entity dissapear when your not in sight anymore.
Or fade slowly.
If the debris stay there it consumes resources.
I saw the Hide(e) and destroy(e) but if i put that under the line the entity is already gone when i test the level.

many thanks
Harry
Dagored
Harry
PM
J_C
17
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 3rd Apr 2015 15:37
AuShadow - I thought the same thing about moving it to the init function...
I used the double doors to test it... but the doors animate and open before you shoot them
So I think Harry's box will explode with out shooting it..

I change Harry's
SetAnimationFrames(15,100)
to
SetAnimation(0)
to use the door animations...from the double door FPE file..

Harry's original code works.. I shoot the door and it opens
but...
I shoot the open door and is closes and opens again...

So I am thinking...
Harry if you shoot the box debris does it reassemble and fly apart again... ?

Thank you Harry - I have learned something from your script and I enjoyed playing with the door..
I have now modified the script to open and close the door by shooting is with shotgun..
I have put in lots of rems... to explain my journey to my final script...I will post it.. so you can check it out...
PM
HarryWever
3D Media Maker
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location: below Sea level
Posted: 3rd Apr 2015 16:02
Hey J_C

No if i shoot again the debris stay on the floor.
Maybe its because i used the SetAnimationFrames.. but i really don't know for sure.
I am also learning,


Cheers
Harry
PM
HarryWever
3D Media Maker
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location: below Sea level
Posted: 3rd Apr 2015 21:02 Edited at: 3rd Apr 2015 21:40
With The adjusted script from J_C thanks.




cheers
Harry
PM
AuShadow
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 4th Apr 2015 06:21
You could try this to destroy when distanced:

PC Specs: Windows 7 home 64-bit, Amd 7900 3gb DDR5 graphics, 8gb DDR3 Ram, Intel i7 3.4ghz
HarryWever
3D Media Maker
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location: below Sea level
Posted: 4th Apr 2015 09:31
Thank you AuShadow,
It is working like a charm now
This is great. now the crate debris are gone and i can see the fps come back.

Many thanks for everybodys help.

Harry
Harry
PM
HarryWever
3D Media Maker
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location: below Sea level
Posted: 4th Apr 2015 10:10
I will put the script in the store for download for free.

Gr
harry
Harry
PM
J_C
17
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 4th Apr 2015 12:04
Harry great video...

It would be even better.. if when the box explodes..
out pops a health or ammo Entity.. or something needed for game...

PM
HarryWever
3D Media Maker
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location: below Sea level
Posted: 4th Apr 2015 15:48
Yep that is true. for a test i put a health box inside the crate. but then if you walk nearby the crate you get the health Always.
So maybe with scripting.

Harry
Harry
PM
perelect
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 12th Apr 2015 05:39
Hi

If you place a health item inside/under the box and adjust the player distance it might work.

I adjusted the health.lua as shown below.



-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Player Collects Health

function health2_init(e)
end

function health2_main(e)
PlayerDist = GetPlayerDistance(e)
if PlayerDist < 40 and g_PlayerHealth > 0 then
PromptDuration("Collected health",3000)
PlaySound(e,0)
AddPlayerHealth(e)
Destroy(e)
ActivateIfUsed(e)
end
end

I adjusted it to 40, at this you can walkover the top of the item and not pick it up, but once you crouch over the top of it you can pick it up.
So just play with that value until your happy.
I didn't try it with the box as I don't own an explode able box.


perelect
I may be old, but at least my memory still ....mmm
HarryWever
3D Media Maker
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location: below Sea level
Posted: 12th Apr 2015 08:11
thanks,
I will try that out.

Harry
Harry
PM

Login to post a reply

Server time is: 2024-12-21 14:00:49
Your offset time is: 2024-12-21 14:00:49