Gridhaul

From GridPlay
Revision as of 08:26, 4 August 2022 by Ven (talk | contribs) (→‎RESTful)

Info

GridHaul is a parcel based frieght hauling game.
Similar to the popular GTFO but parcel based meaning there can be more then one hub per sim.
Can exchange GridHaul dollars (G$) to Gridpay dollars (P$) and spend anywhere.

How To

GridHaul Group
GridHaul.png
Leader venkellie
Members 10

HUD

Wear the FREE hud, be in a GridHaul parcel, touch it and select pickup, select what item then your destination.
Travel to the destination, when you are in the parcel the text on the hud will turn green, touch and select Deliver

HUB Terminal

Rez it, click it, type in a name and submit.
Can then edit your hub using the GridPlay webconfig system
Updating your hub is easy, right click the old one, select Delete, rez out the new one
Minimum parcel size is 256 sqm

API

LSL

The HUD broadcasts loading and unloading commands on channel 47434285 with a json message
LOADING

{
"uri":"loading",
"cargo":
    {
    "id":3,
    "name":"Tree Logs",
    "des":"Rolls down stairs, alone or in pairs.",
    "p_per_gg":25,
    "slurl":"http:\/\/maps.secondlife.com\/secondlife\/Cavanaugh\/192\/154\/100",
    "gg":2,
    "fee":50,
    "tohub":"SLDA North Complex",
    "tohubuuid":"4ab1c442-4c0e-0bb5-9959-f51a0337ad3f"
    },
"parcel_uuid":"638f361e-7eea-3b5a-b253-1ef41c9034ba"
}

UNLOADING

{
"uri":"unloading",
"cargo":
    {
    "id":3,
    "name":"Tree Logs",
    "des":"Rolls down stairs, alone or in pairs.",
    "p_per_gg":25,
    "slurl":"http:\/\/maps.secondlife.com\/secondlife\/Cavanaugh\/192\/154\/100",
    "gg":2,
    "fee":50,
    "tohub":"SLDA North Complex",
    "tohubuuid":"4ab1c442-4c0e-0bb5-9959-f51a0337ad3f"
    },
"parcel_uuid":"4ab1c442-4c0e-0bb5-9959-f51a0337ad3f"
}

RESTful

We have two types of info which are hubs and items which both will return a json
GET https://api.gridplay.net/gridhaul/hubs

