Page 1 of 1

In NEED

Posted: Fri Apr 29, 2011 6:53 am
by SpiritWebb
I am in need for some help, and I hope someone here can help. I know most have heard of Second Life, yes I play it. Anyway, I am building a game in it called "Invisible Time." Its a laser tag game, where all of Second Life is the arena. So what I am needing help with, is someone who is familiar with LSL (Linden Scripting Language) that can get LSL to talk to PHP then to a database...I know its possible, there are a few games within SL that use this. Since they make a ton in the in-game currency, which is convertable to real cash, these scripters won't share...it took an act of congress just to get one to point me in the right direction. I have searched tons of places and it confuses the heck out of me.

So I was hoping if anyone out there can help me with this. What I am wanting to do:

Have a database with the following: Username | Rank | Kills | Health

They don't use bullets, they rely on sensors that way they can play anywhere. When a weapon is fired upon another and the sensor sees it, then the health will drop. Once zero, it will take a few seconds or minutes for it to reset, then the player who "killed" the other will get +1 kill on their HUD. X amount of kills will equal a new rank. When they first put it on, it registers the players Username and creates a new "account/record." Health is placed at 100%, Kills: 0, and Rank: Ensign or whatever...

Re: In NEED

Posted: Tue May 03, 2011 5:09 am
by SpiritWebb
Anyone have any idea? I'm in desperate need...

Re: In NEED

Posted: Wed May 04, 2011 8:31 am
by SpiritWebb
Ok, so here are the two scripts I got working, but getting it to work with a database is the problem now as how I need it stated above on what it is supposed to do...

LSL script

Code: Select all

key myRequest;
default
{
    touch_start(integer number)
    {
           myRequest = llHTTPRequest("http://www.mysite.com/index.php",
          [HTTP_METHOD, "POST",
           HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
           "name=Jane&age=22");
    }

    http_response(key request_id, integer status, list metadata, string body)
    {
            if (request_id == myRequest)
            {
                  llSay(0,body);
            }
    }
}
PHP script

Code: Select all

<?php
    $aName = $_POST['name'];
    $anAge = $_POST['age'];

    echo "$aName is $anAge years old";
?>
Output: Jane is 22 years old

Re: In NEED

Posted: Fri May 06, 2011 1:50 am
by SpiritWebb
Anyone have any idea? I'm in desperate need...

Re: In NEED

Posted: Sat May 07, 2011 4:24 pm
by Xaleph
Seems tricky, however, i still don`t quite understand what you want now.. If LSL is event driven, you can make a http listener which listens to HTTP requests, kind of what you have right now, however, make sure the HTTP header has a unique ID to be sent back to the user.

Re: In NEED

Posted: Tue May 10, 2011 2:48 am
by SpiritWebb
The HTTPRequest I know, its already in the code. The part I don't understand is how to code LSL part. Where it says name=Jane&age=22 has a pre-defined section and called to echo back to the screen in the PHP. Its how to change that part so it can connect to PHP and PHP to the database and back. Hope that makes sense.

Re: In NEED

Posted: Tue May 10, 2011 11:17 am
by hallsofvallhalla

Code: Select all

  llSay(0,body);
looks like this is your return script. So find a way to split the data by say ";" so you echo out player data "Username;Rank;Kills;Health" then just split it. Not sure of LSL or what ever has a split function.

Re: In NEED

Posted: Tue May 10, 2011 2:21 pm
by Xaleph
Let me get this straight, you managed to get the LSL code to perform the POST action to your PHP page? If so, you don`t know what to return back to the LSL code?

If i understand correctly, you have to update your database etc, ( PHP stuff) and return a header in PHP back to where the request came from.

And like halls said, it accepts an object of string named Body. If that`s all it has to return, you can simply return a string, ( format is up to you, i would go with the simple GET response).

The HTTP listener should have a wait, because a request might take some time, then after it has an action, do your operations in LSL.

Re: In NEED

Posted: Tue May 10, 2011 5:59 pm
by SpiritWebb
hallsofvallhalla wrote:

Code: Select all

  llSay(0,body);
looks like this is your return script. So find a way to split the data by say ";" so you echo out player data "Username;Rank;Kills;Health" then just split it. Not sure of LSL or what ever has a split function.
Right, but all its saying is what was pre-set in the LSL "name=Jane&age=22." I don't need to split it, I am wanting to know how to change that part of it, the name=Jane&age=22 part in the LSL. I am needing to change that part and swap it with information that will consistently change.

The current info will always stay the same as how it is wrote right now because name and age are pre-defined.
Xaleph wrote:Let me get this straight, you managed to get the LSL code to perform the POST action to your PHP page? If so, you don`t know what to return back to the LSL code?

If i understand correctly, you have to update your database etc, ( PHP stuff) and return a header in PHP back to where the request came from.
Yes I managed to get the LSL code to POST action to the PHP page, but that is because the name=Jane&age=22 was pre-set. What I don't know, is what to change in the LSL script to allow consistently changing information, not a pre-set definition.

But yes, the LSL asks PHP if anything has changed, PHP then checks the database and says yes or no, if PHP says Yes some info has changed here it is, then LSL is like I will show the new info now.

Re: In NEED

Posted: Wed May 11, 2011 7:21 am
by SpiritWebb
Playing with some variables and LSL/PHP I managed to get some stuff working. For example now when a player puts on the hud for the first time, it registers them successfully in the database, however it doesn't place their username in the username table. Now working this bug, but it does display the correct information otherwise...until I figure this new bug out, this will not be resolved. :cry: