Sci-Fi Combat System

Written by Kitsune

The Sci-Fi Combat System (SFCS) is an RP system made to facilitate Sci-Fi Roleplay within Second Life.
Currently, it supports Star-Wars Roleplay, with future updates being added for Stargate Roleplay. (It may even allow the intermixing of the two.)

Commands:
/1 sfcs - Brings up SFCS Menu with these functions.
/1 help - Gives you this file.
/1 hud - Gives you the SFCS HUD
/1 fullreset - Resets all settings (color and title), as well as resetting health and stamina to 100%
/1 reset - Resets health and stamina to 100%
/1 color - Sets Color. Replace R, G and B with Values from 0 to 255. The brackets and commas are required
/1 title text - Sets your personal title. Replace text with your title. To clear the title, replace text with none.
/1 update - Looks for the next update.
/1 regen - Start Regeneration of Health from Stamina
/1 stopregen - Stop Regeneration of Health from Stamina (Before completion)To block (hold Up + Down simultaneously while not attacking (no holding the mouse button at the same time))

---You will also need a sleep and block animation for this Combat System to work properly.  Put the scripts in their own prim and the HUD script has its own prim and is placed inside the combat system prim:

Display Script:

key collided;
integer dead = 0;
integer health;
integer stamina;
integer blocking = 0;
string sfcs;
string title;
string owner;
string heal;
vector color;
integer tick;


fullinit()
{
    color = <253, 225, 149> / 255;
    title = "";
    init();
}
init()
{
    llMessageLinked(LINK_THIS, 0, "stopregen", NULL_KEY);  
    tick = 0;
    owner = llToLower(llKey2Name(llGetOwner()));
    heal = "heal " + llGetSubString(owner, 0, 0);
    sfcs = "SFCS " + llGetSubString(llGetObjectName(), 21, -1);
    health = 100;
    stamina = 100;
    llListen(1, "", "", "");
    llListen(532254, "", "", "");
    llListen(-690069, "", "", "");
    llListen(696969, "", "", "");
    updatehealth();
    llOwnerSay(sfcs + " Active. For Help/Commands, type /1 help. For the menu, type /1 sfcs");
}

updatehealth()
{
    string stats;
    if(health > 100)
    {
        health = 100;
    }
    else if(health < 0)
    {
        health = 0;
    }
    if(stamina > 100)
    {
        stamina = 100;
    }
    else if(stamina < 0)
    {
        stamina = 0;
    }
    if(health == 0)
    {
        die();
    }
    if(blocking == 0)
    {
       stats = sfcs + "\n";
    }
    else
    {
        stats = "Blocking....\n";
    }
    if(title != "")
    {
        stats += title + "\n";
    }
    stats += "Health: "+ (string)health + "% / Chakra: " + (string)stamina + "%";
    llShout(-696969, "color " + (string)color);
    llShout(-696969, (string)health + "," + (string)stamina);
    llSetText(stats, color, 1.0);
}

die()
{
    if(dead == 0)
    {
        dead = 1;
        llStartAnimation("sleep");
        llSetTimerEvent(0);
        llSay(0, llKey2Name(llGetOwner()) + " has been defeated");
    }
}
live()
{
    llStopAnimation("sleep");
    dead = 0;
    llSetTimerEvent(3);
}
block()
{
    llStartAnimation("block");
}
unblock()
{
    llStopAnimation("block");
}
healstam(integer damage)
{
    if(blocking == 1 && damage < 0)
    {
        stamina += damage;
    }
    else if(blocking == 0 && damage < 0)
    {
        health += damage;
    }
    else if(damage > 0)
    {
        if(health == 0)
        {
            live();
        }
        health += damage;
        stamina = 100;
    }
    
    updatehealth();
}
        
    

