Join us in Outworldz at or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Combat Improved_Combat_System  


An updated combat system.

I have changed a great deal in this script. Please refer to the original version to see the changes.

Also i use the name HUD when referring to the cs as I am used to scripting combat systems that have a full HUD setup. Even though this system has no HUD so to speak i will be using HUD as a reference to this system.
Based on

Category: Combat
By : shesuka
Created: 2013-03-06 Edited: 2013-03-06
Worlds: Second Life

the Zip file

Download all files for Improved_Combat_System
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Improved_Combat_System_1.lsl
1 // This script is free for use, and may be set with any perms you wish, and even sold; it is only to be sold if it is modified. Under no circumstances should you sell this free and opensource code to anyone, beyond the basic 1L for 'gift-item' purposes. This original code should remain full-perms unless modified.
5 string csName = "[Enter CS Name Here]";//Displays the name of your Combat System in floating text. So your system entry for this line may look something like string csName = "[THE FUNKY COMBAT SYSTEM]";
6 integer chan = 4; //Defining this as 4 means that the player can use the various commands for the HUD on channel 4.
7 integer health = 100; //Your standard Health Amount.
8 integer healthMax = 100; //Your maxmimum Health Amount.
9 integer resist = 10; //Resistance to damage taken.
10 vector color = <1,1,1>; //Colour of the CS Text above the head.
11 integer healthInc = 5; //Time between each health regeneration.
12 string customTitle = "Unamed Player"; //Your own custom title or name that users can set to be displayed in the overhead text via one of the new commands i added.
13 key user; //Key of person playing (DONT EDIT).
14 integer deathStatus = 0; //If 1 then dead, else not dead. Used in the timer to let the timer know that if the status is 1 then revive and re set status to 0 (DONT EDIT).
15 integer hudStatus = 0; //If 1 then HUD is activate else HUD is in offline mode (DONT EDIT).
16 string statusText = "HUD OFFLINE"; //To be displayed in the overhead text if hud is online this will be changed later in the script (DONT EDIT).
18 setStatusText(){
19 llSetText(csName + "\n" + "Health : " + (string)health + " / " + (string)healthMax + "\n" + customTitle + "\n" + statusText, color, 1.0);
20 }
22 default{
23 attach(key attached){
24 if(attached == NULL_KEY){
25 llSay(0, (string)llKey2Name(user) + " has detached their " + (string)csName); //Says this on channel 0 if they detatch "Shesuka Resident has detached their FUNKY COMBAT SYSTEM
26 }else{
27 hudStatus = 0; //On attach the HUD is off by default.
28 statusText = "HUD OFFLINE"; //On attach HUD displays it is off by default.
29 user = llGetOwner(); //Defines the user variable from above as the owners key. Reason i did this is it means you do not have to reset each time a new owner is given the HUD.
30 llRequestPermissions(user, PERMISSION_TRIGGER_ANIMATION); //Requests the users permissions to play animations.
31 llListen(chan, "", user, ""); //Listen on the channel chan and only to the user.
32 setStatusText(); //Our global status variable. The handy thing about global variables is i only need to write llSetText once at the top of the script and then i can just user setStatusText(); instead of writing out the full set text line each time.
33 llOwnerSay("Welcome to the " + (string)csName + ". " + "Please type /4help for a list of commands to help you activate and use this system"); //Tells the user on attach what to do and gives them a welcome message.
34 }
35 }
36 listen(integer channel, string name, key id, string message){
37 if(channel == chan){
38 if(id == user){
39 if(message == "help"){
40 //Displays the list of commands you can do with this system.
41 llOwnerSay("Command for this System are typed onto channel " + (string)chan + " and are as follows : " + "\n" + "1. To activate the system type : /4on" + "\n" + "2. To deactivate the system type : /4off" + "\n" + "3. To change your title/name type : /4title (name) so for example you might type..../4title THE GREAT BASINGA...." + "\n" + "4. To change your Overhead Text color type : /4color (vector colour) so for example you might type..../4color <1,0,0>....which would set the overhead text to red.");
42 }else if(message == "on"){
43 hudStatus = 1; //Set to 1 as HUD is on. Setting as 1 and 0 is the same as using TRUE and FALSE.
44 statusText = "HUD ONLINE"; //Sets the HUD text status to "HUD ONLINE".
45 setStatusText(); //Again calling this global function to update the overhead text to show the HUD is online.
46 llOwnerSay((string)csName + " is now online"); //Telling player the HUD is online
47 }else if(message == "off"){
48 hudStatus = 0; //Set to 0 as HUD is now off.
49 statusText = "HUD OFFLINE"; //Sets the HUD text status back to "HUD OFFLINE".
50 setStatusText(); //Now calling to update the overhead text to display the offline status of the HUD.
51 llOwnerSay((string)csName + " is now offline"); //Telling player the HUD is offline.
52 }else if(llGetSubString(message, 0,4) == "title"){ //checking if the first five letters of the message say title.
53 if(llGetSubString(message, 5,-1) != ""){ //Checking if letters 5 to the last letter do not equal nothing.
54 customTitle = llGetSubString(message, 5,-1); //Assign letters 5 to end (name etc) as the new title.
55 llOwnerSay("You have changed your title to " + customTitle + "."); //Telling the user that their name is successfully changed.
56 setStatusText(); //Update overhead text to display new name.
57 }
58 }else if(llGetSubString(message, 0,6) == "color"){ //If the first 7 letters say color.
59 if(llGetSubString(message, 7,-1) != ""){ //if letters/symbols etc etc 7 to end do not equal nothing.
60 color = (vector)llGetSubString(message, 7,-1); //Set the new color of the overhead text as whatever colour is set from 7 to end in the message.
61 setStatusText(); //Update new color to overhead text.
62 }
63 }else{
64 llOwnerSay("Unknown command please try again"); //If a help command is entered wrongly then it will display this message.
65 }
66 }
67 }
68 }
70 if(hudStatus == 0)return;
71 if(llDetectedType(0) == AGENT_BY_LEGACY_NAME)return;//if the detected object is an agent then do not go any further.
72 integer damage = llRound(llVecMag(llDetectedVel(0))/resist);
73 health -= damage;//Health is minus the bullet velocity divided by the resist and then the damage is taken off the health.
74 setStatusText(); //Update over head text to display new health.
75 llSetTimerEvent(10); //Instead of having individual times and multiple timers as this is a script for beginners we are going to use a default value of 10 for all timers. This one will increase health.
76 if(health <= 0){
77 deathStatus = 1; //As status now equals 1
78 llShout(0, (string)llKey2Name(user) + " has died in combat."); //Announce players death.
79 llStartAnimation("death");
80 health = 0; //so if health is reduced to below 0 this will automatically make health equal 0 so you don't go into negative numbers.
81 setStatusText(); //update new health to overhead text.
82 llSetTimerEvent(10); //This will start the timer again at 10 seconds but with the deathStatus added this will also deal with how long you stay dead for.
83 }
84 }
85 timer(){
86 if(health < healthMax){//If health is less than the max health available.
87 health += 20; //So every 10 seconds add 20 health.
88 if(health > healthMax){ //Checking if health is greater than healthMax.
89 health = healthMax; //If so health is equal healthMax.
90 }
91 setStatusText(); //update health regain to overhead text.
92 }else if(deathStatus == 1){ //if death status is true (1).
93 llStopAnimation("death"); //stop the death animation.
94 llOwnerSay("You have been revived"); //alert the player.
95 }
96 }
97 }

Back to the Best Free Tools in Second Life and OpenSim.