Jump to content
Sign in to follow this  
DaSquade

Reversing warning sound

Recommended Posts

I rencently tried to make a small script that activates a warning sound when my truck is reversing. I don't have much scripting exp., but thought this would work:

(script is beeing launched trough the class EventHandlers...[_this select 0] exec "\SB_Tractor45\reverse.sqs",)

script:

_Truck = _this select 0

_player = player

#check

~0.001

?(driver _Truck==player): goto "reversecheck"

goto "check"

;?(_player in _Truck):goto "reversecheck"

#reversecheck

~0.001

? (speed _Truck) < 0 : goto "reverse"

? (speed _Truck) >= 0 : goto "check"

#reverse

_Truck say "SBreverse"

~2

goto "reversecheck"

#exit

exit

Tested sound class seperate and works fine. Sample is 2 secs. Anybody an idea of what i'm doing wrong?

Share this post


Link to post
Share on other sites

I optimised your script a bit, tested and works fine:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Truck = _this select 0

; Wait until the player is driver of _Truck and engine is on

#wait

~1

? ((driver _Truck)!=player) && !(isengineon _Truck) : goto "wait"

; Check if _Truck reverses

#check

~0.1

; < (-1) because sometimes when the truck stands,

; the indicated speed is e.g. -0.12392 ...

? (speed _Truck) < (-1) : goto "reverse"

? ((driver _Truck)==player) && (isengineon _Truck) : goto "check"

goto "wait"

; If the sound should only be heard inside the truck, use "player say ..."

#reverse

player say "SBreverse"

~2

goto "check"

This script actually waits until the player is the driver of the truck, the sound will mainly be heard inside (like cockpit warnings)

If it should be heard also outside and with any driver, than the script had to be different.

EDIT: Another thing: In eventhandlers you can call the script simply with "_this exec {yourscript.sqs}", since the first element of all eventhandlers is always the truck itself

Share this post


Link to post
Share on other sites

Thanks for the help hardrock, but no luck so far.

I suppose it's something i overlooked, but I tried changing:

player say "SBreverse" into _player say "SBreverse"

(though it needed the _ to work?) But then again no luck.

Well, will look at it again.

Share this post


Link to post
Share on other sites

you can't rename "player say..." to "_player say...", since I deleted the variable _player in the script, since it's not necessary.

The script works 100%, I tested it myself.

So there are two possible errors:

1. Your sound doesn't work correctly.

Try putting a trigger in a mission, Activation:Alpha, onActivation:player say "SBreverse"

Then preview the mission and press 0-0-1 to activate the trigger. Do you hear the sound?

2. You don't call the script correctly.

Your eventhandler had to be like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">init = "_this exec {\SB_Tractor45\reverse.sqs}";

Good luck wink_o.gif

Share this post


Link to post
Share on other sites

another way you could optimize the scripts is to only use the

"engine" or "getin" event handlers....

that way it will not be running continously even when no one is in the vehicle.... could help some if there are a ton of your addons in the game...just frees up some cpu

Share this post


Link to post
Share on other sites

Just got it working!  unclesam.gif  Thanks for the help and tips.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×