Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Play sound on text command


Blister
 Share

Recommended Posts

Hey guys!

First: I'm using EE 2.7  And I want to try out some easy scripting to learn it better. Learning by doing so to speak. I tried some messages that display if you step on some place. I have a question to this also but i'll come to this later.

The first more complex thing I want to do is make a simple, nonsenseless script, which allows me to play a sound by tiping a text command.

So I think the beginning of the script should be something like this

If LCase(Mid(TextSay, 1, 8)) = "/belch" Then  (<–- now get why it's nonsenseless? ;P)

But I'm not sure if this is right and also I don't know the right command to play a sound or how I shall write the script further.

This is why I aks you to explain to me how to proceed with the script.

So now to the thing with the script that starts if you step somewhere. Well in the map editor there are the 2 attributes "Scripted" (i think thats the one you step on) and "click" (I thought you have to press enter or space if you're at this? I used the rm2k in the past this is why this stuff confuses me a little bit)
When you setup those you have to choose a script number. So how do I mark any Script as.. don't know.. number 100? is this the line in the main.txt ?

speaking of the main.txt: where would I have to place those scripts in there?
I'm so damn clueless  :confused:
Link to comment
Share on other sites

Ok

1st: About the sound play command.

You'd want to do something like:

```
Case "/command"
PlaySound(Index, "sound_name.wav")
Exit Sub
```
So this is what it does:

Case "/command" => Specifies in which case u want the script to happen (in this case, when player types /command)

PlaySound => is the command to play the sound chosen (u must specify to whom u wish the sound to play to (this case index, which the the user of the command) and which .wav sound u wish to play (this case "sound_name.wav" (look in ur sfx folder for .wav sounds))

Exit Sub => ends the currend case.

This should go under Sub Commands on ur Main.txt

2nd: Map editor attributes:

Scripted: will search in ur main.txt for the script under Sub ScriptedTiles. For example: if u build a script under Sub ScriptedTiles with the Case 4 on, you'd have to choose the script 4 in the script attribute.

```
Case 4
PlaySound(Index, "sound_name.wav")
Exit Sub

```Its recommended to build scripts in numerical order cases, not to get the main.txt messed up (Case 1, Case 2, Case 3…)

Click: sorry but i havent used this attribute yet so i can only guess what it does =/

Hope i helped
Link to comment
Share on other sites

Thx very much allanws!  The much detail helped me a lot.
And also thx to you Balliztik cause I want the whole map to hear the sound.

EDIT: damn I can't get it to work. He just says invalid comman or something like this.

I added it to nearly the bottom of my main.txt like this

Sub Case "/belch"
    PlaySoundToMap (index, "burrrrrp.wav")
End Sub   

I read this sub at anything so I tried it with the sub (I tried it without bevor but didn't work.)
I'm really ashamed of asking but would you mind telling me how to add this? Sry I just don't get it yet.

I use version EE 2.7    and theres a command-ini…  does it have something to do with this?
Link to comment
Share on other sites

Do not put sub on case. it should be simply:

```
Case "/belch"
    PlaySoundToMap (index, "burrrrrp.wav")
End Sub
```
Case, as the conditional says, is a case that should happen on a sub. So the sub for this is Commands, and the case is /belch.

Add that code under Sub Commands on your main.txt 

EDIT: Don't be ashamed!  :cheesy: everyone starts slow then they start picking up. try reading some tuts on SadScripting, thats how i started. Good luck

command.ini is just for storing commands that were used in the server (i think, not sure). every script u build is basicly placed on the main.txt Then u just have to figure out which section u wish to place it in, depending on when u want the script to run (those are the subs)
Link to comment
Share on other sites

Ahhhh  now I understand ^^  Thx

EDIT:
I'm sorry to ask again but there's a problem.
I did everythign as you told me. Script seems to be in the right place and basically it seems to work
cause he doesn't say invalid command anymore.

But for some reason I can hear no sound oO  I thought it could be the wave data and tried the other sounds (even the standart ones) and none did work. I tried PlaySound and PlaySoundToMap but in both cases: total silence.

This is how my Sub Command part of the main.txt looks like: (I marked the Custom Script Part)

' Executed whenever a slash command is sent to the server.
Sub Commands(Index)
Dim TextSay
Dim PlayerID
Dim MapNum

' Get the command and arguments from the cache.
TextSay = Trim(GetVar("Scripts\Command.ini", "TEMP", "Text" & Index))

' Split the command into an array. All arguments are seperated by spaces.
TextSay = Split(TextSay)

Select Case TextSay(0)
Case "/testscripts"
Call TestMain(Index)
Exit Sub

Case "/help"
Call PlayerMsg(Index, "Social Commands:", WHITE)
Call PlayerMsg(Index, "'msghere = Broadcast Message", WHITE)
Call PlayerMsg(Index, "-msghere = Emote Message", WHITE)
Call PlayerMsg(Index, "!namehere msghere = Player Message", WHITE)
Call PlayerMsg(Index, "Available Commands: /help, /info, /who, /fps, /inv, /stats, /train, /party, /join, /leave, /refresh", WHITE)
Exit Sub

Case "/calladmins"
If GetPlayerAccess(Index) = 0 Then
Call AdminMsg(GetPlayerName(Index) & " needs your help!", BRIGHTGREEN)
Else
Call PlayerMsg(Index, "You are an admin! You cannot call for help!", BRIGHTGREEN)
End If
Exit Sub

Case "/admin"
If GetPlayerAccess(Index) > 0 Then
Call PlayerMsg(Index, "Social Commands:", WHITE)
Call PlayerMsg(Index, """msghere = Global Admin Message", WHITE)
Call PlayerMsg(Index, "=msghere = Private Admin Message", WHITE)
Call PlayerMsg(Index, "Available Commands: /admin, /loc, /mapeditor, /warpmeto, /warptome, /warpto, /setsprite, /mapreport, /kick, /ban, /edititem, /respawn, /editnpc, /motd, /editshop, /ban, /editspell", WHITE)
End If
Exit Sub

      **Case "/belch"
                PlaySoundToMap(index, "belch.wav")
            End Sub**

Case "/warpmeto"
If GetPlayerAccess(Index) > 0 Then
PlayerID = FindPlayer(TextSay(1))

If PlayerID > 0 Then
Call PlayerWarp(Index, GetPlayerMap(PlayerID), GetPlayerX(PlayerID), GetPlayerY(PlayerID))
Call PlayerMsg(Index, "You have been warped to " & GetPlayerName(PlayerID) & ".", BROWN)
Else
Call PlayerMsg(Index, "Player is not online.", WHITE)
End If
End If
Exit Sub

Case "/warptome"
If GetPlayerAccess(Index) > 0 Then
PlayerID = FindPlayer(TextSay(1))

If PlayerID > 0 Then
Call PlayerWarp(PlayerID, GetPlayerMap(Index), GetPlayerX(Index), GetPlayerY(Index))
Call PlayerMsg(PlayerID, "You have been warped to " & GetPlayerName(Index) & ".", BROWN)
Else
Call PlayerMsg(Index, "Player is not online.", WHITE)
End If
End If
Exit Sub

Case "/warpto"
If GetPlayerAccess(Index) > 0 Then
MapNum = TextSay(1)

If MapNum > 0 And MapNum <= MAX_MAPS Then
Call PlayerWarp(Index, MapNum, GetPlayerX(Index), GetPlayerY(Index))
Call PlayerMsg(Index, "You have been warped to map #" & MapNum & ".", BRIGHTBLUE)
Else
Call PlayerMsg(Index, "Invalid map number.", BRIGHTRED)
End If
End If
Exit Sub
End Select

Call PlayerMsg(Index, "That is not a valid command.", BRIGHTRED)
End Sub
Link to comment
Share on other sites

damn sorry i must have typed fast and didnt see that *shoots his own head*

```
Case "/belch"
                Call PlaySoundToMap(index, "belch.wav")
            Exit Sub
```
You need to Call the command and that would be an exit sub :P
Link to comment
Share on other sites

Ahhhh  I already wondered whats the difference between end sub and exit sub.
I hope it'll work this time  :cheesy: Thank you for your patience  ;)

EDIT:
hmm… thats weird..
There's still no sound but the funny thing is every other text commands do not work also oO theres no error message but nothing happens. but in my server panel scripts are turned on oO
Link to comment
Share on other sites

@Blister:

> Ahhhh  I already wondered whats the difference between end sub and exit sub.
> I hope it'll work this time  :cheesy: Thank you for your patience  ;)
>
> EDIT:
> hmm… thats weird..
> There's still no sound but the funny thing is every other text commands do not work also oO theres no error message but nothing happens. but in my server panel scripts are turned on oO

Your main.txt is bugged somewhere, then. Post it or PM it to me, and I can fix it up real quick.
Link to comment
Share on other sites

First off I'll try to simply explain the diffrence
Exit sub = I don't want anymore code in this sub to run
End Sub = There is no more code that goes in this sub

```
        Case "/belch"
                PlaySoundToMap(index, "belch.wav")
            End Sub
```
Needs to be
```
        Case "/belch"
                Call PlaySoundToMap(index, "belch.wav")
            Exit Sub
```
Also Balliztik, he said all his other commands work, which means no matter how bugged his main is this command should work.
Link to comment
Share on other sites

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
 Share

×
×
  • Create New...