Scripts / Lua script for a repeating sound

Author
Message
almightyhood
11
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 20th Jan 2014 11:41
hello all, I have been trying to get a sound loop with Lua scripting. so far im unable to figure out why or how this is not working or able to fix it lol, no surprise there really...



below is the script I last tried, according to internet this is supposed to be the easiest way to create a loop but it don't work, any 1 got some pointers for me please??









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

-- Appear and repeat



function appear_main(e)



repeat = true

if 2 > 3



end

have fun stay safe

hood
PM
almightyhood
11
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 20th Jan 2014 12:27
ok did something wrong in above script, forgot to add something.



should of been more like this but still does not work yet..



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

-- Appear and repeat



i = 1



function appear_main(e)



repeat

function appear_main(e)

if i > 3



end





cant believe a simple script is giving me so much trouble lol,.. I know I must be doing something wrong but I am so confused right now cant work it out.

have fun stay safe

hood
PM
Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 20th Jan 2014 12:47 Edited at: 20th Jan 2014 12:49
oh how I miss the FPI command:



loopsound=sound.ogg



and



music=music.ogg



lol

almightyhood
11
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 20th Jan 2014 13:00
yeah?, never got to play fpsc classic or the others myself.

all im trying to do is get a creepy music to loop continuously for the outside world lol but its beyond my abilities lmfao...



does not help that every tutorial is for repeating hello 5 times or printing I a lot ;/.. even Lua.org is little help and that's Lua's main site I think...

have fun stay safe

hood
PM
Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 24th Jan 2014 05:20
The Global LUA script plays a big role in how certain calls are handled. You might want to take a look in there.



Tutorials wont help much until we get a list of variables we can work with to do various functions in Reloaded.



LUA is what everyone wanted so I'm sure we'll get all this sorted soon. I personally did not mind FPI as it was straight forward. But again limiting.

almightyhood
11
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 25th Jan 2014 12:43
i have been using some c'sharp scripting with unity tutorials to try to get my head around some scripting, unfortunately unity4 don't use Lua so im not sure the tuts are much use for reloaded but its interesting to see how and where things work at least. hopefully i can get my head around Lua sooner rather than later lol...



1 thing unity does do is have an option outside of scripting for sound looping, this is far better than scripting a loop sound as it takes care of all that for you. maybe lee can get the same function for reloaded?!.

have fun stay safe

hood
PM
J_C
17
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 27th Jan 2014 18:40
Hood@

Let me see if I can help relieve your confusion.. I think most peoples problem so far is how LUA works with Reloaded..

This is the picture I have in my head when I was playing with the Door script - of how Lua works with Reloaded...



Inside Reloaded Lee has a loop that talks to each Entity. Using its Main LUA script.

So if we look at the Health script as an example.











1. You will see that I have renamed the script file health_find.lua

and the main function health_find_main



2. I have added an else to the PlayerDist if check.

The else portion of the code just shows the Prompt message on the screen with the players distance from the health entity ( healthbox ).



So I copy this new script health_find.lua to scriptbank folder.

I make a test level that only contains the start marker and the healthbox remote from the start maker.

I change the healthbox to use the helath_find.lua script inside reloaded editor properties dialog.( press Apply changes button )

Run the level.



You will see on the screen..

Find the Health - distance to health is 5045 (number depends on you level)

as I move around this number keeps changing - If I am going towards the health it gets smaller..



