Join us in Phaze Demesnes or follow us:

Home   Show All
Category: Contributor: Creator
Combat OpenSource_Combat_System  

OpenSource_Combat_System

Here it is: // (best used when compiled in mono) // // Also note, armor ratings are based on AC; velocity of bullet divided by AC equals damage. Set AC higher to take less damage.

Category: Combat
By : Tyro Dreamscape
Created: 2010-03-03 Edited: 2010-03-03
Worlds: Second Life + OpenSim

the Zip file

Download all files for OpenSource_Combat_System
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. OpenSource_Combat_System_1.lsl
1 // Basic Physics-Based Combat System (Open-Source)
2 // Created by Tyro Dreamscape
3 // Source Version: v1.1
4
5 // 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.
6
7 // This system does NOT accept melee damage. Only physical damage from bullets. It is able to have custom titles and colors of text.
8
9 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- CODE BELOW -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
10 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- CODE BELOW -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
11
12
13 string CSname = "[UnnamedCS v1.1]"; // The title displayed over the CS
14 integer userCHAN = 4; // The channel users use for commands
15 string adminKEY = "fe0f105a-3a2a-4d70-ad1e-6cac0da5388d"; //The key of the Admin, who uses /5heal and /5kill plus a name to do stuff
16
17 integer HEALTH = 100; //Basic health to start with
18 integer AC = 35; // Resistance to damage. Bullet vel/AC = damage taken.
19 vector COLOR = <1,1,1>; // The color of the meter text
20 integer REGENRATE = 5; // Time between each regeneration of 1 HP
21 integer DOWNTIME = 15; // How long you remain unconcious after being downed
22 string CUSTOMtitle = ""; // The starting title between CS name and stats
23 // ^^^^^^^ SETTINGS ^^^^^^^
24
25 key OWNER; // Not to be changed...
26 integer DAMAGE; // Not to be changed...
27 integer DEAD = FALSE; // Not to be changed...
28
29 default // ~~~~~~~~~~~~~~OFFLINE STATE~~~~~~~~~~~~~
30 {
32 {
34 OWNER = llGetOwner();
36
37 llStopAnimation("DOWNED");
38
39 llListen(userCHAN,"",llGetOwner(),"");
40 llListen(5,"",adminKEY,"");
41 HEALTH = 100;
42 integer DEAD = FALSE;
43 llSetText(CSname + CUSTOMtitle + "\nOFFLINE", COLOR, 1.0);
44 llOwnerSay("-\nOFFLINE\nSay /4on to enable system. '/4color (vector)' will change hovertext. '/4title (text)' will add a custom title.\n'/4reset' will perform a hard reset of the scripts, and can be performed at any time... but will lose you ANY and ALL saved information.");
45 }
46
47 attach(key id) // This resets the whole system if a new owner is detected
48 {
49 if(OWNER != llGetOwner())
50 {
51 llOwnerSay("New owner detected. Performing total wipe of memory...");
52 llSleep(2);
53 llOwnerSay("Welcome to " + CSname + ". This system ONLY accepts physical damage, modified by a set ArmorClass or AC."); // The new owner Welcome Message.
55 }
56 }
57
58 listen(integer channel, string name, key id, string message) // Here be all commands.
59 {
60 string MSG = llToLower(message); // Changes all commands to lowercase so it ain't case-sensitive
61 if(channel == 4)
62 {
63 if(message == "reset")
64 {
65 llOwnerSay("Performing total reset...");
67 }
68
69 if(message == "on")
70 {
71 state ARMED;
72 }
73
74 if(llGetSubString(MSG,0,4) == "title") //Setting Titles
75 {
76 if(llGetSubString(message,5,-1) != "")
77 {
78 CUSTOMtitle = "\n" + llGetSubString(message,5,-1) + "\n";
79 llSetText(CSname + CUSTOMtitle + "\nOFFLINE", COLOR, 1.0);
80 }
81 else
82 {
83 CUSTOMtitle = "";
84 llSetText(CSname + CUSTOMtitle + "\nOFFLINE", COLOR, 1.0);
85 }
86 }
87
88 if(llGetSubString(MSG,0,4) == "color") //Setting colors.
89 {
90 if(llGetSubString(message,5,-1) != "")
91 {
92 COLOR = (vector)llGetSubString(message,6,-1);
93 llSetText(CSname + CUSTOMtitle + "\nOFFLINE", COLOR, 1.0);
94 }
95 else
96 {
97 COLOR = <1,1,1>;
98 llSetText(CSname + CUSTOMtitle + "\nOFFLINE", COLOR, 1.0);
99 }
100 }
101 }
102 else // Everything here is ADMIN ONLY command!
103 {
104 if(message == "kill " + llKey2Name(llGetOwner()))
105 {
106 llOwnerSay("You were AdminKilled by: " + name);
107 state down;
108 }
109 } // Everything here is ADMIN ONLY command!
110 }
111 }
112
113 state ARMED // ~~~~~~~~~~~~~~ONLINE STATE~~~~~~~~~~~~~
114 {
116 {
119 llStopAnimation("dead");
120
121 llListen(userCHAN,"",llGetOwner(),"");
122 llListen(5,"",adminKEY,"");
123 llSetTimerEvent(REGENRATE);
124 llSetText(CSname + CUSTOMtitle + "\nHP: "+(string)HEALTH, COLOR, 1.0); // Set text for meter!
125 llOwnerSay("-\nONLINE\nSay /4off to disable system.");
126 }
127
128 attach(key id) // This resets the whole system if a new owner is detected
129 {
130 if(OWNER != llGetOwner())
131 {
132 llOwnerSay("New owner detected. Performing total wipe of memory...");
134 }
135 }
136
137 collision_start(integer total_number) // THIS IS WHERE DAMAGE IS CALCULATED
138 {
139 //key BLEG = llDetectedKey(0);
140 if(llDetectedType(0) != AGENT)
141 {
142
143 DAMAGE = llRound(llVecMag(llDetectedVel(0))) / AC;
144 // The damage you take is 'bullet velocity' divided by 'AC'. So, 100m per second bullets would normally do 10 damage each to a 10 AC individual.
145 HEALTH = HEALTH - DAMAGE; // Subtract health...
146 llSetText(CSname + CUSTOMtitle + "\nHP: "+(string)HEALTH, COLOR, 1.0); // Refresh text to show new status
147 if(HEALTH <= 0) // If you're out of health...
148 {
149 llShout(0, "/me -- "+llKey2Name(llGetOwner())+ " has been DEFEATED");
150 state down; // ...drop dead.
151 }
152 }
153 }
154
155 listen(integer channel, string name, key id, string message)
156 {
157 string MSG = llToLower(message);
158 if(channel == 4)
159 {
160 if(message == "reset")
161 {
162 llOwnerSay("Performing total reset...");
164 llShout(0, llKey2Name(llGetOwner()) + " is resetting while combative..."); // Alert others to possible cheating attempt >.>
165 }
166
167 if(message == "off")
168 {
169 state default;
170 }
171
172 if(llGetSubString(message,0,4) == "title")
173 {
174 if(llGetSubString(message,5,-1) != "")
175 {
176 CUSTOMtitle = "\n" + llGetSubString(message,5,-1) + "\n";
177 llSetText(CSname + CUSTOMtitle + "\nHP: "+(string)HEALTH, COLOR, 1.0);
178 }
179 else
180 {
181 CUSTOMtitle = "";
182 llSetText(CSname + CUSTOMtitle + "\nHP: "+(string)HEALTH, COLOR, 1.0);
183 }
184 }
185
186 if(llGetSubString(MSG,0,4) == "color")
187 {
188 if(llGetSubString(message,5,-1) != "")
189 {
190 COLOR = (vector)llGetSubString(message,6,-1);
191 llSetText(CSname + CUSTOMtitle + "\nHP: "+(string)HEALTH, COLOR, 1.0);
192 }
193 else
194 {
195 COLOR = <1,1,1>;
196 llSetText(CSname + CUSTOMtitle + "\nHP: "+(string)HEALTH, COLOR, 1.0);
197 }
198 }
199 }
200 else // Everything here is ADMIN ONLY command!
201 {
202 if(message == "kill " + llKey2Name(llGetOwner()))
203 {
204 llOwnerSay("You were AdminKilled by: " + name);
205 state down;
206 }
207
208 if(message == "heal " + llKey2Name(llGetOwner()))
209 {
210 llOwnerSay("You were AdminHealed by: " + name);
211 HEALTH = HEALTH + 10;
212 }
213 } // Everything here is ADMIN ONLY command!
214 }
215
216 timer() // The timer for regeneration
217 {
218 if(DEAD == FALSE)
219 {
220 if(HEALTH >= 100)
221 {
222 // Do Nothing...
223 }
224 else
225 {
226 HEALTH++; // Regenerate 1 HP
227 llSetText(CSname + CUSTOMtitle + "\nHP: "+(string)HEALTH, COLOR, 1.0); // Refresh title
228 }
229 }
230 else
231 {
232 state down;
233 }
234 }
235 }
236
237 state down // ~~~~~~~~~~~~~~DEAD STATE~~~~~~~~~~~~~
238 {
240 {
242
243 llStartAnimation("dead");
244
245 llListen(userCHAN,"",llGetOwner(),"");
246 llListen(5,"",adminKEY,"");
247 integer DEAD = TRUE;
249 llSetText(CSname + CUSTOMtitle + "\nUNCONSCIOUS", <1,0,0>, 0.7);
250
251 llSetTimerEvent(DOWNTIME);
252 }
253
255 {
257 {
266 }
267 }
268
269 attach(key id) // This resets the whole system if a new owner is detected
270 {
271 if(OWNER != llGetOwner())
272 {
273 llOwnerSay("New owner detected. Performing total wipe of memory...");
275 }
276 }
277
278 timer() // Downtime expired...
279 {
280 state default; //...reset to offline status
281 }
282
283 listen(integer channel, string name, key id, string message)
284 {
285 string MSG = llToLower(message);
286 if(channel == 4)
287 {
288 if(message == "reset")
289 {
290 llOwnerSay("Performing total reset...");
291 llShout(0, llKey2Name(llGetOwner()) + " is resetting while down..."); // Alert others to possible cheating attempt >.>
293 }
294
295 if(llGetSubString(MSG,0,4) == "title")
296 {
297 if(llGetSubString(message,5,-1) != "")
298 {
299 CUSTOMtitle = "\n" + llGetSubString(message,5,-1) + "\n";
300 llSetText(CSname + CUSTOMtitle + "\nUNCONSCIOUS", <1,0,0>, 0.7);
301 }
302 else
303 {
304 CUSTOMtitle = "";
305 llSetText(CSname + CUSTOMtitle + "\nUNCONSCIOUS", <1,0,0>, 0.7);
306 }
307 }
308
309 if(llGetSubString(MSG,0,4) == "color")
310 {
311 if(llGetSubString(message,5,-1) != "")
312 {
313 COLOR = (vector)llGetSubString(message,6,-1);
314 llSetText(CSname + CUSTOMtitle + "\nUNCONSCIOUS", <1,0,0>, 0.7);
315 }
316 else
317 {
318 COLOR = <1,1,1>;
319 llSetText(CSname + CUSTOMtitle + "\nUNCONSCIOUS", <1,0,0>, 0.7);
320 }
321 }
322 }
323 else // Everything here is ADMIN ONLY command!
324 {
325 if(message == "heal " + llKey2Name(llGetOwner()))
326 {
327 llOwnerSay("You were AdminHealed by: " + name);
328 state ARMED;
329 }
330 } // Everything here is ADMIN ONLY command!
331 }
332 }