Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need help with my lightsaber script

Zip Paz
Registered User
Join date: 18 Sep 2005
Posts: 16
10-06-2005 22:06
I'm new to scripting so I've been using a modified version of pillow fighter script for my combat/animations. I originally got this script from a guy who (I'm certain) tinkered with it alot and screwed it up as it had ALOT of errors when I first tried to use it. I fixed.. most of them and it works pretty well. Bounces avys and everything.. however it WILL not transmit damage when I'm in a damage sim...
And try as I might I have NO idea where to put the collision detection and llsetdamage to get it to work. It seems like it wont work no matter where I put it.....

I'm tired.. it's late.. So i'm just going to post the script and leave it in your hands.

// Ugly 2 fisted hack - Francis (Re-vamped by Zip Paz after someone screwed it up bad)

key owner;
integer SWORD = 1;
integer PUNCH12 = 2;
integer PUNCHL = 3;
integer KICK = 4;
integer FLIP = 5;

integer strike_type;

default
{
state_entry()
{
llSetDamage(50.0);
llSetStatus(STATUS_BLOCK_GRAB, TRUE);
}
run_time_permissions(integer perm)
{
if (perm)
{
llTakeControls(CONTROL_ML_LBUTTON | CONTROL_LBUTTON | CONTROL_UP | CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_LEFT | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ROT_RIGHT | CONTROL_DOWN, TRUE, TRUE);
}
}

attach(key on)
{
if (on != NULL_KEY)
{
integer perm = llGetPermissions();

if (perm != (PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION))
{
llRequestPermissions(on, PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
}
else
{
llTakeControls(CONTROL_ML_LBUTTON | CONTROL_LBUTTON | CONTROL_UP | CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_LEFT | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ROT_RIGHT, TRUE, TRUE);
}

}
else
{
llSay(0, "releasing controls";);
llTakeControls(TRUE, TRUE, TRUE);
}
}

timer()
{
if ( (strike_type == FLIP)
|| (strike_type == SWORD))
{
llSensor("", "", ACTIVE | AGENT, 4.0, PI_BY_TWO*0.5);
}
else
{
llSensor("", "", ACTIVE | AGENT, 3.0, PI_BY_TWO*0.5);
}
llSetTimerEvent(0.0);
}

control(key owner, integer level, integer edge)
{
if (level & (CONTROL_ML_LBUTTON | CONTROL_LBUTTON))
{
if (edge & CONTROL_UP)
{
llApplyImpulse(<0,0,3.5>,FALSE);
llStartAnimation("backflip";);
llSetTimerEvent(0.25);
strike_type = FLIP;
}
if (edge & CONTROL_FWD)
{
llStartAnimation("sword_strike_R";);
llSleep(0.5);
llSetTimerEvent(0.25);
strike_type = SWORD;
}
if (edge & (CONTROL_LEFT | CONTROL_ROT_LEFT))
{
llStartAnimation("sword_strike_R";);
llSleep(0.5);
llSetTimerEvent(0.25);
strike_type = SWORD;
}
if (edge & (CONTROL_RIGHT | CONTROL_ROT_RIGHT))
{
llStartAnimation("sword_strike_R";);
llSleep(0.5);
llSetTimerEvent(0.25);
strike_type = SWORD;
}
if (edge & CONTROL_BACK)
{
llStartAnimation("sword_strike_R";);
llSleep(0.5);
llSetTimerEvent(0.25);
strike_type = SWORD;
}
if (edge & CONTROL_DOWN)
{
llStartAnimation("sword_strike_R";);
llSleep(0.5);
llSetTimerEvent(0.25);
strike_type = SWORD;
}

}
}
collision_start(integer num)
{
llSetDamage(50.0);
}
sensor(integer tnum)
{
vector dir = llDetectedPos(0) - llGetPos();
dir.z = 0.0;
dir = llVecNorm(dir);
rotation rot = llGetRot();
if (strike_type == SWORD)
{
llTriggerSound("crunch", 0.5);
dir += llRot2Up(rot);
dir *= 1000000.0;
llPushObject(llDetectedKey(0), dir, ZERO_VECTOR, FALSE);
}
else if (strike_type == PUNCH12)
{
llTriggerSound("crunch", 0.2);
dir += dir;
dir *= 1000000.0;
llPushObject(llDetectedKey(0), dir, ZERO_VECTOR, FALSE);
}
else if (strike_type == PUNCHL)
{
llTriggerSound("crunch", 0.2);
dir -= llRot2Left(rot);
dir *= 1000000.0;
llPushObject(llDetectedKey(0), dir, ZERO_VECTOR, FALSE);
}
else if (strike_type == KICK)
{
llTriggerSound("crunch", 0.2);
dir += dir;
dir *= 1000000.0;
llPushObject(llDetectedKey(0), dir, ZERO_VECTOR, FALSE);
}
else if (strike_type == FLIP)
{
llTriggerSound("crunch", 0.2);
llPushObject(llDetectedKey(0), <0,0,150>, ZERO_VECTOR, FALSE);
}
strike_type= 0;
}

}
Zip Paz
Registered User
Join date: 18 Sep 2005
Posts: 16
upon rethinking it
10-06-2005 22:27
After advice from a friend Im guessing I need to rezz an invisible object onto the area where it strikes the other avy and have that transmit the damage. I'll probably need a collision start statement...

god Im exhausted LOL. If anyone has a suggestion for this particular project including a way to set it to KILL mode and non kill mode (Im guessing a gigantic if statement) I'd sure appreciate it.

As I said before I'm still learning to script... very new.

Thanks.
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
10-07-2005 03:11
Zip - firstly, welcome to LSL :)
Secondly, please use the PHP tags when posting LSL code - it makes it muuuuuch easier for us to read and help. (Kehknev: you sleeping? I beat you! :D )

Some suggestions:
  1. Replace llSay(0, "releasing controls";) with llOwnerSay
  2. Clean up your IFs. Extract common code and common tests. In the control event, for example, other than the CONTROL_UP, all the other cases do the same thing. You could OR them together into one IF condition, or considering that they handle all cases other than CONTROL_UP - just use an ELSE.
  3. You are only using SWORD and FLIP, so get rid of the other strike types.
  4. As far as kill/no_kill is concerned: do you mean, still doing all the anims, but not just causing damage? Just remember to avoid "a gigantic if statement" if you can.
  5. That's it for now - I'll leave the damage help up to people that have actually used it :)

