Variable Help
|
Yonke Ming
Fat Laughing Hyena
Join date: 18 Jun 2005
Posts: 16
|
06-29-2005 12:38
Well for some reason, I am having trouble with some of my script. The Monster and Sword seems to work, but.... The HP will not decrease. ---------THE MONSTER------ integer COLLISION_CHANNEL = 19484; integer HP = 30; default { on_rez(integer totalNum) { llResetScript(); } state_entry() { llListen(COLLISION_CHANNEL, "", NULL_KEY, (string) llGetKey()); } listen(integer channel, string name, key id, string message) { llSetText("HP:" + (string)HP, <1,1,1>, 1.0); if (HP <= 0) { llSay(0, "Yonke Ming has defeated the Test Object Box."  ; } else { llSay(0, "Ouch!"  ; HP - 10; } } } The variable, "HP", will not even decrease. This is the "Monster". Now I have one for my sword, which is a nuisance. When I have the collision with the box and the sword, spams the word "Ouch!" until I take it out. But I only want it to happen once for each time I stick the sword in the box. ----THE SWORD---- integer COLLISION_CHANNEL = 19484; default { state_entry() { llVolumeDetect(TRUE); // So the attachment can detect collision with the box. } collision_start(integer totalNumber) { integer i; for (i = 0; i < totalNumber; ++i) { llShout(COLLISION_CHANNEL, (string)llDetectedKey(i)); } } } Please help me if you can. 
_____________________
I like Hyenas...
...Especially the soft, fat, squishy, and silly ones!
|
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
|
06-29-2005 12:44
That code is pretty hard to read. Could you please put it in the tags? Thanks.
|
Yonke Ming
Fat Laughing Hyena
Join date: 18 Jun 2005
Posts: 16
|
06-29-2005 12:47
Well for some reason, I am having trouble with some of my script. The Monster and Sword seems to work, but.... The HP will not decrease. ---------THE MONSTER------ integer COLLISION_CHANNEL = 19484; integer HP = 30;
default {
on_rez(integer totalNum) { llResetScript(); } state_entry() { llListen(COLLISION_CHANNEL, "", NULL_KEY, (string) llGetKey());
} listen(integer channel, string name, key id, string message) {
llSetText("HP:" + (string)HP, <1,1,1>, 1.0); if (HP <= 0) { llSay(0, "Yonke Ming has defeated the Test Object Box."); } else { llSay(0, "Ouch!"); HP - 10; }
}
}
The variable, "HP", will not even decrease. This is the "Monster". Now I have one for my sword, which is a nuisance. When I have the collision with the box and the sword, spams the word "Ouch!" until I take it out. But I only want it to happen once for each time I stick the sword in the box. ----THE SWORD---- integer COLLISION_CHANNEL = 19484; default { state_entry() { llVolumeDetect(TRUE); // So the attachment can detect collision with the box. } collision_start(integer totalNumber) { integer i; for (i = 0; i < totalNumber; ++i) { llShout(COLLISION_CHANNEL, (string)llDetectedKey(i)); } } } There. I didn't know how ta do that, hehe. Forgive me. ^^;
_____________________
I like Hyenas...
...Especially the soft, fat, squishy, and silly ones!
|
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
|
06-29-2005 12:50
Well, now it's unindented.
Do you know about the edit button? You should have just edited your original post--you would have kept the indentation.
|
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
|
06-29-2005 12:52
But, I could read it now. You have a problem on one of your lines: HP - 10;
This calculates the value of it, but doesn't do anything with that value. What you want is: HP = HP - 10; //or HP -= 10;
|
Yonke Ming
Fat Laughing Hyena
Join date: 18 Jun 2005
Posts: 16
|
06-29-2005 13:20
Thank you, that part works! Now I have to find out what's up with this sword. Feel free to test out the Swprd and the box for yourself, it spams it's messages when I wanted for it to happen once for each time the sword is stabbed into the box. integer COLLISION_CHANNEL = 19484; default { state_entry() { llVolumeDetect(TRUE); // So the attachment can detect collision with the box. } collision_start(integer totalNumber) { integer i; for (i = 0; i < totalNumber; ++i) { llShout(COLLISION_CHANNEL, (string)llDetectedKey(i)); } } }
_____________________
I like Hyenas...
...Especially the soft, fat, squishy, and silly ones!
|
Velox Severine
Network Slave
Join date: 19 May 2005
Posts: 73
|
06-29-2005 13:58
I haven't done much with collisions yet, but do you really need the for loop? It seems if you wanted it ONLY to shout on the collision channel once you would remove it, since every time a collision happens collision_start is called correct?
|
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
|
06-29-2005 15:01
Theoretically. However, sometimes the sim lags, and the collision event does get more than one detected object.
|
Logan Bauer
Inept Adept
Join date: 13 Jun 2004
Posts: 2,237
|
Maybe...
07-06-2005 11:22
Hmm, are you attaching the sword to your hand and then running an animation to "swing" the sword at the box? Doesn't look like you are, but just FYI in my experience that doesn't work. I was trying to make "boxing gloves" for a combat game, put a few custom animations in, and basically if you run your "swing" animation, even while it will make your character lunge forward and the sword/glove/whatever WILL hit, and go right through your target, it does NOT register as a collision. Just incase that's where you were going or planning to go with this.
Also, yes, collisions are, well, IMHO almost useless for things like this. I'm at work and can't log in now,but I'm guessing you have a sword that kills your test object in 1 hit because as soon as it starts colliding, it keeps colliding, right? You can try collision_end instead of collision_start to see if that helps, but you may be better off using volume_detect and another prim... Good luck!
|
Garth FairChang
~ Mr FairChang ~
Join date: 24 Jun 2003
Posts: 275
|
07-06-2005 11:55
This might help. Not tested it: -- Monster -- integer COLLISION_CHANNEL = 19484; integer HP = 30;
default { on_rez(integer totalNum) { llResetScript(); } state_entry() { llListen(COLLISION_CHANNEL, "", NULL_KEY, ""); } listen(integer channel, string name, key id, string message) { // Hears and converts key to name of who hit monster string hitter = llDetectedName((key)message); if (HP <= 0) { llSay(0, hitter + " has defeated the Test Object Box."); } else { HP -= 10; llSay(0, "Ouch! " + hitter + " hit me"); llSetText("HP:" + (string)HP, <1,1,1>, 1.0); } } } --Sword -- integer COLLISION_CHANNEL = 19484;
default { state_entry() { llVolumeDetect(TRUE); // So the attachment can detect collision with the box. } collision_start(integer totalNumber) { // Shouts the key of the player holding sword - presumes they are owner of sword llShout(COLLISION_CHANNEL, (string)llGetOwner()); } }
_____________________
Garth FairChang ~Cheeky Brit~ ' Have a nice day  ' http://www.fairchang.com
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
07-06-2005 14:12
From: Yonke Ming Thank you, that part works!
Now I have to find out what's up with this sword. Feel free to test out the Swprd and the box for yourself, it spams it's messages when I wanted for it to happen once for each time the sword is stabbed into the box. When the collision event shouts a key, it shouts the key of what is collides with. The monster should, in its listen event, check if the text said by the sword is equal to its key, like so: listen(integer channel, string name, key id, string message) { if ((key)message == llGetKey()) { if (HP <= 0) { llSay(0, "Yonke Ming has defeated the Test Object Box."); llSetText("Dead", <1, 1, 1>, 1.0); } else { llSay(0, "Ouch!"); HP -= 10; llSetText("HP:" + (string)HP, <1,1,1>, 1.0); } } }
|