Automatic payment!
|
|
Null Fargis
Registered User
Join date: 1 Jun 2007
Posts: 5
|
02-25-2009 15:57
Hi there, I'm quite new to LSL but not new to programming. Have a lot of experience in Java and PHP currently. So far I've done investigating of my own and found out how to get second life to return values from a web page. The PHP script that I query returns the result of people who need to be paid, and the amount to paid. When I execute the PHP command it comes out as: Firstuser1Seconduser2 First/Seconduser being the username of the person who needs to be paid, and 1/2 being the amount that needs to be paid out. My question is, how can LSL go about parsing this data so that it will pay the appropriate user, the appropriate amount of lindens? I took a quick look at the givemoney function, but still unsure as to how I would go about taking the raw text data to give the money to specific users. If I need to create an array, or something similar that's fine as I learn quick in programming languages, and LSL doesn't seem to be a far throw from any others out there. Thank you all for your time!
Got the script to work 100% to my needs, thank you to all who responded.
|
|
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
|
02-25-2009 16:18
You need to parse the message (echo from the php response) with: llParseString2List( string src, list separators, list spacers ); and string llList2String( list src, integer index ); from the wiki: http://wiki.secondlife.com/wiki/LlParseString2Listhttp://wiki.secondlife.com/wiki/LlList2Stringthe wiki is your friend  !! Also take a look on this post on my comment: /54/0d/308221/1.html
|
|
Null Fargis
Registered User
Join date: 1 Jun 2007
Posts: 5
|
02-25-2009 19:52
Thanks a lot for the quick response Papalopulus, it helped me a ton on getting this started, and considering this the first day I've worked with LSL I consider myself doing not bad hehe. Okay I've been working away at this, calling to methods in LSL is...kind of weird haha. This is what I have so far: key requestid; default { touch_start(integer num) { llRequestPermissions(llGetOwner(), PERMISSION_DEBIT ); requestid = llHTTPRequest("url", [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], "parameter1=hello¶meter2=world"  ; } http_response(key request_id, integer status, list metadata, string body) { if (request_id == requestid) { string fname; string lname; string amount; string my_string = body; list my_list = llParseString2List(my_string,[" "],["."]); integer i = 0; integer end = llGetListLength(my_list); for (; i<end; ++i) { fname = llList2String(my_list,i); i++; lname = llList2String(my_list,i); i++; amount = llList2String(my_list,i); llOwnerSay(" First name is: " + fname + " Last name is: " + lname + " Amount to pay is: " + amount); } } } } So far this has no problem spitting out the first name, last name, and amount that needs to be paid to the person, but I am having a lot of troubles with paying out. Whenever I try to call to the llGiveMoney function, it fails. As far as I can see it bases it on a key, and not a username...but I looked around and could not find a way to generate a key for someone other then the person clicking on the object. Can someone steer me in the right direction?
|
|
Faust Vollmar
llSetAgentSanity(FALSE);
Join date: 3 Feb 2007
Posts: 87
|
02-25-2009 19:55
There are no internal LL commands for Name2Key, however, there are other ways around it...
How are you collecting names for who needs to be paid? If it's via any scripted method, chances are you can collect their UUID at the same time. Otherwise you could use w-hat... (I can't find the specifics on that offhand atm.)
|
|
Taff Nouvelle
Virtual Business Owners
Join date: 4 Sep 2006
Posts: 216
|
02-25-2009 19:57
look up w-hat name2key on the web, it is a web based name to key database with virtually all avatars registered , except new accounts that have not been found yet. this can be called from LSL.
|
|
Tabliopa Underwood
Registered User
Join date: 6 Aug 2007
Posts: 719
|
02-25-2009 19:59
There isnt any lsl NameToKey function. You have to know the persons key for most things to work in LL. Is a number of ways you can do that. Dont know how you got the peoples names ??? If you collected them in SL then you can gather the persons keys as well and save them out to your datatable and bring them back like you doing here.
what they ^^ said =)
|
|
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
|
02-25-2009 20:26
Im glad to help  From: Null Fargis Thanks a lot for the quick response Papalopulus, it helped me a ton on getting this started, and considering this the first day I've worked with LSL I consider myself doing not bad hehe. Okay I've been working away at this, calling to methods in LSL is...kind of weird haha. This is what I have so far: key requestid; default { touch_start(integer num) { llRequestPermissions(llGetOwner(), PERMISSION_DEBIT ); requestid = llHTTPRequest("url", [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], "parameter1=hello¶meter2=world"  ; } http_response(key request_id, integer status, list metadata, string body) { if (request_id == requestid) { string fname; string lname; string amount; string my_string = body; list my_list = llParseString2List(my_string,[" "],["."]); integer i = 0; integer end = llGetListLength(my_list); for (; i<end; ++i) { fname = llList2String(my_list,i); i++; lname = llList2String(my_list,i); i++; amount = llList2String(my_list,i); llOwnerSay(" First name is: " + fname + " Last name is: " + lname + " Amount to pay is: " + amount); } } } } So far this has no problem spitting out the first name, last name, and amount that needs to be paid to the person, but I am having a lot of troubles with paying out. Whenever I try to call to the llGiveMoney function, it fails. As far as I can see it bases it on a key, and not a username...but I looked around and could not find a way to generate a key for someone other then the person clicking on the object. Can someone steer me in the right direction?
key requestid; key toucher; string toucher_name; default { state_entry() { llRequestPermissions(llGetOwner(), PERMISSION_DEBIT );//its better here because every time the avatar touch the object this will be triger it out and must be set for the owner
} touch_start(integer num) { toucher=llDetectedKey(0); toucher_name=llKey2Name(toucher); requestid = llHTTPRequest("url", [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], "parameter1=hello¶meter2=world"); } run_time_permissions( integer perm )// you need set this to get works { if ( (perm && PERMISSION_DEBIT) )
{ llOwnerSay ( "Permission debit granted."); } else{ llOwnerSay ( "I must have Permission debit to get this work!!Please try again..."); llResetScript();
} }
http_response(key request_id, integer status, list metadata, string body) { if (request_id == requestid) { string fname; string lname; string amount; string my_string = body; list my_list = llParseString2List(my_string,["@_@"],["."]);//<---its better with some weird characters as separators integer i = 0; integer end = llGetListLength(my_list); //i dont know where you have the amount to be paid but supose is this: integer payamount=10;// =llList2Integer(my_list,position where you have the data to be paid); for (; i<end; ++i) { fname = llList2String(my_list,i); i++; lname = llList2String(my_list,i); i++; amount = llList2String(my_list,i); llOwnerSay(" First name is: " + fname + " Last name is: " + lname + " Amount to pay is: " + amount); llGiveMoney(toucher,payamount);//the give money allways need a key to paid the amount if you are retriving the data from the PHP side you need to convert it first to a valid key "(key)string from php)the same for the amount but to integer "(integer)amount" llSay(0,"I pay you: " +(string)payamount+" thanks to be our customer: " +toucher_name);// if you are getting the key from some DB you can make the llKey2Name in ".." thanks to be our customer: " +llKey2Name((key)key_from_db); //the avatar needs to be in the current sim to get work the key2name }
}
}
}
Try to copy and paste into an script to read the code.
|
|
Null Fargis
Registered User
Join date: 1 Jun 2007
Posts: 5
|
02-25-2009 22:29
Thanks again for the quick responses, very helping community  This is what I have for what I've worked on:
string NAME; // name to look up string URL = "http://w-hat.com/name2key"; // name2key url key reqid; // http request id key requestid;
default { state_entry() { llRequestPermissions(llGetOwner(), PERMISSION_DEBIT );//ask for permission to use cash }
touch_start(integer num) { requestid = llHTTPRequest("http://www.unitekcomputers.net/sl/sl.php",//this connects to my database on a server. it will return null fargis@1@bram braham@1@ that being myself and a friend for test purposes [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], ""); }
run_time_permissions( integer perm ) { if ( (perm && PERMISSION_DEBIT) ) { llOwnerSay ( "Permission debit granted."); } else { llOwnerSay ( "I must have Permission debit to get this work!!Please try again..."); llResetScript(); } }
http_response(key request_id, integer status, list metadata, string body) { if (request_id == requestid) { string fname; string lname; string amount; string my_string = body; list my_list = llParseString2List(my_string,["@"],["."]);//initialize the array integer i = 0; integer end = llGetListLength(my_list); integer payamount; for (; i<end - 1; ++i) { NAME = llList2String(my_list,i);//this is the raw text name ie. "Null Fargis" i++; payamount = llList2Integer(my_list,i);//this is the amount to be paid to that person, it will be 1 reqid = llHTTPRequest( URL + "?terse=1&name=" + llEscapeURL(NAME), [], "" ); //this calls to the w-hat database, and returns a very odd key; llGiveMoney(reqid,payamount); llOwnerSay("Amount paid: " + (string)payamount + " Account name: " + NAME + " key: " + (string)reqid); //the reqid returns "b728003f-6f3b-dd1a-92a0-19f0834b502a" for null fargis, and that is not my key
}
}
} }
The main problem here is that it returns a very weird key for myself when I query it through w-hat. Now, I see calling llHttpRequest being a problem since it's inside itself you could say. Is that possible to do? Or how would I go about executing another php file inside of executing one? Thanks again.
|
|
Faust Vollmar
llSetAgentSanity(FALSE);
Join date: 3 Feb 2007
Posts: 87
|
02-25-2009 22:47
You're trying to save the HTTP Request Key like it were the w-hat's responce. It's not, you need to loop through it. Give this a try. key uuidrequestid; key listrequestid;
list storedlist; integer length; integer index; string currname; integer currpay;
requestnext() { if(index < length) { currname = llList2String(storedlist, index); ++index; currpay = llList2Integer(storedlist, index); ++index; uuidrequestid = llHTTPRequest( "http://w-hat.com/name2key" + "?terse=1&name=" + llEscapeURL(currname), [], "" ); } }
default { state_entry() { llRequestPermissions(llGetOwner(), PERMISSION_DEBIT ); }
touch_start(integer num) { listrequestid = llHTTPRequest("http://www.unitekcomputers.net/sl/sl.php", [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], ""); }
run_time_permissions( integer perm ) { if ( (perm && PERMISSION_DEBIT) ) { llOwnerSay ( "Permission debit granted."); } else { llOwnerSay ( "I must have Permission debit to get this work!!Please try again..."); llResetScript(); } }
http_response(key request_id, integer status, list metadata, string body) { if(request_id == listrequestid) { storedlist = llParseString2List(body,["@"],["."]); length = llGetListLength(storedlist); requestnext(); } else if(request_id == uuidrequestid) { key target = (key)body; if( target != NULL_KEY ) { llGiveMoney(target, currpay); llOwnerSay("Amount paid: " + (string)currpay + " Account name: " + currname + " key: " + (string)target); } else { //Target not found in w-hat database. } requestnext(); } } }
EDIT: Minor point but worth mentioning for the sake of those few bytes of memory. For ParseString2List, you can use an empty list ( [] ) for either separators or spacers.
|
|
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
|
02-25-2009 22:54
That is because you are retiving the key from the request id and not your key look: llOwnerSay("Amount paid: " + (string)payamount + " Account name: " + NAME + " key: " + (string)reqid); //<----- key from your reqid and not your key from w-hat.com
string NAME; // name to look up string URL = "http://w-hat.com/name2key"; // name2key url key reqid; // http request id key requestid;
default { state_entry() { llRequestPermissions(llGetOwner(), PERMISSION_DEBIT );//ask for permission to use cash }
touch_start(integer num) { requestid = llHTTPRequest("http://www.unitekcomputers.net/sl/sl.php",//this connects to my database on a server. it will return null fargis@1@bram braham@1@ that being myself and a friend for test purposes [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], ""); }
run_time_permissions( integer perm ) { if ( (perm && PERMISSION_DEBIT) ) { llOwnerSay ( "Permission debit granted."); } else { llOwnerSay ( "I must have Permission debit to get this work!!Please try again..."); llResetScript(); } }
http_response(key request_id, integer status, list metadata, string body) { if (request_id == requestid) { string fname; string lname; string amount; string my_string = body; list my_list = llParseString2List(my_string,["@"],["."]);//initialize the array integer i = 0; integer end = llGetListLength(my_list); integer payamount; for (; i<end - 1; ++i) { NAME = llList2String(my_list,i);//this is the raw text name ie. "Null Fargis" i++; payamount = llList2Integer(my_list,i);//this is the amount to be paid to that person, it will be 1 reqid = llHTTPRequest( URL + "?terse=1&name=" + llEscapeURL(NAME), [], "" ); //this calls to the w-hat database, and returns a very odd key;
}
}
if (request_id==reqid)//the second request {
llGiveMoney((key)body,payamount);//set the body (string to a key) llOwnerSay("Amount paid: " + (string)payamount + " Account name: " + NAME + " key: " + body); //body its already an string my_list=[]; //empty the list because the data is not necessary right now
}
} }
Also you can have several httprequest any where but the diference is in the response comparation if (request_id == requestid)<--- your first httprequest if (request_id==reqid) <--- the second one Check it in SL Because im using an offline editor and dont know if im correct
|
|
ElQ Homewood
Sleeps Professionally
Join date: 25 Apr 2007
Posts: 280
|
02-26-2009 04:00
Also, if this is for a payroll type system, where you generally pay the same people all the time, it might be advantageous for you to store the keys in your offline database, or even in a notecard in the inworld object. This way you won't have to look up the keys every time. Other ways to get others' keys include having them touch an object when "hired" which will use llDetectedKey(0) to get their key and tell it to you or store it, or looking their name up in All Search inworld and looking at their search profile page..at the very bottom you will find their key at the end of the url for the page.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
02-26-2009 09:18
Yeah, it's often a lot simpler to use a resident's UUID as your primary key. Looking up their name is a lot easier and more reliable than the other way around. Also, in terms of the data you pass back to LSL from PHP, you may want to separate your names and amounts with commas, because the llCSV2List() function makes things very easy and fast. It's far easier to massage the data on the PHP end, where you have a very decent function library and such. http://www.lslwiki.net/lslwiki/wakka.php?wakka=llCSV2List
|
|
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
|
02-26-2009 09:26
From: ElQ Homewood Also, if this is for a payroll type system, where you generally pay the same people all the time, it might be advantageous for you to store the keys in your offline database, or even in a notecard in the inworld object. This way you won't have to look up the keys every time. Other ways to get others' keys include having them touch an object when "hired" which will use llDetectedKey(0) to get their key and tell it to you or store it, or looking their name up in All Search inworld and looking at their search profile page..at the very bottom you will find their key at the end of the url for the page. Yep its much better store the data and then retrive it from the DB (i use that way on my site) you need just store the first time the avatar try to register.
|
|
Null Fargis
Registered User
Join date: 1 Jun 2007
Posts: 5
|
02-26-2009 14:31
I have everything working the way I want it to work. When someone is directed to my site it will copy the UUID onto the database, and retrieve it when they need to be paid.
Thank you to all who responded, got this done a lot quicker than expected.
|