Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

sword script not working

Bizcut Vanbrugh
Registered User
Join date: 23 Jul 2006
Posts: 99
08-02-2006 04:17
i got ahold of a sword script and it doesnt seem to be working for the collision can some one tell me what is wrong sorry i dont know how to get it in one of those cool boxes


code:
CODE
// code here[*/PHP]
integer SWORD = 1;
integer PUNCH12 = 2;
integer PUNCHL = 3;
integer KICK = 4;
integer FLIP = 5;

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(FALSE, 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("punch_L");
llSetTimerEvent(0.25);
strike_type = PUNCHL;
}
if (edge & (CONTROL_RIGHT | CONTROL_ROT_RIGHT))
{
llStartAnimation("kick_roundhouse_R");
llSetTimerEvent(0.25);
strike_type = KICK;
}
if (edge & CONTROL_BACK)
{
llStartAnimation("punch_onetwo");
llSetTimerEvent(0.25);
strike_type = PUNCH12;
}
if (edge & CONTROL_DOWN)
{
llMoveToTarget(llGetPos(), 0.25);
llSleep(1.0);
llStopMoveToTarget();
}
}
}

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 *= 200.0;
llPushObject(llDetectedKey(0), dir, ZERO_VECTOR, FALSE);
}
else if (strike_type == PUNCH12)
{
llTriggerSound("crunch", 0.2);
dir += dir;
dir *= 100.0;
llPushObject(llDetectedKey(0), dir, ZERO_VECTOR, FALSE);
}
else if (strike_type == PUNCHL)
{
llTriggerSound("crunch", 0.2);
dir -= llRot2Left(rot);
dir *= 100.0;
llPushObject(llDetectedKey(0), dir, ZERO_VECTOR, FALSE);
}
else if (strike_type == KICK)
{
llTriggerSound("crunch", 0.2);
dir += dir;
dir *= 100.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;
}
}

nand Nerd
Flexi Fanatic
Join date: 4 Oct 2005
Posts: 427
08-02-2006 07:11
I'm afraid I can't quite see where the script is in error, to put the script code in a box use PHP tags [*PHP]// code here[*/PHP] without the *s
becomes
CODE
// code here

(see sticky at top of scripting tips forum)
_____________________
www.nandnerd.info
http://ordinalmalaprop.com/forum - Ordinal Malaprop's Scripting Forum
Bizcut Vanbrugh
Registered User
Join date: 23 Jul 2006
Posts: 99
08-02-2006 09:02
well it swings but has no effect on anyone. i changed it a litle trying to figure out what was wrong. i thought that maybe it wasnt registering a collision but the say command i put in is registering a collision. am i missing a force setting some where ??
Damanios Thetan
looking in
Join date: 6 Mar 2004
Posts: 992
08-02-2006 11:27
The script uses push to actually show an effect.
Nowadays a lot of areas are push restricted, to prevent griefing.
Make sure you use the weapon on a parcel you own, or that push is enabled for the parcel.

(Do the sounds work?)
_____________________
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
08-02-2006 11:40
Err...well, first you aren't actually testing for collisions. You might try throwing in a 'collision_start' to see what happens. Some temporary 'llOwnerSay()'s might work well in any case to debug whether or not the logic is actually being exercised.

Second, if you really want to use a sensor, you could use an 'llSensorRepeat()' instead of using a timer. That's sort of what it is made for. Either way 0.25 seconds is actually a long time in between calls. If things are moving with moderate speed you could easily, "miss," a target with that window of time.
nand Nerd
Flexi Fanatic
Join date: 4 Oct 2005
Posts: 427
08-02-2006 14:02
As far as I am aware actual collisions will not register on attachments as they dont have a physical presence (and neither would volume detect). This is really to do with the way the avatar is handled by the sim with animations only taking effect client-side the sim wouldn't know where and when a collision with an attachment takes place.

Sorry, forgot to say that the code above is fine from this respect as it doesn't actually use collisions.
_____________________
www.nandnerd.info
http://ordinalmalaprop.com/forum - Ordinal Malaprop's Scripting Forum
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
08-02-2006 14:59
From: nand Nerd
As far as I am aware actual collisions will not register on attachments as they dont have a physical presence (and neither would volume detect). This is really to do with the way the avatar is handled by the sim with animations only taking effect client-side the sim wouldn't know where and when a collision with an attachment takes place.

Sorry, forgot to say that the code above is fine from this respect as it doesn't actually use collisions.

Ah. I wasn't sure of that. Some shield scripts I have seen have used 'collision_start', but I haven't really messed with it myself yet (on attachments).