// Sword 2.0 // Compatible with Combat 2.0 // Written by Kero, 2024/09/28 float damagemax = 30.0; //ダメージ最大値 float damagemin = 10.0; //ダメージ最小値 float damagerange; float damage; // damagemax と damagemin の範囲でランダムにダメージ値が決まる。 float power = 1.0; // プッシュの強さ float range = 3.0; // 距離 (剣の長さ) float arc = 90.0; // 範囲 (振り回す角度) string attack = "sword_strike_R"; string hitsound = "Sword-Hit"; string failsound = "Sword-Fail"; key mykey = NULL_KEY; vector mypos; vector impulse; default { state_entry() { llSetText("", <1.0, 1.0, 1.0>, 1.0); mykey = llGetOwner(); arc *= DEG_TO_RAD; llPreloadSound(hitsound); llSleep(1.0); llPreloadSound(failsound); damagerange = damagemax- damagemin; llRequestPermissions(mykey, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS); } attach(key attached) { if (attached == NULL_KEY) { llReleaseControls(); } else { llResetScript(); } } run_time_permissions(integer perm) { if (perm & PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS) { llOwnerSay("Click Ground to Attack."); llTakeControls(CONTROL_LBUTTON | CONTROL_ML_LBUTTON, TRUE, TRUE); } } control(key id, integer level, integer edge) { if (level & edge & CONTROL_LBUTTON | level & edge & CONTROL_ML_LBUTTON) { llSensor("", NULL_KEY, AGENT_BY_LEGACY_NAME, range, arc); llStartAnimation(attack); } } sensor(integer detected) { mypos= llGetPos(); damage = damagemin + llFrand(damagerange); impulse = llVecNorm(llDetectedPos(0) - mypos) * damage * power; llPushObject(llDetectedKey(0), impulse, ZERO_VECTOR, FALSE); llTriggerSound(hitsound, 1.0); llDamage(llDetectedKey(0), damage, DAMAGE_TYPE_SLASHING); } no_sensor() { llSleep(0.5); llTriggerSound(failsound, 1.0); } }