CODE
// Ugly 2 fisted hack - Francis (Re-vamped by Zip Paz after someone screwed it up bad)

key owner;
integer SWORD = 1;
integer FLIP = 2;

integer strike_type;

default
{
state_entry()
{
llSetStatus(STATUS_BLOCK_GRAB, TRUE);
}

run_time_permissions(integer perm)
{
if (perm)
{
llTakeControls(CONTROL_ML_LBUTTON | CONTROL_LBUTTON | CONTROL_UP | CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_LEFT | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ROT_RIGHT | CONTROL_DOWN, TRUE, TRUE);
}
}

attach(key on)
{
if (on != NULL_KEY)
{
integer perm = llGetPermissions();
if (perm != (PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION))
llRequestPermissions(on, PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
else
llTakeControls(CONTROL_ML_LBUTTON | CONTROL_LBUTTON | CONTROL_UP | CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_LEFT | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ROT_RIGHT, TRUE, TRUE);
}
else
{
llSay(0, "releasing controls");
llTakeControls(TRUE, TRUE, TRUE);
}
}

timer()
{
llSensor("", "", ACTIVE | AGENT, 4.0, PI_BY_TWO*0.5);
llSetTimerEvent(0.0);
}

control(key owner, integer level, integer edge)
{
if (level & (CONTROL_ML_LBUTTON | CONTROL_LBUTTON))
{

if (edge & CONTROL_UP)
{
llApplyImpulse(<0,0,3.5>,FALSE);
llStartAnimation("backflip");
llSetTimerEvent(0.25);
strike_type = FLIP;
}
else
{
llStartAnimation("sword_strike_R");
llSleep(0.5);
llSetTimerEvent(0.25);
strike_type = SWORD;
}
}
}

sensor(integer tnum)
{
if (strike_type)
{
llTriggerSound("crunch", 0.5);
vector dir;
if (strike_type == SWORD)
{
dir = llDetectedPos(0) - llGetPos();
dir.z = 0.0;
dir = llVecNorm(dir);
dir += llRot2Up(llGetRot())
dir *= 1000000.0;
}
else
dir = <0,0,150>;
llPushObject(llDetectedKey(0), dir, ZERO_VECTOR, FALSE);
strike_type= 0;
}
}

}
Zip Paz
Registered User
Join date: 18 Sep 2005
Posts: 16
error
10-07-2005 07:21
Ok, on that script you posted I get an error on dir *= 1000000.0;

ACK NEVERMIND.. Found it.. missing a ;
No biggie.
..
Incidentally.. I think what I need to do for damage (because any item thats attached to your avatar that collides with another avatar is technically still phantom) is have it res an invisible object that where it collides (using collision_start) and then have that object with llset_damage and lldie (so it goes away right after it hits.

Shouldn't be too hard... Then I can have it set up with an if statement so that depending on what my particular variable has it'll swap out the bullet for one that does less or more damage.

Sound right so far?

Btw thanks so much for your help!
Zip Paz
Registered User
Join date: 18 Sep 2005
Posts: 16
Also
10-07-2005 07:35
How do I get it to NOT bring up the window that says "This object would like to animate your avatar" when I attach it to myself.
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
10-07-2005 08:15
The last parameter of llRezObject is there for you to pass any number you want to a rezzed object. The rezzed object sees it as start_param in its on_rez event.

What I'm thinking is you could have an integer "damage" variable. in your collision event you would say something like:
CODE
if (Damage)
llRezObject("blah", somepos, somevel, somerot, Damage);
so if Damage is set to 0, no damage object will be created at all, otherwise the damage object gets it by doing something like:
CODE
on_rez(integer start_param)
{
llSetDamage(start_param);
...
...
}

I don't have an answer on the dialog box, I'm afraid :(