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

Can't find a certin code, can anyone help? :)


ZeoWorks
 Share

Recommended Posts

Hello everyone;
Basicly, i'm trying to edit the source code so that whenever the player presses the control key it plays the sound of the weapon he/she has equiped.  I tried a few things in the 'check attack sub' like:

```
        If GetPlayerEquipment(MyIndex, Weapon) > 0 Then
        soundName = Trim$(Item(entityNum).Sound)
        PlaySound soundName
        End If
```
But it just doesent work, can someone please give me the right code for this? thank you!
(If possible, it would be better that instead of playing the items (weapon) set sound; it would play the items (weapon) set animation sound instead).

Thanks for reading!
~ZeoWorks
Link to comment
Share on other sites

On the client side; ModGameLogic
Under the Sub CheckAttack,
After:
```
    If ControlDown Then
        If SpellBuffer > 0 Then Exit Sub ' currently casting a spell, can't attack
        If StunDuration > 0 Then Exit Sub ' stunned, can't attack

        ' speed from weapon
        If GetPlayerEquipment(MyIndex, Weapon) > 0 Then
            attackspeed = Item(GetPlayerEquipment(MyIndex, Weapon)).Speed
        Else
            attackspeed = 1000
        End If
```
The reason I need this is for gun shooting sounds to be played when the player presses the Ctrl key. :)
Link to comment
Share on other sites

As I stated before; the reason why I want the sound of the item played when the player presses the control key so that I can make gun shooting sound effects.  I'm using Wabbits projectile system however when you fire a projectile there is no firing sound, there is only a sound from the animation played when the projectile hits the npc/player.

Thats why i'm gonna use the items sound for firing sounds. (I would use the animation sound instead however there would be a situation that the animation sound would be played again when the projectile hits the npc/player ya'know?).
Link to comment
Share on other sites

@zerosavior115:

> well you have a good idea but i think you should observe how the animation sound take place and redo it in the check attack sub but ill manage to try this

