Difference between revisions of "Template:Darwin's Scripts"
Jump to navigation
Jump to search
(New page: <includeonly> test {{#switch: {{{1}}} | find screen width = <lsl>default { touch_start(integer total_number) { vector scale = llGetScale(); vector off_point = ll...) |
|||
(29 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<includeonly> | <includeonly> | ||
{{#switch: {{{1}}} | {{#switch: {{{1}}} | ||
| find screen width = | | find screen width = <div id="box"> | ||
==Find Screen Width== | |||
<div style="padding: 0.5em"> | |||
The script below will give the width of the screen in meters by touching anywhere on the visible face, given that the prim is a box with zero rotation and attached at one of the corner HUD attachment points. | |||
<lsl>default | <lsl>default | ||
{ | { | ||
Line 17: | Line 18: | ||
llOwnerSay((string)screen_width); | llOwnerSay((string)screen_width); | ||
} | } | ||
}</lsl></div></div> | |||
| date difference = <div id="box"> | |||
==Date Difference== | |||
<div style="padding: 0.5em"> | |||
Finds the difference in days between two dates. Dates are used in the format yyyy-mm-dd | |||
<lsl>integer dateDiff(string date1, string date2) | |||
{ | |||
list months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; | |||
integer year1 = (integer)llGetSubString(date1, 0, 3); | |||
integer month1 = (integer)llGetSubString(date1, 5, 6); | |||
integer day1 = (integer)llGetSubString(date1, 8, 9); | |||
integer year2 = (integer)llGetSubString(date2, 0, 3); | |||
integer month2 = (integer)llGetSubString(date2, 5, 6); | |||
integer day2 = (integer)llGetSubString(date2, 8, 9); | |||
integer daysDiff; | |||
integer i; | |||
integer yeardays1; | |||
for(i=0; i<month1-1; i++) | |||
yeardays1 += llList2Integer(months, i); | |||
yeardays1 += day1; | |||
integer yeardays2; | |||
for(i=0; i<month2-1; i++) | |||
yeardays2 += llList2Integer(months, i); | |||
yeardays2 += day2; | |||
daysDiff = yeardays2 - yeardays1 + 365*(year2-year1); | |||
return daysDiff; | |||
}</lsl></div></div> | |||
| color picker = <div id="box"> | |||
==Color Picker== | |||
<div style="padding: 0.5em"> | |||
Script that converts hue/sat/lum to red/green/blue based on texture coordinates on a single prim and outputs the vector rgb. | |||
===Prim Setup=== | |||
<lsl>default | |||
{ | |||
state_entry() | |||
{ | |||
llSetPrimitiveParams([ | |||
PRIM_SIZE, <.5,.4,.1>, | |||
PRIM_TYPE, PRIM_TYPE_BOX, PRIM_HOLE_SQUARE, <0,1,0>, 0.0, <0,0,0>, <.8,1,0>, <.02,0,0>, | |||
PRIM_TEXTURE, ALL_SIDES, (key)"5748decc-f629-461c-9a36-a35a221fe21f", <1,1,0>, <0,0,0>, 0.0, | |||
PRIM_TEXTURE, 0, (key)"404e4461-8a22-fbf7-7652-4b81dc7da325", <1,1,0>, <0,0,0>, 0.0, | |||
PRIM_TEXTURE, 2, (key)"01c02d68-dfb0-d907-7397-cba857c61144", <1,1,0>, <0,0,0>, -PI_BY_TWO]); | |||
} | |||
} | |||
</lsl> | |||
===Color Picker=== | |||
<lsl>float hue = 0.0; | |||
float lum = 0.5; | |||
float sat = 1.0; | |||
integer start_face; | |||
//hsl to rgb steps take from http://130.113.54.154/~monger/hsl-rgb.html | |||
vector hsl_to_rbg(float h, float s, float l) | |||
{ | |||
vector rbg; | |||
float temp1; | |||
float temp2; | |||
if(l < .5) | |||
temp2 = l*(1.0+s); | |||
else | |||
temp2 = l+s-l*s; | |||
temp1 = l*2.0-temp2; | |||
float Rtemp3 = h+1.0/3.0; | |||
if(Rtemp3 < 0.0) | |||
Rtemp3 = Rtemp3+1.0; | |||
else if(Rtemp3 > 1.0) | |||
Rtemp3 = Rtemp3-1.0; | |||
float Gtemp3 = h; | |||
if(Gtemp3 < 0.0) | |||
Gtemp3 = Gtemp3+1.0; | |||
else if(Gtemp3 > 1.0) | |||
Gtemp3 = Gtemp3-1.0; | |||
float Btemp3 = h-1.0/3.0; | |||
if(Btemp3 < 0.0) | |||
Btemp3 = Btemp3+1.0; | |||
else if(Btemp3 > 1.0) | |||
Btemp3 = Btemp3-1.0; | |||
if(6.0*Rtemp3 < 1.0) | |||
rbg.x = temp1+(temp2-temp1)*6.0*Rtemp3; | |||
else if(2.0*Rtemp3 < 1.0) | |||
rbg.x = temp2; | |||
else if(3.0*Rtemp3 < 2.0) | |||
rbg.x = temp1+(temp2-temp1)*((2.0/3.0)-Rtemp3)*6.0; | |||
else | |||
rbg.x = temp1; | |||
if(6.0*Gtemp3 < 1.0) | |||
rbg.y = temp1+(temp2-temp1)*6.0*Gtemp3; | |||
else if(2.0*Gtemp3 < 1.0) | |||
rbg.y = temp2; | |||
else if(3.0*Gtemp3 < 2.0) | |||
rbg.y = temp1+(temp2-temp1)*((2.0/3.0)-Gtemp3)*6.0; | |||
else | |||
rbg.y = temp1; | |||
if(6.0*Btemp3 < 1.0) | |||
rbg.z = temp1+(temp2-temp1)*6.0*Btemp3; | |||
else if(2.0*Btemp3 < 1.0) | |||
rbg.z = temp2; | |||
else if(3.0*Btemp3 < 2.0) | |||
rbg.z = temp1+(temp2-temp1)*((2.0/3.0)-Btemp3)*6.0; | |||
else | |||
rbg.z = temp1; | |||
return rbg; | |||
} | |||
default | |||
{ | |||
touch_start(integer total_number) | |||
{ | |||
start_face = llDetectedTouchFace(0); | |||
if(start_face == 4) | |||
llOwnerSay((string)hsl_to_rbg(hue, sat, lum)); | |||
} | |||
touch(integer total_number) | |||
{ | |||
vector st = llDetectedTouchST(0); | |||
integer face = llDetectedTouchFace(0); | |||
if(start_face != face) return; | |||
if(face == 0) | |||
{ | |||
sat = st.y; | |||
hue = st.x; | |||
llSetColor(hsl_to_rbg(hue, sat, lum), 4); | |||
} | |||
else if(face == 2) | |||
{ | |||
lum = st.x; | |||
llSetColor(hsl_to_rbg(hue, sat, lum), 4); | |||
} | |||
} | |||
} | |||
</lsl></div></div> | |||
| uv button maker = <div id="box"> | |||
==UV Button Maker== | |||
<div style="padding: 0.5em"> | |||
The following scripts are tools to making your own uv button setup for a texture in a hud or for any multi-button texture. First script is for getting the button coordinates which are used in the second script (detected_button) which returns the button number pressed. | |||
===Get Coordinates=== | |||
<lsl>integer start_face; | |||
vector start_uv; | |||
default | |||
{ | |||
touch_start(integer s) | |||
{ | |||
start_face = llDetectedTouchFace(0); | |||
start_uv = llDetectedTouchUV(0); | |||
start_uv.x += -(integer)start_uv.x - (start_uv.x < 0); | |||
start_uv.y += -(integer)start_uv.y - (start_uv.y < 0); | |||
} | |||
touch(integer s) | |||
{ | |||
if(llDetectedTouchFace(0) == start_face) | |||
{ | |||
vector new_uv = llDetectedTouchUV(0); | |||
new_uv.x -= (integer)new_uv.x - (new_uv.x < 0); | |||
new_uv.y -= (integer)new_uv.y - (new_uv.y < 0); | |||
llSetText((string)start_uv+" | "+(string)new_uv, <1,1,1>, 1); | |||
} | |||
} | |||
touch_end(integer s) | |||
{ | |||
if(llDetectedTouchFace(0) == start_face) | |||
{ | |||
vector end_uv = llDetectedTouchUV(0); | |||
end_uv.x -= (integer)end_uv.x - (end_uv.x < 0); | |||
end_uv.y -= (integer)end_uv.y - (end_uv.y < 0); | |||
llOwnerSay("Button coords: "+(string)start_uv+" | "+(string)end_uv, <1,1,1>, 1); | |||
} | |||
} | |||
}</lsl> | }</lsl> | ||
===detected_button()=== | |||
<lsl>//Example coords | |||
list button_coords = [ | |||
<0.617, 0.050, 0.000>, <0.823, 0.141, 0.000>, //Button 0 | |||
<0.399, 0.535, 0.000>, <0.972, 0.764, 0.000>, //Button 1 | |||
<0.152, 0.864, 0.000>, <0.796, 0.940, 0.000>, //Button 2 | |||
<0.047, 0.529, 0.000>, <0.376, 0.576, 0.000> //Button 3 | |||
]; | |||
integer within_square(vector test, vector a, vector b) | |||
{ | |||
vector BLC; | |||
vector TRC; | |||
if(a.x > b.x) | |||
{ | |||
TRC.x = a.x; | |||
BLC.x = b.x; | |||
} | |||
else | |||
{ | |||
TRC.x = b.x; | |||
BLC.x = a.x; | |||
} | |||
if(a.y > b.y) | |||
{ | |||
TRC.y = a.y; | |||
BLC.y = b.y; | |||
} | |||
else | |||
{ | |||
TRC.y = b.y; | |||
BLC.y = a.y; | |||
} | |||
if(test.x <= TRC.x && test.x >= BLC.x && test.y >= BLC.y && test.y <= TRC.y) | |||
return TRUE; | |||
else | |||
return FALSE; | |||
} | |||
integer detected_buttonUV(vector uv) | |||
{ | |||
uv.x -= (integer)uv.x - (uv.x < 0); | |||
uv.y -= (integer)uv.y - (uv.y < 0); | |||
integer i; | |||
for(i=0; i<llGetListLength(button_coords); i=i+2) | |||
{ | |||
if(within_square(uv, llList2Vector(button_coords, i), llList2Vector(button_coords, i+1))) | |||
return i/2; | |||
} | |||
return -1; | |||
} | |||
default | |||
{ | |||
touch_start(integer total_number) | |||
{ | |||
llOwnerSay("Button "+(string)detected_buttonUV(llDetectedTouchUV(0))); | |||
} | |||
}</lsl></div></div> | |||
| pass code dialog = <div id="box"> | |||
==Pass Code Dialog== | |||
<div style="padding: 0.5em"> | |||
A simple script that will receive number inputs through menu like a number pad, and will grant access when submission matches pass code | |||
<lsl>string pass_code = "1234"; | |||
string code_input; | |||
integer dialog_ch; | |||
integer dialog_handle; | |||
key dialog_user; | |||
list rebutton(list src) | |||
{ | |||
list temp; | |||
temp += llList2List(src, -3, -1); | |||
temp += llList2List(src, -6, -4); | |||
temp += llList2List(src, -9, -7); | |||
temp += llList2List(src, -12, -10); | |||
return temp; | |||
} | |||
integer rand(integer max) | |||
{ | |||
return llAbs((integer)("0x"+llGetSubString(llMD5String((string)llFrand(10000), 0), 0, 7)))%max; | |||
} | |||
num_pad() | |||
{ | |||
llSetTimerEvent(10); | |||
list buttons = [ | |||
"1", "2", "3", | |||
"4", "5", "6", | |||
"7", "8", "9", | |||
"Submit", "0", "Cancel"]; | |||
llDialog(dialog_user, "Enter pass code.\n\n"+code_input, rebutton(buttons), dialog_ch); | |||
} | |||
new_channel() | |||
{ | |||
dialog_ch = rand(1 << 30); | |||
llListenRemove(dialog_handle); | |||
dialog_handle = llListen(dialog_ch, "", "", ""); | |||
} | |||
new_user(key user) | |||
{ | |||
dialog_user = user; | |||
code_input = ""; | |||
new_channel(); | |||
num_pad(); | |||
} | |||
clear_user() | |||
{ | |||
llSetTimerEvent(0); | |||
dialog_user = NULL_KEY; | |||
llListenRemove(dialog_handle); | |||
dialog_handle = 0; | |||
} | |||
default | |||
{ | |||
touch_start(integer s) | |||
{ | |||
if(dialog_user); | |||
else | |||
new_user(llDetectedKey(0)); | |||
} | |||
timer() | |||
{ | |||
clear_user(); | |||
} | |||
listen(integer channle, string name, key id, string message) | |||
{ | |||
if(id != dialog_user) return; | |||
if((integer)message || message == "0") | |||
{ | |||
code_input += message; | |||
num_pad(); | |||
} | |||
if(message == "Submit") | |||
{ | |||
if(code_input == pass_code) | |||
llSay(0, "Access granted."); | |||
else | |||
llSay(0, "Access denied."); | |||
clear_user(); | |||
} | |||
if(message == "Cancel") | |||
clear_user(); | |||
} | |||
}</lsl></div></div> | |||
| Script not found: {{{1}}} | | Script not found: {{{1}}} | ||
}} | }} | ||
</includeonly><noinclude> | |||
==Usage== | |||
<nowiki>{{Darwin's Scripts|script name}}</nowiki> | |||
Returns lsl scripts in a div box with descriptions | |||
==Contents:== | |||
* find screen width (1) | |||
* color picker (2) | |||
* date difference (1) | |||
* uv button maker (2) | |||
* pass code dialog (1) | |||
==Templates List== | |||
[https://wiki.secondlife.com/w/index.php?title=Special%3APrefixIndex&from=&namespace=10 List of all wiki templates] | |||
</noinclude> | </noinclude> |
Latest revision as of 02:29, 6 October 2009
Usage
{{Darwin's Scripts|script name}}
Returns lsl scripts in a div box with descriptions
Contents:
- find screen width (1)
- color picker (2)
- date difference (1)
- uv button maker (2)
- pass code dialog (1)