VirtusVerbis
Member
Hi All,
Thank you for your help (in advance).
I'm trying to get the following to work:
Tutorial - Custom Sounds For Collecting Items
Here is the code I am using in my item.c :
I then add the didhitscript to my <char>.txt (entity level) header :
When I test it, there are no OpenBOR log errors, but I also don't get any sound for the item pick up (just defaults to regular item pick up sound).
Alternatively, I tried doing an inline script as follows in my <char>.txt under the 'get' animation:
Question #1: I must be doing something wrong for the didhitscript inclusion, as I don't get any sound effect whatsoever (which tells me the code isn't running).
Question #2: I can get the Inline Script to work only if the "If-Statement" is commented out (meaning I can't check for a specific item). Is there a way I can output the 'Name' variable to the OpenBOR log so that I can see what is being returned? In this case "Gold" is the actual name of the item that I am targeting the sfx for, here's the Gold.txt :
Thank you for your help (in advance).
I'm trying to get the following to work:
Tutorial - Custom Sounds For Collecting Items
Here is the code I am using in my item.c :
Code:
void main()
{
void self = getlocalvar("self"); //get the self var
void hit = getlocalvar("damagetaker"); // get target entity
char Name = getentityproperty(self,"name"); // get target's name //not sure why 'self' is used here tho, but that's what the posted article had
if( Name == "Gold")
{
//play sound effect
int SFX1 = loadsample("data/sounds/mysound.wav"); // load samples
playsample(SFX1, 0, 120, 120, 100, 0);
}
}
I then add the didhitscript to my <char>.txt (entity level) header :
didhitscript data/scripts/Item.c
When I test it, there are no OpenBOR log errors, but I also don't get any sound for the item pick up (just defaults to regular item pick up sound).
Alternatively, I tried doing an inline script as follows in my <char>.txt under the 'get' animation:
anim get
loop 0
delay 10
offset 19 70
frame data/chars/hero/pickup00.png
@script
if(frame==1)
{
void self = getlocalvar("self"); //get the self var
void hit = getlocalvar("damagetaker"); // get target entity
char Name = getentityproperty(hit,"name"); // get target's name // I changed 'self' to 'hit' which works, but only if I comment out the IF-Statement that follows
// if( Name == "Gold") // if statement is commented out just for testing, and it does play the sound this way (since no validation is being done)
// {
//play sound effect
int SFX1 = loadsample("data/sounds/mysound.wav"); // load samples
playsample(SFX1, 0, 120, 120, 100, 0);
// }
}
@end_script
delay 35
offset 38 47
frame data/chars/hero/pickup01.png
Question #1: I must be doing something wrong for the didhitscript inclusion, as I don't get any sound effect whatsoever (which tells me the code isn't running).
Question #2: I can get the Inline Script to work only if the "If-Statement" is commented out (meaning I can't check for a specific item). Is there a way I can output the 'Name' variable to the OpenBOR log so that I can see what is being returned? In this case "Gold" is the actual name of the item that I am targeting the sfx for, here's the Gold.txt :
name Gold
health 0
score 5000
type item
shadow 0
icon data/chars/misc/goldicon.gif
anim idle
loop 1
offset 9 13
bbox 0 0 17 13
delay 200
frame data/chars/misc/gold00.gif
delay 15
frame data/chars/misc/gold01.gif
frame data/chars/misc/gold02.gif
frame data/chars/misc/gold03.gif
frame data/chars/misc/gold02.gif
frame data/chars/misc/gold01.gif