Now do you see You are already inside a loop (Lee's loop)..

If you put your play sound where the prompt is ... it would keep resetting the sound back to the beginning.

So we need an if statment something like

if PlayingSound0 == 0 then

PlaySound0(e);

end

but we don't have this PlayingSound0 variable from Lee yet...



anyway I hope this helps someone to see how LUA maybe working..

( I am just guessing - but that's the way it seems to work to me )
PM
almightyhood
11
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 27th Jan 2014 20:41
ok.



it would help alittle maybe to know which version of Lua is used with reloaded, 5.2 is currently the newest Lua scripting version but maybe lee used Lua 5.0 or 5.1 or older than that?



also sorry but im no good with this sort of thing, c sharp tutorial for a simple top down space shooter took me about 2 days to finish, with nothing but following and changing the codes as required by the tut lol.. so I don't hold out much hope for me doing anything with Lua until tutorials are released for reloaded tbh m8..



thanks for taking the time to try and help me out though

have fun stay safe

hood
PM
Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 27th Jan 2014 20:59
I'm having a lot of troubles with LUA at the moment but I'm a completely newbie to it. I'm just trying to make it so that when I walk up to a health pack it says press E to take and then it disappears giving you health when you press E. Instead it says press E to take but walking on it still automatically gives you the health.



Guess this will just take a bit more of playing around with.

almightyhood
11
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 27th Jan 2014 21:05
maybe when inventory system is introduced you will have better results?.

I also am a complete noob to scripting in any form lol, so cant help you im afraid m8.



like I said above it took me 2 days str8 doing a 4-6 hour tutorial lol.

watching and repeating should of been easy!, why o why was I cursed with a numbskull brain hahaha..

have fun stay safe

hood
PM
Fane
12
Years of Service
User Offline
Joined: 9th May 2012
Location: Deutschland
Posted: 28th Jan 2014 00:04
Quote: "I'm having a lot of troubles with LUA at the moment but I'm a completely newbie to it. I'm just trying to make it so that when I walk up to a health pack it says press E to take and then it disappears giving you health when you press E. Instead it says press E to take but walking on it still automatically gives you the health.



Guess this will just take a bit more of playing around with."




This is how you can make it. Maybe this will help you in future scripting.



PM
Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 30th Jan 2014 03:05
For some reason I get an error about ""

Fane
12
Years of Service
User Offline
Joined: 9th May 2012
Location: Deutschland
Posted: 30th Jan 2014 08:58
Hmmm, have you name your file pickup_health ?

You have to name your file like the funcion except the _main(e) or you will get an error.
PM
Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 1st Feb 2014 05:25 Edited at: 6th Feb 2014 08:42
I named it take_health, no wonder!



It worked!



Thanks

BarZaTTacKS
10
Years of Service
User Offline
Joined: 3rd Feb 2014
Location:
Posted: 12th Feb 2014 04:31 Edited at: 12th Feb 2014 04:56
http://forum.thegamecreators.com/?m=forum_view&t=205172&b=21



Not sure if anyone here saw the list there, check the function list.



PM
BarZaTTacKS
10
Years of Service
User Offline
Joined: 3rd Feb 2014
Location:
Posted: 12th Feb 2014 04:32 Edited at: 12th Feb 2014 04:55
#NAME?
PM
AuShadow
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 12th Feb 2014 05:03 Edited at: 12th Feb 2014 05:04
I think this lua update is for a fpsc classic mod and not reloaded but I could be wrong

Feel free to visit and edit the public FPSCR resource wiki page



http://fpscrresource.wikispaces.com/home
Imchasinyou
10
Years of Service
User Offline
Joined: 22nd Mar 2014
Location: OH
Posted: 1st Apr 2014 02:01
Ive tried this with weapons and for what ever reason, it wont add the weapon to my inventory during testing. The weapon is picked up, it does disappear after picked up, just not added to inventory.



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

-- Player Collects Weapon by pressing "E"



function pickup_weapon_main(e)

PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;

PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;

PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;

PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs(PlayerDZ*PlayerDZ));

-- Showing Text

if PlayerDist < 100 then

Prompt("Press E to pick up Weapon");

end

-- Player picks up weapon through pressing "E"

if PlayerDist < 80 and g_KeyPressE == 1 then

PlaySound0(e);

AddPlayerWeapon(e);

Destroy(e);

end

--End of function

end



Suggestions?
PM
Scene Commander
Support Manager
16
Years of Service
User Offline
Joined: 3rd May 2008
Location:
Posted: 1st Apr 2014 08:56
@BarZaTTacKS



I'm afraid that list is for FPSC classic as has been mentioned, however, LUA for Reloaded will be being expanded to cover such things as loopsound, etc, once performance and all of its little gremlins are fixed (very soon).



SC
Dralel
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 4th Nov 2013
Location: UK
Posted: 27th May 2014 14:41 Edited at: 27th May 2014 15:01
Yes I would like the expanded list, would love to play around with looping sounds in FPSCR.



Edit: Realised the loop function is in musicinzone.lua, nevermind lol.

GPU: GTX 660, CPU: i7 3770 Intel 3.40ghz x4, PSU: 650 Watt, RAM: 8GB DDR3, OS: Win7 Ultimate 64-bit
PM

Login to post a reply

Server time is: 2024-12-22 01:24:02
Your offset time is: 2024-12-22 01:24:02