Thank you zerosavior ^_^!
I've been looking through the source and I can't quite put my finger on it on how to do it, have you found anything? :)
(Thanks again for your help, i'll add a special thanks into my-games credits if you find it.*or anyone else of that matter..*)
Link to comment
Share on other sites

```
If GetPlayerEquipment(MyIndex, Weapon) > 0 Then
        soundName = Trim$(Item(entityNum).Sound)
        PlaySound soundName
        End If
```Why are you using```
Trim$
```
The variable is not a string, so there is no reason to treat it like one. Instead you could leave it as is
```
Item(entityNum).Sound
```

We would want to use Trim$ if we wanted to remove blank spaces from the back and front of a string, for example.

```
LolName = trim$(frmLol.lbl1.caption)

Buffer.Writestring LolName
```

Of course, lets say you stored a number in a Textbox, or a Label. You would want to get the value of the string by using

```
Val(frmLol.lbl1.caption)
```
Link to comment
Share on other sites

@General:

> ```
> If GetPlayerEquipment(MyIndex, Weapon) > 0 Then
>         soundName = Trim$(Item(entityNum).Sound)
>         PlaySound soundName
>         End If
> ```Why are you using```
> Trim$
> ```
> The variable is not a string, so there is no reason to treat it like one. Instead you could leave it as is
> ```
> Item(entityNum).Sound
> ```
>
> We would want to use Trim$ if we wanted to remove blank spaces from the back and front of a string, for example.
>
> ```
> LolName = trim$(frmLol.lbl1.caption)
>
> Buffer.Writestring LolName
> ```
>
> Of course, lets say you stored a number in a Textbox, or a Label. You would want to get the value of the string by using
>
> ```
> Val(frmLol.lbl1.caption)
> ```

> The variable is not a string, so there is no reason to treat it like one. Instead you could leave it as is
> ```
> Item(entityNum).Sound
> ```

Yes it is. Trim$ is used for constant length strings.

```
Private Type ItemRec
    Name As String * NAME_LENGTH
    Desc As String * 255
    Sound As String * NAME_LENGTH

    Pic As Long
    Type As Byte
    Data1 As Long
    Data2 As Long
    Data3 As Long
    ClassReq As Long
    AccessReq As Long
    LevelReq As Long
    Mastery As Byte
    Price As Long
    Add_Stat(1 To Stats.Stat_Count - 1) As Byte
    Rarity As Byte
    Speed As Long
    Handed As Long
    BindType As Byte
    Stat_Req(1 To Stats.Stat_Count - 1) As Byte
    Animation As Long
    Paperdoll As Long

    AddHP As Long
    AddMP As Long
    AddEXP As Long
    CastSpell As Long
    instaCast As Byte
End Type

```
```
Sound As String * NAME_LENGTH

```
```
Sound As String * NAME_LENGTH

```
```
String * NAME_LENGTH

```

* * *

Anyway, now back to the question.

If we look at PlayMapSound, we see the following function header:
```
Public Sub PlayMapSound(ByVal x As Long, ByVal y As Long, ByVal entityType As Long, ByVal entityNum As Long)

```
Now we can use the Player's x and y for the first two parameters. But then we see something we haven't see before "entityType". If we scroll down, we see a Select Case switch. So to do an item, entityType should be SoundEntity.seItem. Lastly, we need the item's number. In this case the weapon. So we piece it together…

```
PlayMapSound GetPlayerX(MyIndex), GetPlayerY(MyIndex), SoundEntity.seItem, GetPlayerEquipment(MyIndex, Weapon)

```
Almost done. Now hop over to Sub CheckAttack (as you have previously noted), and under:
```
If Player(MyIndex).Attacking = 0 Then

```
add:
```
    If GetPlayerEquipment(MyIndex, Weapon) > 0 Then
        PlayMapSound GetPlayerX(MyIndex), GetPlayerY(MyIndex), SoundEntity.seItem, GetPlayerEquipment(MyIndex, Weapon)
    End If

```
And so we are finished. Compile and enjoy.

* * *

The observant reader will note that the check was already done in the sub when the attack speed was calculated. However, this will play the sound even if the player simply holds the control button, therefore a different check is needed.

There's also a problem with this tutorial, it doesn't broadcast the attack sound to all the players. Personally I would find it annoying if it did, but if you want, you should look into Sub HandleAttack server-side.
Link to comment
Share on other sites

@General:

> Why in the hell would you store sound files as strings in the first place?
>
> I like storing everything in numbers, hell. In my project my player files are in numerical order rather then saved as the default strings.

It stores the sound file's name in the ItemRec, which is far more efficient than loading the sound file as a binary blob (storing blobs in a database is a bad idea, as it discourages caching and other optimization techniques). It does not store the sound file in the Item because that would be crazy.

Also, VB6 strings are just an array of bytes.
Link to comment
Share on other sites

@General:

> You're not understanding what I'm saying, rather then storing the sound files as names. Such as "Slash.wav" why not store them as numbers "1.wav". To me, that would be far easier to use.

1.wav is still a string, but you can convert that string to long, like sprite
Link to comment
Share on other sites

@General:

> You're not understanding what I'm saying, rather then storing the sound files as names. Such as "Slash.wav" why not store them as numbers "1.wav". To me, that would be far easier to use.

It's not like sprites where you can see a picture of the sprite as you select it. It would be much easier to pick a name that says "Slash.wav" than to listen through all the sounds for "12.wav". Sounds NEED a name in order to be maintainable. That is why they are handled differently from all the other systems.
Link to comment
Share on other sites

@Soul:

> It's not like sprites where you can see a picture of the sprite as you select it. It would be much easier to pick a name that says "Slash.wav" than to listen through all the sounds for "12.wav". Sounds NEED a name in order to be maintainable. That is why they are handled differently from all the other systems.

I need no names because I'm a boss lololol
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...