default
{
    state_entry()
    {
        fullinit();
    }
    run_time_permissions(integer perms)
    {
        if(perms & PERMISSION_TAKE_CONTROLS)
        {
            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);
            init();
        }
        if(perms & PERMISSION_TRIGGER_ANIMATION)
        {
            live();
        }
    }
    attach(key attached)
    {
        if(attached != NULL_KEY)
        {
            llRequestPermissions(llGetOwner(),PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
        }
    }
    collision_start(integer total)
    {
        if(llDetectedKey(0) != collided)
        {
            collided = llDetectedKey(0);
            if(llDetectedName(0) == "Fireball")
            {
                healstam(-10);
            }
            else if(llDetectedName(0) == "Pull")
            {
            }
            else if(llDetectedType(0) & ACTIVE && !(llDetectedType(0) & AGENT))
            {
                healstam(-2);
            }
        }
        
    }
    sensor(integer total)
    {
        integer i;
        for(i = 0; i < total; i++)
        {
            llShout(-690069, llDetectedKey(i));
        }
    }
    timer()
    {
        if(health < 100 || stamina < 100)
        {
            if(tick == 1)
            {
                health += 1;
                tick = 0;
            }
            else if(tick == 0)
            {
                tick = 1;
            }
            if(blocking == 0)
            {
                stamina += 1;
            }
            updatehealth();
        }
    }
    control(key id,integer held,integer change)
    {
        if(held & CONTROL_LBUTTON || held & CONTROL_ML_LBUTTON)
        {
            blocking = 0;
            if((change & held & CONTROL_ROT_LEFT) | (change & ~held & CONTROL_LEFT))
            {
                llSensor("", "", AGENT, 4, PI_BY_TWO);
            }
            if((change & held & CONTROL_ROT_RIGHT) | (change & ~held & CONTROL_RIGHT))
            {
                llSensor("", "", AGENT, 4, PI_BY_TWO);
            }
            if(change & held & CONTROL_FWD)
            {
                llSensor("", "", AGENT, 4, PI_BY_TWO);                
            }
            if(change & held & CONTROL_BACK)
            {
                llSensor("", "", AGENT, 4, PI_BY_TWO);                
            }
            
        }
        else if(~held & CONTROL_LBUTTON || ~held & CONTROL_ML_LBUTTON)
        {
            if((held & CONTROL_BACK) && (held & CONTROL_FWD))
            {
                if(stamina > 0)
                {
                    blocking = 1;
                    block();
                }
                else
                {
                    if(blocking == 1)
                    {
                        unblock();
                    }
                    blocking = 0;
                }
                updatehealth();
            }
//            else if((change & ~held & CONTROL_BACK) && (change & ~held & CONTROL_FWD))
            else
            {
                if(blocking == 1)
                {
                    unblock();
                }
                blocking = 0;
                updatehealth();
            }
        }
    }
    link_message(integer sender, integer num, string msg, key id)
    {
        if(msg == "regen")
        {
            if(health < 100 && stamina > 0 && health > 0)
            {
                stamina -= 2;
                health += 2;
            }
            if(health >= 100 || stamina == 0 || health == 0)
            {
                llMessageLinked(LINK_THIS, 0, "stopregen", NULL_KEY);  
            }
                
            updatehealth();
        }
    }
    listen(integer chan, string name, key id, string msg)
    {
        string mesg;
        mesg = llToLower(msg);
        if(chan == 1)
        {
            if(llGetOwnerKey(id) == llGetOwner())
            {
                if(mesg == "reset")
                {
                    live();
                    init();
                }
                else if(mesg == "fullreset")
                {
                    live();
                    fullinit();
                }
                else if(mesg == "regen")
                {
                    llMessageLinked(LINK_THIS, 0, "startregen", NULL_KEY);
                }
                else if(mesg == "stopregen")
                {
                    llMessageLinked(LINK_THIS, 0, "stopregen", NULL_KEY);
                }
                else if(mesg == "help")
                {
                    llGiveInventory(llGetOwner(), "SFCS Help");
                }
                else if(llGetSubString(mesg, 0, 5) == "color ")
                {
                    color = (vector)llGetSubString(msg, 6, -1);
                    color /= 255;
                    updatehealth();
                }
                else if(llGetSubString(mesg, 0, 5) == "title ")
                {
                    title = llGetSubString(msg, 6, -1);
                    if(llToLower(title) == "none")
                    {
                        title = "";
                    }
                    updatehealth();
                }
            }
            
            if(llGetSubString(mesg, 0, 5) == heal)
            {
                if(health < 100)
                {
                    healstam(10);
                }
                updatehealth();
            }
        }
        else if(chan == 532254 && llGetSubString(name, 0, 4) == "Force")
        {
            if(msg == (string)llGetOwner())
            {
                healstam(-2);
            }
            else if(msg == (string)llGetOwner() + "+")
            {
                healstam(5);
            }
        }
        else if(chan == 696969)
        {
            if(msg == (string)llGetOwner())
            {
                healstam(-5);
            }
            else if(msg == (string)llGetOwner() + "+")
            {
                healstam(5);
            }
            else if(llGetSubString(msg, 0, 35) == (string)llGetOwner())
            {
                healstam((integer)llGetSubString(msg, 36, -1));
            }
        }
        else if(chan == -690069)
        {
            if(msg == (string)llGetOwner())
            {
                healstam(-2);
            }
            else if(msg == "updatehp" && llGetOwnerKey(id) == llGetOwner())
            {
                updatehealth();
            }
        }
    }
        
}

