// Sword 1.0 // MeltingDots Combat System // Written by Kero, 2024/09/28 integer channel = 20240928; // 通信チャンネル integer handle; integer damagemax = 30; //ダメージ最大値 integer damagemin = 10; //ダメージ最小値 integer damagerange; integer damage; // damagemax と damagemin の範囲でランダムに与えるダメージ値が決まる。 float power = 1.0; // プッシュの強さ float range = 3.0; // 距離 (剣の長さ) float arc = 90.0; // 範囲 (振り回す角度) integer life = 100; // Life の初期値 float deadtime = 5.0; // 動けなくなる時間 string attack = "sword_strike_r"; string dead = "dead"; string hitsound = "Sword-Hit"; string failsound = "Sword-Fail"; key mykey = NULL_KEY; key target; vector mypos; vector impulse; // push される力 integer mydamage; // 受けたダメージ値 vector green = <0.0, 1.0, 0.0>; vector yellow = <1.0, 1.0, 0.0>; vector red = <1.0, 0.0, 0.0>; vector black = <0.0, 0.0, 0.0>; vector color; getdamage(integer val) { life -= val; if (life <= 0) color = black; else if (life < 25) color = red; else if (life < 50) color = yellow; else color = green; llSetText((string)life, color, 1.0); if (life <= 0) { llListenRemove(handle); llStartAnimation(dead); mypos = llGetPos(); llMoveToTarget(mypos, 0.1); llSleep(deadtime); llStopMoveToTarget(); life = 100; color = green; llSetText((string)life, color, 1.0); llStopAnimation(dead); handle = llListen(channel, "", NULL_KEY, ""); } } default { state_entry() { mykey = llGetOwner(); arc *= DEG_TO_RAD; color = green; llSetText((string)life, color, 1.0); 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) { handle = llListen(channel, "", NULL_KEY, ""); llOwnerSay("Click Ground to Attack."); llTakeControls(CONTROL_LBUTTON | CONTROL_ML_LBUTTON, TRUE, TRUE); } } control(key id, integer level, integer edge) { if (edge & level & CONTROL_LBUTTON | edge & level & CONTROL_ML_LBUTTON) { llSensor("", NULL_KEY, AGENT_BY_LEGACY_NAME, range, arc); llStartAnimation(attack); } } sensor(integer detected) { mypos= llGetPos(); damage = (integer)(damagemin + llFrand(damagerange)); target = llDetectedKey(0); llSay(channel, (string)target + "_" + (string)damage + "_" + (string)mypos); llTriggerSound(hitsound, 1.0); } no_sensor() { llSleep(0.5); llTriggerSound(failsound, 1.0); } listen(integer chan, string name, key id, string command) { list com = llParseString2List(command, ["_"], []); if (llList2Key(com, 0) == mykey) { mydamage = (integer)(llList2String(com, 1)); impulse = llVecNorm(llGetPos() - (vector)(llList2String(com, 2))) * mydamage * power; llPushObject(mykey, impulse, ZERO_VECTOR, FALSE); getdamage(mydamage); } } }