Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Looking to script low-damage arrows and swords.

Gydeon Fox
Registered User
Join date: 4 Mar 2005
Posts: 148
05-15-2005 12:33
Is there an official sword script available which works well with the current update? There are threads in this forum about swords not working after the newer updates.

I've got the freebie Celtic sword, a pillow fighter script, and the freebie archery bow and arrow. I'd like to modify these to do a little damage so I can use them in an arena.

I'd like for the weapons to do a low level of damage so that people can still stick around and have some fun after being hit a few times, and I'd like for the arrows to be temp on rez with a time limit which I can change. Say, five minutes or so. Long enough to check the archery target, but short enough for the land not to be bogged down by people who forget to pickup. I might even make some throwing knives.

I'd also like to be able to adjust the push on things. Just enough to make the target take a step back if he's hit with a sword/arrow, etc.

I'm just now starting to look at scripting, so links to url's/other threads are welcome. Thanks!


Gydeon.
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
05-15-2005 13:05
Actually, the archery bow comes with a damage script. Have a look! :)
_____________________
---
Gydeon Fox
Registered User
Join date: 4 Mar 2005
Posts: 148
Really?
05-15-2005 16:22
It must have been right in front of me. I never find stuff if it's right in front of me. Now, if they'd hidden it under a rock somewhere... Thanks Jeffery, I'll check it out. :-)


Gydeon.
Gydeon Fox
Registered User
Join date: 4 Mar 2005
Posts: 148
Hmm...
05-16-2005 01:51
I'm looking at the 2003 Summer Camp Bow, which you can get at the telehubs. I know it's late, but I've checked the bow, the Arrow, and the arrow object in the bow... don't see the word "damage" anywhere. Shouldn't there be a "set damage" command of some type?

Gydeon.


Example: Script for the bow itself:
========================================================

vector fwd;
vector pos;
rotation rot;

key holder; // Key of avatar holding gun
integer on = TRUE;

integer attached = FALSE;
integer permissions = FALSE;
integer armed = TRUE;
key owner;

fire()
{
if(armed)
{
//
// Actually fires the ball
//
armed = FALSE;
integer shot = llRound(llFrand(1.0));
rot = llGetRot();
fwd = llRot2Fwd(rot);
pos = llGetPos();
pos = pos + fwd;
pos.z += 0.75; // Correct to eye point
fwd = fwd * 30.0;
llSay(57, (string)owner + "shoot";);
llStartAnimation("shoot_L_bow";);
llTriggerSound(llGetInventoryName(INVENTORY_SOUND, shot), 0.8);
llRezObject("arrow", pos, fwd, rot, 0);
llSetTimerEvent(2.0);
}


}

default
{

run_time_permissions(integer permissions)
{
if (permissions > 0)
{
llWhisper(0, "Enter Mouselook to shoot me, Say 'pickup' to pickup arrows, say 'id' to identify yours.";);
llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
llStartAnimation("hold_L_bow";);
attached = TRUE;
permissions = TRUE;
owner = llGetOwner();
}
}

attach(key attachedAgent)
{
//
// If attached/detached from agent, change behavior
//
if (attachedAgent != NULL_KEY)
{
string name = llKey2Name(llGetOwner());

on = TRUE;
attached = TRUE;
if (!permissions)
{
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS | PERMISSION_ATTACH);
}

}
else
{

attached = FALSE;
llStopAnimation("hold_L_bow";);
llReleaseControls();


}
}