{
  "uri": "hubs",
  "hubs": [
    {
      "name": "Australian Locomotive Shed",
      "sim": "Tuliptree",
      "ifo": null,
      "owner": "Hrdtop75 Deluxe",
      "Vehicle_Types": "Foot,Road,RailRoad",
      "map": {
        "uuid": "960987dd-4673-08d2-f526-dc10c9f67954",
        "name": "Australian Locomotive Shed",
        "pos": "1007.7265625,1014.34765625",
        "lpos": "186,89,30",
        "icon": "https://gridplay.net/slmap/GHLogoNoAlpha.png",
        "sim": "Tuliptree"
      },
      "items": [
        {
          "id": 5,
          "name": "Lag test dummies",
          "onHand": 2
        },
        {
          "id": 8,
          "name": "Max8 airplane reckage",
          "onHand": 36
        },
      ]
    },
    {
      "name": "AXON Airport",
      "sim": "Lesters Best",
      "ifo": null,
      "owner": "Nikoli Nicholls",
      "Vehicle_Types": "Foot,Airport,Helipad",
      "map": {
        "uuid": "d355ece5-aacf-0be9-5e5e-d6858de51700",
        "name": "AXON Airport",
        "pos": "1130.55859375,1058.21484375",
        "lpos": "143,55,131",
        "icon": "https://gridplay.net/slmap/GHLogoNoAlpha.png",
        "sim": "Lesters Best"
      },
      "items": [
        {
          "id": 2,
          "name": "Barrel of Debiven Red Wine",
          "onHand": 0
        },
        {
          "id": 8,
          "name": "Max8 airplane reckage",
          "onHand": 0
        },
        {
          "id": 3,
          "name": "Tree Logs",
          "onHand": 2
        }
      ]
    },
}

GET https://api.gridplay.net/gridhaul/items

{
  "uri": "items",
  "items": [
    {
      "id": 1,
      "name": "Arabica Coffee beans",
      "des": "Beans for making coffee",
      "p_per_gg": 2
    },
    {
      "id": 2,
      "name": "Barrel of Debiven Red Wine",
      "des": "Not only good tasting wine but healthy too. Grown, aged and produced in Plusia",
      "p_per_gg": 10
    },
}

GET https://api.gridplay.net/gridhaul/jobs

{
  "uri": "jobs",
  "jobs": [
    {
      "from_hub": "Brandi's  Depo",
      "to_hub": "SLDA North Complex",
      "item": "Arabica Coffee beans",
      "gg": "2",
      "time": "Aug 03 2022 2:11.44PM"
    },
    {
      "from_hub": "Brandi's  Depo",
      "to_hub": "SLDA South Complex",
      "item": "Arabica Coffee beans",
      "gg": "2",
      "time": "Aug 03 2022 6:18.24AM"
    },
    {
      "from_hub": "SLDA South Complex",
      "to_hub": "Paradise Marina",
      "item": "Hemp",
      "gg": "2",
      "time": "Aug 02 2022 6:20.47PM"
    }
  ]
}

LSL Example Code

/*
Wiki at https://wiki.gridplay.net/w/Gridhaul#API
THIS IS JUST A EXAMPLE OF HOW TO USE THE GRIDHAUL API WITHIN LSL
Please feel free to add to it to make your own products to sell
*/
integer OPENAPI = 47434285;
string wcurl = "https://api.gridplay.net/gridhaul";
list httplist = [HTTP_METHOD, "GET", HTTP_VERIFY_CERT, TRUE,
HTTP_VERBOSE_THROTTLE, FALSE, HTTP_MIMETYPE,"application/json"];
key http_q;
string pid;
sendmsg(string uri, string search) {
    http_q = llHTTPRequest(url+"/"+uri+"?search="+search, httplist, "");
}
default {
	state_entry() {
		llListen(OPENAPI, "", "", "");
    	list pdetails = llGetParcelDetails(llGetPos(),[PARCEL_DETAILS_ID]);
    	pid = llList2String(pdetails,0)];
		sendmsg("hubs", pid);
	}
	listen(integer channel, string name, key id, string msg) {
		if (channel == OPENAPI) {
			// Lets make sure its for this parcel since the hud sends as llRegionSay
			if (llJsonGetValue(msg, ["parcel_uuid"]) == pid) {
				string uri = llJsonGetValue(msg, ["uri"]);
				string cargo = llJsonGetValue(msg, ["cargo"]);
				string itemName = llJsonGetValue(cargo, ["name"]);
				integer gg = (integer)llJsonGetValue(cargo, ["gg"]);
				if (uri == "loading") {
					// add to item
				}
				if (uri == "unloading") {
					// remove from item
				}
			}
		}
	}
	http_response(key request_id, integer status, list metadata, string body) {
        if (request_id == http_q) {
            string json = llUnescapeURL(body);
            string uri = llJsonGetValue(json, ["uri"]);
            if (uri == "hubs") {
            	string hubs = llJsonGetValue(json, ["hubs"]);
            	list hublist = llJson2List(hubs);
            	integer i = 0;
            	for(i; i < llGetListLength(hublist); i++) {
            		string hub = llList2String(hublist, i);
            		string hubName = llJsonGetValue(hub, ["name"]);
            		string hubOwner = llJsonGetValue(hub, ["owner"]);
            		string items = llJsonGetValue(hub, ["items"]);
            		list itemlist = llJson2List(items);
            		integer ii = 0;
            		for (ii; ii < llGetListLength(itemlist); ii++) {
            			string item = llList2String(itemlist, ii);
            			string itemID = llJsonGetValue(item, ["id"]);
            			string itemName = llJsonGetValue(item, ["name"]);
            			integer onHand = (integer)llJsonGetValue(item, ["onHand"]);
            			// handle item data here
            			sendmsg("items", itemID);
            		}
            		string ifo = llJsonGetValue(hub, ["ifo"]);
            		string Vehicle_Types = llJsonGetValue(hub, ["Vehicle_Types"]);
            		// handle hub data here
            	}
            }
            if (uri == "items") {
            	string items = llJsonGetValue(json, ["items"]);
            	list itemlist = llJson2List(items);
            	integer i = 0;
            	for(i; i < llGetListLength(itemlist); i++) {
            		string des = llJsonGetValue(item, ["des"]);
            		string p_per_gg = llJsonGetValue(item, ["p_per_gg"]);
            		// handle item data here
            	}
            }
        }
    }
}

PHP Example Code

Comes with Bootstrap 5.1.3

<?php
function GET($uri, $search = "") {
	$ch = curl_init();
	$url = "https://api.gridplay.net/gridhaul/".$uri."?search=".$search;
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	$output = curl_exec($ch);
	curl_close($ch);
	return json_decode($output, true);
}
$search = "Calleta";
if (!empty($_GET['search'])) {
	$search = $_GET['search'];
}
echo '<html><head>';
echo '<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">';
echo '</head><body><B>Showing results for '.$search.'</B>';
echo '<table class="table">';
echo '<thead><tr>';
echo '<th>Image</th>';
echo '<th>Name</th>';
echo '<th>Sim</th>';
echo '<th>Item Name - Quantities - Description</th>';
echo '</tr></thead>';
echo '<tbody>';
$hubs = GET("hubs", $search);
foreach($hubs['hubs'] as $hub) {
	echo '<tr>';
	echo '<td><img src="'.$hub['map']['icon'].'" style="max-height: 50px;"></td>';
	echo '<th>'.$hub["name"].'</th>';
	echo '<td>'.$hub["sim"].'</td>';
	$items = [];
	foreach($hub['items'] as $item) {
		$itemGET = GET("items", $item['id']);
		$items[] = $item['name'].' - '.$item['onHand'].' - '.$itemGET['items'][0]['des'];
	}
	echo '<td>'.implode("<br>", $items).'</td>';
	echo '</tr>';
}
echo '</tbody></table>';
echo '<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>';
echo '</body></html>';
?>

UPDATES

Hub 1.2.0 - June 30 2022 Happy Canada / USA Day eh

  • Fixed a bug where the terminal wouldnt do a full reset on rezzing
  • Added a confirm dialog when deleting the hub through the dialog
  • Some code clean up, mostly useless if statements
  • Website button now directs the person to the hub's website listing

HUD 1.2.0 - June 28 2022

  • Added distance to drop off location
  • Fixed some spelling issues
  • Hubs in the HUD now sort by sim name in ascending order (A-Z)
  • Some bug fixes
  • Text update timer changed from 5 seconds to 1 second

Hub 1.1.1 - Oct. 7 2021

  • Issue installing fixed. Seems to be a problem with a OR in a IF statement

Vehicle API 1.1.0a - Sept 17 2021

  • Same reason as with HUB and HUD, want to move all products to match
  • Fix Amphibian so that they now are supported by airports, marinas and road hubs
  • Fix OPENAPI data handling by Venkellie. OPENAPI is only triggered now if the sender is NOT owned by the owner of this script

HUD 1.1.0 - Sept 17 2021

  • Moving all GridHaul products to 1.1.0 so they all on the same version number going forward.
  • Cancel Run option
  • Fix page issue i hope (could still be buggy for some weird reason)

HUB 1.1.0 - Sept 17 2021

  • Code fixes and clean up
  • More info when installing a hub such as minimum parcel size
  • Moving all GridHaul products to 1.1.0 so they all on the same version number going forward.

SERVER SIDE AGAIN - Sept 14 2021

  • Amphibians can now see airports, marinas and road hubs
  • More fixes to picking hubs and dropping off

SERVER SIDE - Sept 13 2021

  • Added more info of the API to the wiki
  • Can now search by parcel uuid in the RESTful API
  • Deduction of quantity from a pickup hub should calculate correctly
  • Added a cancel run option to the server for a future HUD update
  • Fixed drop off issue
  • Fixed pagination issue with items and hubs, HUD fix coming soon
  • Amphibians can now see boat and airport hubs when picking up

HUD 1.0.7a - Sept 10 2021

  • HUD is now modifiable so you can resize it

Vehicle Script 1.1.0 - Sept 10 2021

  • FindSitTarget() fix by CarlaWetter
  • Sit attachment fix by CarlaWetter, enhanced by Venkellie
  • Max GridGram calculations by Venkellie
  • amphibian added by Venkellie
  • API cleanup by Venkellie
  • Szym Paladin compatibility by Venkellie
  • Max GG message by CarlaWetter

Server Side - Sept 10 2021

  • Added Amphibian to the hub and vehicle API options, this gives 19 GridGrams
  • More fixes for gg calculations
  • Fix for the search option, still needs testing
  • Distance check now in play when selecting a hub from the hud

HUD 1.0.7 - Sept 1 2021

  • Region say for API
  • Help button link fixed
  • Hub search option

July 25 2021 - Server side update

  • Picking up through the HUD will show items that hub has for pickup
  • Hub owners can now buy items for their hub using Haul dollars
  • Fixed a issue with vehicle types saving to the database
  • More minor fixes to the php code

Video

<youtube>https://www.youtube.com/watch?v=Bbd1UYkb2FA</youtube> <youtube>https://www.youtube.com/watch?v=zav5Pio3wxQ</youtube>