IvyTechEngineer Posted November 23, 2021 Share Posted November 23, 2021 I have a six sided dice that I would like to add a script to it. I purchased a script from the Marketplace, Dice Roll Script Version 1.01, which is pretty good but I would like to better understand how the script works. Thanks Link to comment Share on other sites More sharing options...
Fritigern Gothly Posted November 23, 2021 Share Posted November 23, 2021 36 minutes ago, IvyTechEngineer said: I have a six sided dice that I would like to add a script to it. I purchased a script from the Marketplace, Dice Roll Script Version 1.01, which is pretty good but I would like to better understand how the script works. Thanks You PAID for a dice roll script? From the old SL forum archives (slightly modified to be a 6-sided die instead of a 50-sides one): default { touch_start(integer n) { llSay(0, llDetectedName(0) + " rolls " + (string)llCeil(llFrand(6.0))); } } Link to comment Share on other sites More sharing options...
Rolig Loon Posted November 23, 2021 Share Posted November 23, 2021 I suspect that the script involves more than just creating a random number to report in chat. There have been some interesting scripts for rolling dice posted in this forum in the past. If you have specific questions about that script (not just "how does this script work?"), you are welcome to post them here. Remember, though, that since you paid for someone else's script, you cannot post the whole thing here without violating the creator's IP rights and potentially undercutting his MP sales. Link to comment Share on other sites More sharing options...
Quistess Alpha Posted November 23, 2021 Share Posted November 23, 2021 (edited) There are some Rollable dice in the Secondlife Library if I remember correctly. Indeed, library-> objects. and here is the script it contains, as written by alberto linden (by a linden and publicly available, so I'd gather that it's freely licensed) // // Dice // // Flips when you click on it. Click longer for higher flip. // Drag physically during click for more amusing flight. // float HOP_SCALE = 1.5; float TORQUE_SCALE = 0.05; vector last_color; vector HELD_COLOR = <1, 0.75, 0.75>; integer NUM_DICE = 1; // Number of additional dice to throw: // 1 = craps // 4 = Yahtzee, etc! integer HELD = FALSE; vector impulse; vector torque; integer CHANNEL = 1263; default { state_entry() { llCollisionSound("dice_drop", 0.5); // Override normal collision sounds } touch_start(integer total_number) { HELD = TRUE; last_color = llGetColor(0); llSetColor(HELD_COLOR, ALL_SIDES); llSay(CHANNEL, "die"); llLoopSound("dice_shake", 1.5); } attach(key avatar) { // // If this gets called it means someone has attached this // object to their body rather than creating in-world. // Ask for permission to detach, then do so with a message // if (avatar != NULL_KEY) { llRequestPermissions(llGetOwner(), PERMISSION_ATTACH); } } run_time_permissions(integer perm) { // // This means we are now OK to detach from avatar, so send message and do so // llWhisper(0, "Drop me on the ground, don't attach me to your body."); llDetachFromAvatar(); } touch_end(integer total_number) { HELD = FALSE; llLoopSound("dice_shake", 0.0); llTargetOmega(<1,1,1>, 0.0, 0.0); llTriggerSound("dice_drop", 1.0); llSetColor(last_color, ALL_SIDES); impulse = < 0, 0, HOP_SCALE>; llApplyImpulse(impulse, FALSE); torque = < llFrand(TORQUE_SCALE), llFrand(TORQUE_SCALE), llFrand(TORQUE_SCALE)>; llApplyRotationalImpulse(torque, TRUE); vector pos = llGetPos(); pos.z += 0.50; pos.x += 0.30; integer i; for (i=0; i<NUM_DICE; i++) { llRezObject("Slave Die",pos,<0,0,1>, <0,0,0,1>, 0); pos.z += 0.50; } } } and the script in the slave-die, which makes how it works even more clear: // // Slave Dice // // Appy rotation on rez to flip nicely. // // float HOP_SCALE = 0.5; float TORQUE_SCALE = 0.05; vector HELD_COLOR = <1, 0.75, 0.75>; vector NORMAL_COLOR = <1, 1, 1>; integer HELD = FALSE; vector impulse; vector torque; integer CHANNEL = 1263; default { state_entry() { llListen(CHANNEL, "", "", ""); llCollisionSound("dice_drop", 0.25); } on_rez(integer param) { torque = < llFrand(TORQUE_SCALE), llFrand(TORQUE_SCALE), llFrand(TORQUE_SCALE)>; llApplyRotationalImpulse(torque, TRUE); } touch_start(integer total_number) { llDie(); } listen(integer channel, string name, key id, string message) { llDie(); } } (Yes I know there are unused variables, but it's not my script so I'm not changing it) Despite what it says in the comments, I don't see any part that changes the height based on the time held, but that would be easy to add. Edited November 23, 2021 by Quistess Alpha 1 Link to comment Share on other sites More sharing options...
IvyTechEngineer Posted November 23, 2021 Author Share Posted November 23, 2021 3 hours ago, Rolig Loon said: I suspect that the script involves more than just creating a random number to report in chat. There have been some interesting scripts for rolling dice posted in this forum in the past. If you have specific questions about that script (not just "how does this script work?"), you are welcome to post them here. Remember, though, that since you paid for someone else's script, you cannot post the whole thing here without violating the creator's IP rights and potentially undercutting his MP sales. I understand. I am just looking for a simple script for a six side dice and I thought that someone might have an easy script to use that was open source. I know that Jeff Heaton has shared scripts in the past and I have found a few places that post scripts with the caveat that you include the script header. 1 Link to comment Share on other sites More sharing options...
IvyTechEngineer Posted November 23, 2021 Author Share Posted November 23, 2021 3 hours ago, Quistess Alpha said: There are some Rollable dice in the Secondlife Library if I remember correctly. Indeed, library-> objects. and here is the script it contains, as written by alberto linden (by a linden and publicly available, so I'd gather that it's freely licensed) // // Dice // // Flips when you click on it. Click longer for higher flip. // Drag physically during click for more amusing flight. // float HOP_SCALE = 1.5; float TORQUE_SCALE = 0.05; vector last_color; vector HELD_COLOR = <1, 0.75, 0.75>; integer NUM_DICE = 1; // Number of additional dice to throw: // 1 = craps // 4 = Yahtzee, etc! integer HELD = FALSE; vector impulse; vector torque; integer CHANNEL = 1263; default { state_entry() { llCollisionSound("dice_drop", 0.5); // Override normal collision sounds } touch_start(integer total_number) { HELD = TRUE; last_color = llGetColor(0); llSetColor(HELD_COLOR, ALL_SIDES); llSay(CHANNEL, "die"); llLoopSound("dice_shake", 1.5); } attach(key avatar) { // // If this gets called it means someone has attached this // object to their body rather than creating in-world. // Ask for permission to detach, then do so with a message // if (avatar != NULL_KEY) { llRequestPermissions(llGetOwner(), PERMISSION_ATTACH); } } run_time_permissions(integer perm) { // // This means we are now OK to detach from avatar, so send message and do so // llWhisper(0, "Drop me on the ground, don't attach me to your body."); llDetachFromAvatar(); } touch_end(integer total_number) { HELD = FALSE; llLoopSound("dice_shake", 0.0); llTargetOmega(<1,1,1>, 0.0, 0.0); llTriggerSound("dice_drop", 1.0); llSetColor(last_color, ALL_SIDES); impulse = < 0, 0, HOP_SCALE>; llApplyImpulse(impulse, FALSE); torque = < llFrand(TORQUE_SCALE), llFrand(TORQUE_SCALE), llFrand(TORQUE_SCALE)>; llApplyRotationalImpulse(torque, TRUE); vector pos = llGetPos(); pos.z += 0.50; pos.x += 0.30; integer i; for (i=0; i<NUM_DICE; i++) { llRezObject("Slave Die",pos,<0,0,1>, <0,0,0,1>, 0); pos.z += 0.50; } } } and the script in the slave-die, which makes how it works even more clear: // // Slave Dice // // Appy rotation on rez to flip nicely. // // float HOP_SCALE = 0.5; float TORQUE_SCALE = 0.05; vector HELD_COLOR = <1, 0.75, 0.75>; vector NORMAL_COLOR = <1, 1, 1>; integer HELD = FALSE; vector impulse; vector torque; integer CHANNEL = 1263; default { state_entry() { llListen(CHANNEL, "", "", ""); llCollisionSound("dice_drop", 0.25); } on_rez(integer param) { torque = < llFrand(TORQUE_SCALE), llFrand(TORQUE_SCALE), llFrand(TORQUE_SCALE)>; llApplyRotationalImpulse(torque, TRUE); } touch_start(integer total_number) { llDie(); } listen(integer channel, string name, key id, string message) { llDie(); } } (Yes I know there are unused variables, but it's not my script so I'm not changing it) Despite what it says in the comments, I don't see any part that changes the height based on the time held, but that would be easy to add. Thank you for find this script. I will check it out... Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now