Function Script:

default
{
    link_message(integer sender, integer num, string msg, key id)
    {
        if(msg == "startregen")
        {
            llSetTimerEvent(0.75);
        }
        else if(msg == "stopregen")
        {
            llSetTimerEvent(0.0);
        }
    }
    timer()
    {
        llMessageLinked(LINK_THIS, 0, "regen", NULL_KEY);
    }
}

Menu Script:
list menulist = ["Help", "HUD", "Update", "Regen", "Stopregen", "Reset", "FullReset"];

init()
{
    llListen(1, "", "", "");
}


default
{
    state_entry()
    {
        init();
    }
    attach(key attached)
    {
        if(attached != NULL_KEY)
        {
            init();
        }
    }
    listen(integer chan, string name, key id, string msg)
    {
        if(id == llGetOwner() && llToLower(msg) == "sfcs")
        {
            llDialog(llGetOwner(), "SFCS Menu", menulist, 1);
        }
        else if(id == llGetOwner() && llToLower(msg) == "hud")
        {
            llGiveInventory(llGetOwner(), "SFCS HUD");
        }
    }
}

Update Server Script:

string updateserver = "This email address is being protected from spambots. You need JavaScript enabled to view it.";
string password = "stargate-sg1x";
string version;
init()
{
    version = llGetSubString(llGetObjectName(), 21, -1);
    llListen(1, "", "", "");
    llOwnerSay("Performing Automatic Update Check");
    llEmail(updateserver, password, (string)llGetOwner() + version);
}
default
{
    attach(key attached)
    {
        if(attached != NULL_KEY)
        {
            init();
        }
    }
    listen(integer chan, string name, key id, string mesg)
    {
        string msg = llToLower(mesg);
        if(id == llGetOwner() && msg == "update")
        {
            llEmail(updateserver, password, (string)llGetOwner() + version);
        }
    }
}

 

SCFS HudScript (This goes in ites own prim):

string updateserver = "This email address is being protected from spambots. You need JavaScript enabled to view it.";
string password = "stargate-sg1x";
string version;
init()
{
    version = llGetSubString(llGetObjectName(), 21, -1);
    llListen(1, "", "", "");
    llOwnerSay("Performing Automatic Update Check");
    llEmail(updateserver, password, (string)llGetOwner() + version);
}
default
{
    attach(key attached)
    {
        if(attached != NULL_KEY)
        {
            init();
        }
    }
    listen(integer chan, string name, key id, string mesg)
    {
        string msg = llToLower(mesg);
        if(id == llGetOwner() && msg == "update")
        {
            llEmail(updateserver, password, (string)llGetOwner() + version);
        }
    }
}