Jump to content

Problem with scripting (please help!)


Recommended Posts

I have a simple script that displays local text in the chatbox when a player walks into it, and it works fine.

Now I want to make it so it plays a .wav file when a player walks into it. I don't see the problem in my script, but obviously there is one. Here it is:

function markerHit( hitPlayer, matchingDimension )
if (source == marker1) then
outputChatBox ( "" .. text1a .. "", hitPlayer, 0, 255, 0 )
outputChatBox ( "" .. text1b .. "", hitPlayer, 0, 255, 0 )
outputChatBox ( "" .. text1c .. "", hitPlayer, 255, 0, 0 )
elseif (source == marker2) then
outputChatBox ( "" .. text2a .. "", hitPlayer, 0, 255, 0 )
outputChatBox ( "" .. text2b .. "", hitPlayer, 0, 255, 0 )
[color=#FF0000]elseif (source == marker3) then [/color]
[color=#FF0000]outputChatBox ( "" .. text3a .. "", hitPlayer, 0, 255, 0 )[/color]
[color=#FF0000]local sound = playSound("distress.wav",false)[/color]
   end
end
addEventHandler ( "onMarkerHit", getRootElement(), markerHit )

Upon hitting marker 3, text3a is displayed, but distress.wav is not played. I checked the server console, and the following error was returned:

[2010-07-11 20:18:59] ERROR: TextMarkers/script.lua:22: attempt to call global 'playSound' (a nil value)

Any help would be greatly appreciated!

Link to comment
sorry, I'm pretty new to scripting, can you dumb that down a bit? :(

EDIT: The script.lua is set to 'server' in the meta.xml, if I changed that to client, would that help?

-->

<script src="script.lua" type="server"/>

do this,

server side:

function markerHit( hitPlayer, matchingDimension )
if (source == marker1) then
outputChatBox ( "" .. text1a .. "", hitPlayer, 0, 255, 0 )
outputChatBox ( "" .. text1b .. "", hitPlayer, 0, 255, 0 )
outputChatBox ( "" .. text1c .. "", hitPlayer, 255, 0, 0 )
elseif (source == marker2) then
outputChatBox ( "" .. text2a .. "", hitPlayer, 0, 255, 0 )
outputChatBox ( "" .. text2b .. "", hitPlayer, 0, 255, 0 )
elseif (source == marker3) then
outputChatBox ( "" .. text3a .. "", hitPlayer, 0, 255, 0 )
triggerClientEvent(hitPlayer,"playTheSound",getRootElement())
end
end
addEventHandler ( "onMarkerHit", getRootElement(), markerHit )

client side:

function playIT()
local sound = playSound("distress.wav",false)
end
addEvent( "playTheSound", true )
addEventHandler( "playTheSound", getRootElement(),playIT )

meta.xml

<meta>
<info name="" author="Blackvein" type="script" version="1.0"/>
<script src="scriptclient.lua" type="client" />
<script src="script.lua" type="server" />
       <file src="distress.wav" />
</meta>

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...