control(key name, integer levels, integer edges)
{
if ( ((edges & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON)
&&;((levels & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON) )
{
fire();
}
}

timer()
{
llSetTimerEvent(0.0);
armed = TRUE;
}



}

========================================================
========================================================



Script for the arrow for your hand:
========================================================

list textlist;
integer i;
integer cb;

default
{
state_entry()
{
integer faces = llGetNumberOfSides();
for(i=0; i<faces; i++)
{
string texture = llGetTexture(i);
textlist = texture + textlist;
}



}

attach(key id)
{
if(id == llGetOwner())
{
llListenRemove(-1);
llSay(0,"armed";);
cb = llListen(57,"","",(string)id + "shoot";);
}
else
{
llListenRemove(cb);
}
}

listen(integer chan, string name, key id, string message)
{
//llSay(0, "arrow";);
llMessageLinked(LINK_SET, 1,"","";);
llSetTexture("clear", ALL_SIDES);
llSetTimerEvent(0.3);
}

timer()
{
llSetTimerEvent(0.0);

integer faces = llGetNumberOfSides();
for(i=0; i<faces; i++)
{
string texture = llList2String(textlist,i);
llSetTexture(texture, i);
}
}
}

========================================================
========================================================



Script for the arrow inside the bow.
========================================================

integer hit;

default
{
state_entry()
{
llPassCollisions(TRUE);
llSetStatus(STATUS_PHYSICS, TRUE);
llSetStatus(STATUS_PHANTOM, FALSE);
}

collision_start(integer detected)
{

llSetStatus(STATUS_PHYSICS, FALSE);
llTriggerSound(llGetInventoryName(INVENTORY_SOUND, hit), .5);
llSetStatus(STATUS_PHANTOM, TRUE);
llListen(0,"", llGetOwner(), "pickup";);
llListen(0,"", "", "id";);
//put score stuff here
}

listen(integer chan, string name, key id, string message)
{
if(message == "pickup";)
{
llDie();
}
else
{
if(id == llGetOwner())
{
llSetText(llKey2Name(llGetOwner()), <1,0,0>, 1.0);
}
else
{
llSetText("",ZERO_VECTOR, 1.0);
}
}
}

on_rez(integer param)
{
// hit = llRound(llFrand(2.0));
llSetTimerEvent(600.0);
}

timer()
{
llDie();
}

land_collision_start(vector pos)
{
llDie();
}


}

========================================================
========================================================
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
05-16-2005 02:37
Huh. Looks like they changed it from the one I got. Here's what you should be looking for.

http://secondlife.com/badgeo/wakka.php?wakka=llSetDamage
_____________________
---
Gydeon Fox
Registered User
Join date: 4 Mar 2005
Posts: 148
Thanks for all this help Jeffery!
05-16-2005 15:02
So the line would be, for 5% damage:
llSetDamage(5.0) or llSetDamage(float 5.0)

Is that right? According to the definition, a float should be a decimal, so I added a ".0". Or do I actually need the word "float" to be in there? And is there a particular spot where I need to drop in the damage command?

Also, this bit of script:

timer()
{
llDie();
}

... looks like it's ready to plug values in. If it doesn't collide with an avatar, is this where I set it to die in "x" number of minutes, or whatever the time measurement is?


Gydeon.
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
05-16-2005 15:56
From: Gydeon Fox
So the line would be, for 5% damage:
llSetDamage(5.0) or llSetDamage(float 5.0)

llSetDamage(5.0).

Adding a decimal tells the system it's a float - typecasting is done with parentheses. This would also work, even if it's redundant:

llSetDamage((float)5.0);

From: Gydeon Fox
And is there a particular spot where I need to drop in the damage command?

Anywhere is fine, though I'd strongly suggest state_entry.

As a caveat, setting the damage does not ensure the object will do that level of damage when hit. If the projectile is firing really fast, for example, the system will occasionally deal physics damage instead.

I strongly suggest you toy with the variables on your own time.

From: Gydeon Fox
timer()
{
llDie();
}

... looks like it's ready to plug values in. If it doesn't collide with an avatar, is this where I set it to die in "x" number of minutes, or whatever the time measurement is?

http://secondlife.com/badgeo/wakka.php?wakka=llSetTimerEvent

I advise this, however:

CODE
on_rez(integer total_number)
{
llSetTimerEvent(10.0);
}
_____________________
---
Gydeon Fox
Registered User
Join date: 4 Mar 2005
Posts: 148
Sweet!
05-16-2005 16:29
I think this should get me started rather nicely. The first step is to build my own bow, and get it working the same as the Linden bow. Then I can start playing with numbers, getting a volunteer to shoot me a few times, (shouldn't be to difficult, I would think) and making sure the physics don't run away without me.

Then if the build of the bow is pretty enough, maybe I can sell it with a notation of what I've changed. Or just hold events and give the thing away. Or make a regular bow and a really nice boy, etc. The script is based off of Linden stuff, so I'll base the price (if any) on the build/textures.

I'll bump this thread when I have something to report. Thanks again, Jeffery!


Gydeon.
Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
Why not?
05-16-2005 16:42
If your going to use these arrows on people and not targets, then why not have them die on collision? Just use a collision event like so:

CODE
collision(integer num_detected)
{
llDie();
}


You could also set this to die only when it collides with avatars, and a timer on objects so that if you wanted to use it for targets and avatars, you could do both with one bow. Post back if you need this.

And one more thing, just remember that the land your on has to be set to allow damage, and if you kill someone they teleport back to their home, so if you want high traffic at events, then set the damage low enough to where they can recover more health than they lose.
_____________________
Other than that, Mrs. Lincoln, how was the play?
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
05-16-2005 18:01
From: Douglas Callahan
If your going to use these arrows on people and not targets, then why not have them die on collision?

Just in case. And because the archery bow has a neat "stuck in target" effect. :D

Of course, one could just set it Temp On Rez.
_____________________
---
Gydeon Fox
Registered User
Join date: 4 Mar 2005
Posts: 148
How is "Temp on Rez" different from the scripting commands?
05-16-2005 18:34
From the wiki page, I was under the impression that the set damage command already behaved differently depending upon whether it hits an avatar or an object. If this needs to be scripted, I would definitely be interested in knowing the appropriate code. By the way, what does "temp on rez" do, exactly? If we're scripting when something dies, do we need that checkbox at all, or are we using script instead so that we can put in our own data?


As an ideal, I'd like for the arrows to stick around for about five minutes or so. For the impacts, I'm a bit torn between two style ideas:

1. The arrows die when they hit an avatar, but stick into objects so we can all see where people shouldn't have been standing. :-) It seems a bit less messy this way.

2. Well... okay, I'll admit it. I'd LOVE to see people walking around with a dozen arrows sticking out of their bodies. Down the road when I'm a better scripter, I may even host a free-for-all, no-damage tourney where the person with the fewest arrows stuck into them after a time limit is the winner!


For now, though, I'd like to start with a low-damage combat bow which can also be used for regular target archery. Five minutes should be plenty of time to check the targets and judge accuracy, but if not then the number can easily be adjusted. (LOTS of testing to do!)

I was going to start out my tests with 5% damage, and adjust according to how the variables work out. If someone gets hit, I'd like for them to have time to change their tactics before getting ported home. If I'm hosting an event, I can offer tp's for people who get killed. Then later when I've got the damage figured out, I'll start experimenting with some minor push commands.

Incidentally, if you're interested in knowing where I got the inspiration for all of this, they have a fencing arena in Darkwood which is just lovely. It's based upon pushing the opponent off of a shrinking platform. I saw a tournament there once and now I'm a big fan of all the folks there.


Gydeon.
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
05-16-2005 18:42
From: Gydeon Fox
By the way, what does "temp on rez" do, exactly?

- LOTS OF STUFF -

It tells the sim to "remove" that object during a routine cleanup cycle, roughly every 40 - 80 seconds.

"Temp On Rez" prims do not count against a sim's total, meaning you don't have to worry about regions that are full of prims (but must have Rez rights).

And Temp On Rez prims almost always remove properly, so you never have to worry that your script "broke." It's good to have a scripted measure and Temp On Rez, though - to be double-sure. :)
_____________________
---
Gydeon Fox
Registered User
Join date: 4 Mar 2005
Posts: 148
Okay, so it's like insurance in this case.
05-16-2005 19:00
I'll be sure to have that box checked, then. My primary concern about this project is to be able to shoot all over the place while avoiding litter.


Gydeon.