Leander Tyles Posted June 2, 2013 Share Posted June 2, 2013 Hello, can anybody help finish this script......its a gift card system for my rentbox so works a little differently than what you may find in a shopits just missing 4 features - help with any of them atall will be appreciated 1) make sure this giftcard can only be used once, then delete itself.2) how to use the card? well im wearing it already so maybe touch for a menu or chat-command to confirm?3) how do i check if im in a script enabled area? if people use the giftcard in a no scriptzone it`ll be used and useless4) check for webserver responce to ensure its online? otherwise giftcard might get used and become useless again string USED = FALSE; integer TIME_GIFT = 1; // number of weeks to give away integer RENT_RATE = 50; // price you usually charge for a single week string NOTE = "INFO"; string UPDATE_URL = "http://mywebhost.com"; string OLD_RENT_MSG = "[LEASE EXTENDED] "; string NEW_RENT_MSG = "[LEASE STARTED]"; string RENT_PAID_MSG = " Time left: "; string OWNER_OLD_RENT_MSG = " has renewed thier rental. Time left: "; string OWNER_NEW_RENT_MSG = " has rented a skybox thier rent. Time left: "; list DESIGN_DLG_BTNS = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40" ]; key checkReqId; key updateReqId; key addReqId; key removeReqId; key deleteReqId; key designReqId; key avatarKey; key creatorThisPrim; string ts2Days(integer unixExpiration) { integer seconds = unixExpiration - llGetUnixTime(); integer weeks = seconds / 604800; integer days = seconds / 86400; integer hours = (seconds % 86400) / 3600; integer mins = (seconds % 3600) / 60; string time = ""; if (weeks) { time += (string)weeks + " week"; if (~-weeks) time += "s"; time += " "; } if (days) { time += (string)days + " day"; if (~-days) time += "s"; time += " "; } if (hours) { time += (string)hours + " hour"; if (~-hours) time += "s"; time += " "; } if (mins) { time += (string)mins + " min"; if (~-mins) time += "s"; } return time; } resetReqId(key respId) { if (respId == checkReqId) { checkReqId = NULL_KEY; } else if (respId == updateReqId) updateReqId = NULL_KEY; else if (respId == addReqId) addReqId = NULL_KEY; else if (respId == removeReqId) removeReqId = NULL_KEY; else if (respId == deleteReqId) deleteReqId = NULL_KEY; } default { state_entry() { llRequestPermissions( llGetOwner(), PERMISSION_ATTACH ); creatorThisPrim = llGetCreator(); // doesnt rename item in inventory llSetObjectName((string)TIME_GIFT + " WEEK Gift Card - (wear me)"); llSetText("Gift Card\n" + (string)TIME_GIFT + " weeks vacation", <1.0, 1.0, 1.0>, 1.0); llSetObjectDesc("Card Value: L$" + (string)(TIME_GIFT * RENT_RATE)); } changed(integer change) { if (change & CHANGED_OWNER) llResetScript(); } on_rez(integer rez) { if (!llGetAttached() ) //reset the script if it's not attached. llResetScript(); } attach(key id) { if (id) llSetObjectName((string)TIME_GIFT + " WK HH Gift Card "); else llSetObjectName((string)TIME_GIFT + " WK HH Gift Card - (wear me)"); } // when worn and activated touch(integer num_detected) { avatarKey = llDetectedKey(0); integer weeks = TIME_GIFT; updateReqId = llHTTPRequest(UPDATE_URL + "?uuid=" + (string)avatarKey + "&name=" + llEscapeURL(llKey2Name(avatarKey)) + "&weeks=" + (string)weeks, [], ""); } http_response(key respId, integer status, list meta, string body) { if (status != 200) { resetReqId(respId); return; } list bodyCSV = llCSV2List(body); key uuid = llList2Key(bodyCSV, 0); string name = llList2String(bodyCSV, 1); key partneruuid = llList2Key(bodyCSV, 2); string partner = llList2String(bodyCSV, 3); string expiration = llList2String(bodyCSV, 4); integer unixExpiration = llList2Integer(bodyCSV, 5); string design = llList2String(bodyCSV, 6); integer idx; string msg; if (respId == updateReqId) { string time = llList2String(llCSV2List(ts2Days(unixExpiration)), 0); if (design == "NEW") // A NEW TENANT { msg = NEW_RENT_MSG + " "; llPlaySound("sound",1.0); integer randIdx = (integer)llFrand(21.0); string randomDesign = llList2String(DESIGN_DLG_BTNS, randIdx); llHTTPRequest(UPDATE_URL + "?uuid=" + (string)uuid + "&name=" + llEscapeURL(llKey2Name(uuid)) + "&design=" + randomDesign, [], ""); if (llGetInventoryType(NOTE) == INVENTORY_NOTECARD) llGiveInventory(uuid, NOTE); llSay(0, msg + RENT_PAID_MSG + time); llInstantMessage(uuid,"You have been assigned '" +randomDesign+ " Pad' but you can change it anytime."); if (uuid != creatorThisPrim) // notify owner of gift cards being used? llInstantMessage(uuid, msg + name + OWNER_NEW_RENT_MSG + time); } else // ALREADY A TENANT SO LEASE EXTENDED { msg = OLD_RENT_MSG; string userMsg = msg + RENT_PAID_MSG + time; string ownerMsg = msg + name + OWNER_OLD_RENT_MSG + time; if (partner != "NONE") llSay(0, userMsg); llInstantMessage(partneruuid, (userMsg)); // notify owner of gift cards being used? if (uuid != creatorThisPrim) llInstantMessage(creatorThisPrim, ownerMsg); } } } } Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted June 2, 2013 Share Posted June 2, 2013 It's a bit difficult to give you advice without knowing how you exactly want the gift card thinggie to work. But you seem to use an external databse. So, as for question one: Keep track of to whom you've given a gift card and who has used it. Since you most likely make the cards no copy, the uuid should be a good identifier. Simply check the database on attaching the gift card. Question 2: Simply define how you want it to work. Question 3: You can't. At least not in a script that is in the area in question - because you'd need a script, which wouldn't run in a no-script area. Question 4: Make a request and see if you get a response with status 200 Link to comment Share on other sites More sharing options...
Leander Tyles Posted June 2, 2013 Author Share Posted June 2, 2013 thanks for the responce, your answers opened up my eyes especially #3 anyway i pretty much done everything i wanted to do now. yes i do use an external database.. i cant keep track of whos who serverside because i barely know lsl let alone php but i managed to make this giftcard system by editing my rentbox,the giftcard itself pratically functions the sameway the rentbox does so its quite dangerous if abused. hopefully in future i can keep track of sales in sl kinda like hippotech payment history menu does - just out of interest not a security measure anyway back on track i have a few questions, problems and concerns: 1) is thier anyway to use lldie if im wearing the giftcard? 2) i checked if status == 200 but then it never works, it will always say llSay(0,"trouble communicating with webserver...\nplease try using the gift-card again later or contact the owner " + llKey2Name(llGetCreator())); return; if i remove that line then it works a treat i dont know what the problem is so i cant fix it 3) im concerned about the USED variable..... i just want to make sure people cant reset my script to use the giftcard again because its very dangerous to my buissness if it wont lldie(); 4) always wondered how i post code on forums so it appears formatted like lsl UPDATED CODE: integer TIME_GIFT = 1; // number of weeks to give awayinteger RENT_RATE = 20; // price you usually charge for a single weekstring USED;string DELETESELF = "TRUE";string NOTE = "INFO";string UPDATE_URL = "http://mywebhost.com";string OLD_RENT_MSG = "[LEASE EXTENDED] ";string NEW_RENT_MSG = "[LEASE STARTED]";string RENT_PAID_MSG = " Time left: ";string OWNER_OLD_RENT_MSG = " has renewed thier rental. Time left: ";string OWNER_NEW_RENT_MSG = " has rented a skybox thier rent. Time left: ";list DESIGN_DLG_BTNS = ["Studio","Noir","Gala","Circle","Shindig","Breeze","Tropical","Stable","Fab","Posh","Bash","Suttle","Zephyr","Chill","Sunset","Beach","Cross","Dip","Escape","Loft","Sweet","Garret","Turn","Party","Small","Modern","Homely","Smart","Marble","Silver","Alley","Grunge","Relax","Submarine","Cardboard","NYC1","NYC2","Escort","Triangle","Realistic"];key checkReqId;key updateReqId;key addReqId;key removeReqId;key deleteReqId;key designReqId;key avatarKey;key creatorThisPrim;string ts2Days(integer unixExpiration){ integer seconds = unixExpiration - llGetUnixTime(); integer weeks = seconds / 604800; integer days = seconds / 86400; integer hours = (seconds % 86400) / 3600; integer mins = (seconds % 3600) / 60; string time = ""; if (weeks) { time += (string)weeks + " week"; if (~-weeks) time += "s"; time += " "; } if (days) { time += (string)days + " day"; if (~-days) time += "s"; time += " "; } if (hours) { time += (string)hours + " hour"; if (~-hours) time += "s"; time += " "; } if (mins) { time += (string)mins + " min"; if (~-mins) time += "s"; } return time;}resetReqId(key respId){ if (respId == checkReqId) { checkReqId = NULL_KEY; } else if (respId == updateReqId) updateReqId = NULL_KEY; else if (respId == addReqId) addReqId = NULL_KEY; else if (respId == removeReqId) removeReqId = NULL_KEY; else if (respId == deleteReqId) deleteReqId = NULL_KEY;}default{ state_entry() { USED = "FALSE"; llRequestPermissions( llGetOwner(), PERMISSION_ATTACH ); creatorThisPrim = llGetCreator(); // doesnt rename item in inventory llSetObjectName((string)TIME_GIFT + " WEEK Gift Card - (wear me)"); llSetText("\n" + (string)TIME_GIFT + " weeks vacation", <1.0, 1.0, 1.0>, 1.0); llSetObjectDesc("Card Value: L$" + (string)(TIME_GIFT * RENT_RATE)); } changed(integer change) { if (change & CHANGED_OWNER) llResetScript(); } on_rez(integer rez) { if (!llGetAttached() ) //reset the script if it's not attached. llResetScript(); } attach(key id) { if (id != NULL_KEY && USED == "TRUE") { // doesnt rename inventory object so kinda pointless llSetObjectName((string)TIME_GIFT + " WK HH Gift Card (USED)"); llSetObjectDesc("may aswell delete this object now"); } if (id != NULL_KEY && USED == "FALSE") llSetObjectName((string)TIME_GIFT + " WK HH Gift Card"); // do it in state entry anyway llSetObjectDesc("Card Value: L$" + (string)(TIME_GIFT * RENT_RATE)); if (llGetInventoryType(NOTE) == INVENTORY_NOTECARD) llGiveInventory(llDetectedKey(0), NOTE); else llSetObjectName((string)TIME_GIFT + " WK HH Gift Card - (wear me)"); } // when worn and activated touch(integer num_detected) { if (llDetectedKey(0) != llGetOwner()) { llOwnerSay(llDetectedName(0) + " touched your giftcard."); llSay(0,llKey2Name(llGetOwner()) + " has a giftcard for highrise homes."); llGiveInventory(llDetectedKey(0),llGetInventoryName(INVENTORY_LANDMARK, 0)); } if (llDetectedKey(0) == llGetOwner() && USED == "TRUE") { llSay(0,"You have already claimed your free Gift"); } if (llDetectedKey(0) == llGetOwner() && USED != "TRUE") { avatarKey = llDetectedKey(0); integer weeks = TIME_GIFT; updateReqId = llHTTPRequest(UPDATE_URL + "?uuid=" + (string)avatarKey + "&name=" + llEscapeURL(llKey2Name(avatarKey)) + "&weeks=" + (string)weeks, [], ""); }} http_response(key respId, integer status, list meta, string body) { if (status == 200) { // Could set used to false but may cause unnecasery problems. llSay(0,"trouble communicating with webserver...\nplease try using the gift-card again later or contact the owner " + llKey2Name(llGetCreator())); return; } if (status != 200) { resetReqId(respId); return; } list bodyCSV = llCSV2List(body); key uuid = llList2Key(bodyCSV, 0); string name = llList2String(bodyCSV, 1); key partneruuid = llList2Key(bodyCSV, 2); string partner = llList2String(bodyCSV, 3); string expiration = llList2String(bodyCSV, 4); integer unixExpiration = llList2Integer(bodyCSV, 5); string design = llList2String(bodyCSV, 6); integer idx; string msg; if (respId == updateReqId) { string time = llList2String(llCSV2List(ts2Days(unixExpiration)), 0); if (design == "NEW") // A NEW TENANT { msg = NEW_RENT_MSG + " "; llPlaySound("sound",1.0); integer randIdx = (integer)llFrand(21.0); string randomDesign = llList2String(DESIGN_DLG_BTNS, randIdx); llHTTPRequest(UPDATE_URL + "?uuid=" + (string)uuid + "&name=" + llEscapeURL(llKey2Name(uuid)) + "&design=" + randomDesign, [], ""); if (llGetInventoryType(NOTE) == INVENTORY_NOTECARD) llGiveInventory(uuid, NOTE); llSay(0, msg + RENT_PAID_MSG + time); llInstantMessage(uuid,"You have been assigned '" +randomDesign+ " Pad' but you can change it anytime."); if (uuid != creatorThisPrim) // notify owner of gift cards being used? llInstantMessage(uuid, msg + name + OWNER_NEW_RENT_MSG + time); } else // ALREADY A TENANT SO LEASE EXTENDED { msg = OLD_RENT_MSG; string userMsg = msg + RENT_PAID_MSG + time; string ownerMsg = msg + name + OWNER_OLD_RENT_MSG + time; if (partner != "NONE") llSay(0, userMsg); llInstantMessage(partneruuid, (userMsg)); // notify owner of gift cards being used? if (uuid != creatorThisPrim) llInstantMessage(creatorThisPrim, ownerMsg); } // got a responce so USED = "TRUE"; llSetText("\n" + (string)TIME_GIFT + " weeks vacation (USED)", <1.0, 1.0, 1.0>,1.0); llSetObjectName((string)TIME_GIFT + " WK HH Gift Card (USED)"); llSetObjectDesc("may aswell delete this object now"); llOwnerSay("Here's a LM to the office incase you dont know where it is, please accept"); llGiveInventory(uuid,llGetInventoryName(INVENTORY_LANDMARK, 0)); llSleep(3.0); if (DELETESELF == "TRUE") { llDie(); } // doesnt work if worn. } }} please scroll up to help with current problems thank you Link to comment Share on other sites More sharing options...
Leander Tyles Posted June 2, 2013 Author Share Posted June 2, 2013 i beleive i could do something like this float WEB_TIMEOUT = 30.0; then initiate a timer when i do a llHTTPRequest llSetTimerEvent(WEB_TIMEOUT); then in the http_responce if infomation is recieved end the timer otherwise timer() { llSay(0,"trouble communicating with webserver...\nplease try using the gift-card again later or contact the owner " + llKey2Name(llGetCreator())); return; } i havent tried it yet tho and im open to any other ideas cuz i would prefer the checking if status == 200 way AH I THINK I GOT IT NOW, 200 IS GOOD != 200 IS A BAD THING Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted June 3, 2013 Share Posted June 3, 2013 You can't use llDie on an atachment Your status == 200 should be just the other way round - if the status is 200, everything is fine save the 'used' flag in the database - this way you can make sure a gift card is used just once look here 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