Randomized Notecard Vendor
|
|
Gen Giacomin
Registered User
Join date: 21 Aug 2006
Posts: 7
|
08-30-2006 03:19
Hi all, I am trying to create a vendor that sells a random notecard. For example: "Get a new recipe every time", or "What position you should use tonight". Those aren't actually what I want to do with it, but it should give you an idea.
I think I have parts of a script... I am either missing one picky little thing or I am totally off base. I'm not sure. At this point I should point out that I haven't done any scripting/programming for 22 years. Any help would be appreciated!
Thanks, Gen
This is what I have, so far:
string FLOAT_TEXT= "Hey look! Float Text!";
integer gCorrectAmount = 15; // this defines the correct price
default{
state_entry() { llSetText(FLOAT_TEXT, <0.3, 0.3, 0.9>, 1.0); }
money(key id, integer amount) { string Item = llGetInventoryName(INVENTORY_NOTECARD,(integer) llFrand(llGetInventoryNumber(INVENTORY_NOTECARD)));
key Dkey = llDetectedKey(0); // Key Of Who Touched Me llSetPayPrice(PAY_HIDE, [15, PAY_HIDE, PAY_HIDE, PAY_HIDE]); //Restrict to one price if (amount == gCorrectAmount) // has the user paid the correct amount llGiveInventory(Dkey, Item); // Give Item To Person }}
|
|
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
|
08-30-2006 05:00
Sorry, no test. I'm not sure if it works well. string FLOAT_TEXT= "Hey look! Float Text!"; integer gCorrectAmount = 15;
list NotecardList;
ListUp() { NotecardList = []; integer NotecardNum = llGetInventoryNumber(INVENTORY_NOTECARD); integer i; for(i = 0; i < NotecardNum; i++) { NotecardList += llGetInventoryName(INVENTORY_NOTECARD, i); } }
string Randomize() { list RandomizedList = llListRandomize(NotecardList, 1); string NotecardName = llList2String(RandomizedList, 0); return NotecardName; }
default { state_entry() { llSetText(FLOAT_TEXT, <0.3, 0.3, 0.9>, 1.0); llRequestPermissions(llGetOwner(),PERMISSION_DEBIT); ListUp(); } on_rez(integer reset) { llResetScript(); } changed(integer change) { if(change & CHANGED_INVENTORY) { ListUp(); } } money(key id, integer amount) { if(amount == gCorrectAmount) { string Item = Randomize(); llGiveInventory(id, Item); } else { llSay(0, "You paid wrong."); llGiveMoney(id, amount); } } }
_____________________
 Seagel Neville 
|
|
Ginge Reymont
Registered User
Join date: 10 Oct 2005
Posts: 190
|
08-30-2006 05:31
string FLOAT_TEXT= "Hey look! Float Text!"; integer gCorrectAmount = 15;
list NotecardList;
ListUp() { NotecardList = []; integer NotecardNum = llGetInventoryNumber(INVENTORY_NOTECARD); integer i; for(i = 0; i < NotecardNum; i++) { NotecardList += llGetInventoryName(INVENTORY_NOTECARD, i); } }
string Randomize() { list RandomizedList = llListRandomize(NotecardList, 1); string NotecardName = llList2String(RandomizedList, 0); return NotecardName; } state on { state_entry() { llRequestPermissions(llGetOwner(),PERMISSION_DEBIT ); } run_time_permissions(integer perm) { if (perm & PERMISSION_DEBIT) { state default; } else { llSay(0,"You need to grant debit permission to run this object."); } }
default { state_entry() { llSetText(FLOAT_TEXT, <0.3, 0.3, 0.9>, 1.0); ListUp(); } on_rez(integer reset) { llResetScript(); } changed(integer change) { if(change & CHANGED_INVENTORY) { ListUp(); } } money(key id, integer amount) { if(amount == gCorrectAmount) { string Item = Randomize(); llGiveInventory(id, Item); } else { llSay(0, "You paid wrong."); llGiveMoney(id, amount); } } }
|
|
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
|
08-30-2006 05:38
Oh, is llRequestPermissions available for acrossing states? I didn't know that.
_____________________
 Seagel Neville 
|
|
Gen Giacomin
Registered User
Join date: 21 Aug 2006
Posts: 7
|
Thanks!
08-30-2006 06:44
Thank you! You guys are fast. I am on my way to bed, but I'll try this out tomorrow. It certainly looks like it makes more sense...
Gen
|
|
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
|
08-30-2006 07:59
I've made sure that my script works. But if you force everybody pay gCorrectAmount linden dollars, you don't have to set llRequestPermissions and can do this. state_entry() { llSetText(FLOAT_TEXT, <0.3, 0.3, 0.9>, 1.0); llSetPayPrice(PAY_HIDE, [gCorrectAmount, PAY_HIDE, PAY_HIDE, PAY_HIDE]); ListUp(); } And everybody won't be able to pay wrong. No need else condition. money(key id, integer amount) { if(amount == gCorrectAmount) { string Item = Randomize(); llGiveInventory(id, Item); } }
_____________________
 Seagel Neville 
|
|
Tenzin Tuque
BodhiSim.org
Join date: 13 Sep 2005
Posts: 81
|
11-07-2006 09:29
hi folks, is there any way of doing this script without a vendor? Just as a touch and give random notecard from inventory? No money, no permissions.
I've been trying to cobble together something like this but I am no scripter and am failing horribly. Any help would be most-appreciated.
thx
_____________________
BodhiSim.org milarepalandtrust.blogspot.com
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
11-07-2006 12:43
From: Tenzin Tuque hi folks, is there any way of doing this script without a vendor? Just as a touch and give random notecard from inventory? No money, no permissions.
I've been trying to cobble together something like this but I am no scripter and am failing horribly. Any help would be most-appreciated.
thx Just replalce the money with a touch default { state_entry() { llSetText(FLOAT_TEXT, <0.3, 0.3, 0.9>, 1.0); ListUp(); } on_rez(integer reset) { llResetScript(); } changed(integer change) { if(change & CHANGED_INVENTORY) { ListUp(); } }
touch_start(integer total_number) { key id = llDetectedKey(0); string Item = Randomize(); llGiveInventory(id, Item); }
}
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
11-07-2006 13:54
From: Seagel Neville I've made sure that my script works. But if you force everybody pay gCorrectAmount linden dollars, you don't have to set llRequestPermissions and can do this. state_entry() { llSetText(FLOAT_TEXT, <0.3, 0.3, 0.9>, 1.0); llSetPayPrice(PAY_HIDE, [gCorrectAmount, PAY_HIDE, PAY_HIDE, PAY_HIDE]); ListUp(); } And everybody won't be able to pay wrong. No need else condition. money(key id, integer amount) { if(amount == gCorrectAmount) { string Item = Randomize(); llGiveInventory(id, Item); } } That's not safe, because if someone figures out an exploit to beat the 'fixed pay price' dialog box, you'll be selling things for 1L. And not too long ago, there was such an exploit, some people discovered it, and some vendor scripts were compromised because they relied on the fixed pay price dialog box and didn't check to see if the correct amount was received. Search the forums, there was at least one long thread about it. All you're saving is a few lines of code, and the owner having to click a button once when the script starts up. It's not worth it, especially when money is involved. Though... your script does check for the correct amount, so I guess you could say it's an anti-hacker script, since if someone does use an exploit, it will take their money and not give them anything in return 
|
|
Tenzin Tuque
BodhiSim.org
Join date: 13 Sep 2005
Posts: 81
|
11-07-2006 15:29
thanks so much, works great! The script is for a random dharma quote machine, you touch it and it delivers pith instructions, at random on Buddhist practice, dharma and history.
Thanks again
_____________________
BodhiSim.org milarepalandtrust.blogspot.com
|