Implement more of the game!
This commit is contained in:
parent
4154512e8f
commit
e2327132d8
4 changed files with 764 additions and 0 deletions
1
SOURCE/LSL/.ext-dependency
Normal file
1
SOURCE/LSL/.ext-dependency
Normal file
|
@ -0,0 +1 @@
|
|||
FURWARE TEXT
|
374
SOURCE/LSL/CAH.lsl
Normal file
374
SOURCE/LSL/CAH.lsl
Normal file
|
@ -0,0 +1,374 @@
|
|||
|
||||
integer ingredient_channel = -8392888;
|
||||
integer containerChannel = -8392891;
|
||||
integer updater_channel = 15418070;
|
||||
integer card_channel = -32988199;
|
||||
integer hud_channel = -328478727;
|
||||
|
||||
string g_sVersion = "1.0.0.0000";
|
||||
key g_kToken;
|
||||
integer DEBUG = FALSE;
|
||||
list g_lReqs;
|
||||
string URL = "https://api.zontreck.dev/ls_bionics";
|
||||
Send(string Req,string method){
|
||||
g_lReqs += [Req,method];
|
||||
Sends();
|
||||
}
|
||||
Sends(){
|
||||
if(g_kCurrentReq == NULL_KEY){
|
||||
DoNextRequest();
|
||||
}
|
||||
//g_lReqs += [llHTTPRequest(URL + llList2String(lTmp,0), [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], llDumpList2String(llList2List(lTmp,1,-1), "?"))];
|
||||
}
|
||||
|
||||
integer g_iCzar;
|
||||
key g_kCurrentReq = NULL_KEY;
|
||||
DoNextRequest(){
|
||||
if(llGetListLength(g_lReqs)==0)return;
|
||||
list lTmp = llParseString2List(llList2String(g_lReqs,0),["?"],[]);
|
||||
if(DEBUG)llSay(0, "SENDING REQUEST: "+URL+llList2String(g_lReqs,0));
|
||||
|
||||
string append = "";
|
||||
if(llList2String(g_lReqs,1) == "GET")append = "?"+llDumpList2String(llList2List(lTmp,1,-1),"?");
|
||||
|
||||
g_kCurrentReq = llHTTPRequest(URL + llList2String(lTmp,0) + append, [HTTP_METHOD, llList2String(g_lReqs,1), HTTP_MIMETYPE, "application/x-www-form-urlencoded"], llDumpList2String(llList2List(lTmp,1,-1),"?"));
|
||||
}
|
||||
|
||||
|
||||
integer Dice(integer NTimes, integer Max, integer Test1, integer Test2){
|
||||
integer i=0;
|
||||
integer LTotal=0;
|
||||
for(i=0;i<NTimes;i++){
|
||||
LTotal += llRound(llFrand(Max));
|
||||
llSleep(0.5);
|
||||
}
|
||||
integer Mean = LTotal / NTimes;
|
||||
if(Mean > Test1&&Mean < Test2)return TRUE;
|
||||
else return FALSE;
|
||||
}
|
||||
|
||||
list g_lListener;
|
||||
list g_lPending;
|
||||
REZ(key i){
|
||||
if(g_iBlockRez)return;
|
||||
integer chan = llRound(llFrand(548937));
|
||||
|
||||
llRezObject("Cards Against Humanity HUD [LS]", llGetPos(), ZERO_VECTOR, ZERO_ROTATION, chan);
|
||||
|
||||
g_lPending += [i, chan];
|
||||
|
||||
integer rnd = llRound(llFrand(5843758));
|
||||
g_lListener += [i,rnd,llListen(rnd,"",i,"")];
|
||||
llDialog(i, "Are you male or female?", ["Female", "Male"], rnd);
|
||||
|
||||
llRequestPermissions(i, PERMISSION_TRIGGER_ANIMATION);
|
||||
}
|
||||
|
||||
Rescan(){
|
||||
list OldPlayers = Players;
|
||||
|
||||
Players=[];
|
||||
integer i=0;
|
||||
integer end = llGetNumberOfPrims();
|
||||
integer ChairNumber = 0;
|
||||
//llSay(0, "Simulating player count");
|
||||
list ToEvict = [];
|
||||
for(i=0;i<=end;i++){
|
||||
vector Scale = llGetAgentSize(llGetLinkKey(i));
|
||||
if(Scale != ZERO_VECTOR){
|
||||
// This is an avatar
|
||||
integer Chair = llList2Integer(Chairs,ChairNumber);
|
||||
if(ChairNumber > llGetListLength(Chairs)) ToEvict += [llGetLinkKey(i)];
|
||||
ChairNumber++;
|
||||
//llSay(0, "Discover: Avatar ID : secondlife:///app/agent/"+(string)llGetLinkKey(i)+"/about");
|
||||
list ChairParams = llGetLinkPrimitiveParams(Chair, [PRIM_POS_LOCAL, PRIM_DESC]);
|
||||
list ChairData = llParseString2List(llList2String(ChairParams,1), ["`"],[]);
|
||||
Players += llGetLinkKey(i);
|
||||
if(llListFindList(OldPlayers, [llGetLinkKey(i)])==-1){
|
||||
llWhisper(0, "secondlife:///app/agent/"+(string)llGetLinkKey(i)+"/about has joined the game!");
|
||||
llInstantMessage(llGetLinkKey(i), "Rezzing a HUD. Please accept attachment permissions");
|
||||
REZ(llGetLinkKey(i));
|
||||
}
|
||||
llSetLinkPrimitiveParams(i, [PRIM_POS_LOCAL, llList2Vector(ChairParams,0)+<0,0,1>+(vector)llList2String(ChairData,1), PRIM_ROT_LOCAL, llEuler2Rot((vector)llList2String(ChairData,0)*DEG_TO_RAD)]);
|
||||
}
|
||||
}
|
||||
|
||||
Compare(OldPlayers);
|
||||
Evict(ToEvict);
|
||||
|
||||
if(llGetListLength(Players)==0 && llGetListLength(OldPlayers)!=0){
|
||||
llSay(0, "All players left the game. Resetting game and shuffling cards!");
|
||||
llResetScript();
|
||||
}
|
||||
}
|
||||
list Chairs=[];
|
||||
list Players;
|
||||
|
||||
Compare(list OldList){
|
||||
// Check for who has left the game, then deactivate their HUD
|
||||
integer i=0;
|
||||
integer end = llGetListLength(OldList);
|
||||
for(i=0;i<end;i++){
|
||||
if(llListFindList(Players,[llList2Key(OldList,i)])==-1){
|
||||
llSay(0, "secondlife:///app/agent/"+llList2String(OldList,i)+"/about has left the game");
|
||||
llSay(hud_channel, llList2Json(JSON_OBJECT, ["type","die","table",g_kID,"avatar", llList2Key(OldList,i)]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Evict(list lLst){
|
||||
integer i=0;
|
||||
integer end = llGetListLength(lLst);
|
||||
for(i=0;i<end;i++){
|
||||
llUnSit(llList2Key(lLst,i));
|
||||
llSay(hud_channel, llList2Json(JSON_OBJECT, ["type","die","table",g_kID,"avatar", llList2Key(lLst,i)]));
|
||||
}
|
||||
|
||||
if(end!=0)Rescan();
|
||||
}
|
||||
key g_kID;
|
||||
integer g_iBlockRez = 0;
|
||||
key g_kCurrentBlackCard;
|
||||
list g_lPendingCards;
|
||||
default
|
||||
{
|
||||
state_entry()
|
||||
{
|
||||
Chairs=[];
|
||||
//llSay(0, "Activating Setup Mode");
|
||||
//llSay(0, "Scanning linkset for positions of prims");
|
||||
integer i=0;
|
||||
integer end = llGetNumberOfPrims();
|
||||
for(i=0;i<=end;i++){
|
||||
string name = llGetLinkName(i);
|
||||
if(name == "Chair [LS]"){
|
||||
Chairs += i;
|
||||
}
|
||||
}
|
||||
//llSay(0, "Scanning for players");
|
||||
g_iBlockRez = 1;
|
||||
Rescan();
|
||||
//llSay(0, "Setup has completed!");
|
||||
|
||||
llSetSitText("Play!");
|
||||
|
||||
llWhisper(0, "Stand by...");
|
||||
g_kID = (key)llGetObjectDesc();
|
||||
if(g_kID == "new_lsk"){
|
||||
g_kID = llGenerateKey();
|
||||
llSetObjectDesc((string)g_kID);
|
||||
llSay(0, "First Rez! Thank you for your purchase of an LS Bionics product!\n \n[Generating License Key]");
|
||||
llSetObjectName("Cards Against Humanity [LS]");
|
||||
Send("/Put_Product_Data.php?PRODUCT=CAH_TABLE&KEYID="+(string)g_kID+"&NICKNAME=License&DATA=1","POST");
|
||||
return;
|
||||
}
|
||||
llWhisper(card_channel, llList2Json(JSON_OBJECT, ["type", "die", "table", g_kID]));
|
||||
llWhisper(hud_channel, llList2Json(JSON_OBJECT, ["type", "die", "table", g_kID, "avatar", NULL_KEY]));
|
||||
Evict(Players);
|
||||
|
||||
|
||||
state license_check;
|
||||
}
|
||||
|
||||
http_response(key r,integer s,list m,string b){
|
||||
if(r==g_kCurrentReq){
|
||||
g_kCurrentReq = NULL_KEY;
|
||||
|
||||
list lTmp = llParseString2List(b,[";;",";"],[]);
|
||||
if(llList2String(lTmp,0) == "Put_Product_Data"){
|
||||
llResetScript();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
on_rez(integer t){
|
||||
llResetScript();
|
||||
}
|
||||
}
|
||||
|
||||
state license_check
|
||||
{
|
||||
state_entry(){
|
||||
//llSay(0, "Checking for a game license... Please hold on awhile while I process your request");
|
||||
Send("/Get_Product_Data.php?PRODUCT=CAH_TABLE&KEYID="+(string)g_kID+"&NICKNAME=License", "GET");
|
||||
}
|
||||
|
||||
http_response(key r,integer s,list m, string b){
|
||||
if(r == g_kCurrentReq){
|
||||
g_kCurrentReq = NULL_KEY;
|
||||
g_lReqs = llDeleteSubList(g_lReqs,0,1);
|
||||
|
||||
list lTmp = llParseString2List(b,[";;",";"],[]);
|
||||
string Script = llList2String(lTmp,0);
|
||||
if(Script == "Get_Product_Data")
|
||||
{
|
||||
string Variable = llList2String(lTmp,1);
|
||||
if(llList2String(lTmp,2) == "1"){
|
||||
//llSay(0, "License is now activated!");
|
||||
state active;
|
||||
} else {
|
||||
llSay(0, "ERROR: No valid license key has been found. Try again later, or contact LS Bionics support\n\n[Error code: "+llList2String(lTmp,2)+"]");
|
||||
}
|
||||
}
|
||||
|
||||
Sends();
|
||||
}
|
||||
}
|
||||
|
||||
on_rez(integer t){
|
||||
llResetScript();
|
||||
}
|
||||
|
||||
changed(integer t){
|
||||
if(t&CHANGED_REGION_START){
|
||||
llResetScript();
|
||||
}
|
||||
}
|
||||
}
|
||||
state active
|
||||
{
|
||||
state_entry(){
|
||||
llSay(0, "Game Table now ready");
|
||||
llSay(0, "Shuffling cards...");
|
||||
Send("/Modify_Card.php?TYPE_OVERRIDE=MAKE_DECK&TABLE_ID="+(string)g_kID, "POST");
|
||||
g_iBlockRez=0;
|
||||
g_lPending=[];
|
||||
|
||||
llListen(hud_channel, "", "", "");
|
||||
llListen(card_channel, "", "", "");/*
|
||||
integer chan = llRound(llFrand(548378));
|
||||
g_lPendingCards += [chan, "null|black"];
|
||||
llRezObject("Playing Card [LS]", llGetPos(), ZERO_VECTOR, ZERO_ROTATION, chan);*/
|
||||
}
|
||||
|
||||
http_response(key r,integer s,list m,string b){
|
||||
if(r==g_kCurrentReq){
|
||||
g_kCurrentReq = NULL_KEY;
|
||||
g_lReqs = llDeleteSubList(g_lReqs,0,1);
|
||||
|
||||
list lTmp = llParseString2List(b,[";;",";"],[]);
|
||||
string Script = llList2String(lTmp,0);
|
||||
if(Script == "Modify_Deck"){
|
||||
llSay(0, "Deck generated!");
|
||||
} else if(Script == "Get_Card"){
|
||||
key Sender = (key)llList2String(lTmp,1);
|
||||
list Params = llJson2List(llBase64ToString(llList2String(lTmp,2)));//llParseString2List(llBase64ToString(llList2String(lTmp,2)), ["|"],[]);
|
||||
if(DEBUG)llSay(0, "HTTP REPLY: "+b);
|
||||
if(DEBUG)llSay(0, "PARAMETER LIST: "+llList2CSV(Params));
|
||||
integer i=0;
|
||||
integer end = llGetListLength(Params);
|
||||
for(i=0;i<end;i++){
|
||||
string card_text = llJsonGetValue(llList2String(Params,i), ["text"]);
|
||||
integer color = (integer)llJsonGetValue(llList2String(Params,i), ["color"]);
|
||||
integer num_req = (integer)llJsonGetValue(llList2String(Params,i),["num"]);
|
||||
integer rezzed = (integer)llJsonGetValue(llList2String(Params,i), ["rezzed"]);
|
||||
if(rezzed==0)
|
||||
llRegionSayTo(Sender, hud_channel, llList2Json(JSON_OBJECT, ["type", "card", "avatar", llGetOwnerKey(Sender), "card", llList2Json(JSON_OBJECT, ["text", llList2String(Params,i)])]));
|
||||
else{
|
||||
if(color){
|
||||
g_kCurrentBlackCard = Sender;
|
||||
llSay(0, "A new black card has been played");
|
||||
if(g_iCzar == -1){
|
||||
llSay(0, "This is a new game, assigning random card czar");
|
||||
g_iCzar = llRound(llFrand(llGetListLength(Players)));
|
||||
} else {
|
||||
g_iCzar++;
|
||||
if(g_iCzar >= llGetListLength(Players)){
|
||||
g_iCzar = 0;
|
||||
}
|
||||
}
|
||||
|
||||
key czar = llList2String(Players,g_iCzar);
|
||||
llRegionSay(hud_channel, llList2Json(JSON_OBJECT, ["type", "select", "czar", czar, "sel_count", num_req]));
|
||||
}
|
||||
llRegionSayTo(Sender, card_channel, llList2Json(JSON_OBJECT, ["type", "set", "card", llList2Json(JSON_OBJECT, ["text", card_text, "color", color, "num", num_req])]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Sends();
|
||||
}
|
||||
}
|
||||
|
||||
listen(integer c,string n,key i, string m){
|
||||
if(DEBUG){
|
||||
llSay(0, "LISTEN: "+llDumpList2String([c,n,i,m], " - "));
|
||||
}
|
||||
if(c==hud_channel){
|
||||
if(llJsonGetValue(m,["type"])=="card_request"){
|
||||
integer card_count = (integer)llJsonGetValue(m,["count"]);
|
||||
Send("/Modify_Card.php?TYPE_OVERRIDE=GET_CARD&TABLE_ID="+(string)g_kID+"&COLOR=0&DRAW_COUNT="+(string)card_count+"&SENDER="+(string)i+"&REZZED=0", "POST");
|
||||
} else if(llJsonGetValue(m,["type"])=="alive"){
|
||||
integer index = llListFindList(g_lPending,[(integer)llJsonGetValue(m,["boot"])]);
|
||||
if(index==-1)return;
|
||||
else {
|
||||
// Boot the HUD
|
||||
if(DEBUG)llSay(0, "Sending HUD Activation signal");
|
||||
index--;
|
||||
|
||||
|
||||
llRegionSayTo(i,llList2Integer(g_lPending,index+1), llList2Json(JSON_OBJECT, ["type", "activate", "user", llList2String(g_lPending,index), "table", g_kID]));
|
||||
g_lPending = llDeleteSubList(g_lPending, index,index+1);
|
||||
}
|
||||
}
|
||||
} else if(c==card_channel){
|
||||
if(llJsonGetValue(m,["type"])=="alive"){
|
||||
llSay(0, "IN ALIVE BLOCK");
|
||||
integer index = llListFindList(g_lPendingCards,[(integer)llJsonGetValue(m,["boot"])]);
|
||||
if(index==-1){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
g_lPendingCards = llDeleteSubList(g_lPendingCards,index,index+1);
|
||||
|
||||
llRegionSayTo(i, (integer)llJsonGetValue(m,["boot"]), llList2Json(JSON_OBJECT, ["type", "activate", "table", g_kID]));
|
||||
// Calculate position offset
|
||||
llSleep(1);
|
||||
llRegionSayTo(i, card_channel, llList2Json(JSON_OBJECT, ["type", "position", "pos", llGetPos()+<0,0,0.5>]));
|
||||
if(DEBUG)llSay(0, "Alive request on the Cards Channel: "+m);
|
||||
Send("/Modify_Card.php?TYPE_OVERRIDE=GET_CARD&TABLE_ID="+(string)g_kID+"&COLOR=1&DRAW_COUNT=1&SENDER="+(string)i+"&REZZED=1", "POST");
|
||||
|
||||
}
|
||||
} else if(llListFindList(g_lListener,[c])!=-1){
|
||||
integer index = llListFindList(g_lListener,[c]);
|
||||
index--;
|
||||
if(m == "Female"){
|
||||
llStartAnimation("female");
|
||||
} else {
|
||||
llStartAnimation("male");
|
||||
}
|
||||
|
||||
llListenRemove(llList2Integer(g_lListener,index+2));
|
||||
g_lListener=llDeleteSubList(g_lListener,index,index+2);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
changed(integer t){
|
||||
if(t&CHANGED_REGION_START){
|
||||
llResetScript();
|
||||
} else if(t&CHANGED_LINK){
|
||||
Rescan();
|
||||
}
|
||||
}
|
||||
|
||||
on_rez(integer t){
|
||||
llResetScript();
|
||||
}
|
||||
|
||||
touch_start(integer t){
|
||||
string name = llGetLinkName(llDetectedLinkNumber(0));
|
||||
if(name == "START"){
|
||||
|
||||
if(!(llGetListLength(Players) > 1)){
|
||||
llSay(0, "Must have more than 1 player to start!");
|
||||
}
|
||||
// Begin the game loop
|
||||
integer chan = llRound(llFrand(548378));
|
||||
g_lPendingCards += [chan, "null|black"];
|
||||
llRezObject("Playing Card [LS]", llGetPos(), ZERO_VECTOR, ZERO_ROTATION, chan);
|
||||
}
|
||||
}
|
||||
}
|
68
SOURCE/LSL/Card.lsl
Normal file
68
SOURCE/LSL/Card.lsl
Normal file
|
@ -0,0 +1,68 @@
|
|||
|
||||
integer card_channel = -32988199;
|
||||
|
||||
integer g_iStart;
|
||||
key g_kTable;
|
||||
|
||||
default
|
||||
{
|
||||
state_entry()
|
||||
{
|
||||
llMessageLinked(LINK_SET,0,"","fw_reset");
|
||||
llSetLinkColor(LINK_ROOT, <1,1,1>,1);
|
||||
llSetLinkColor(LINK_ROOT, <1,1,1>,0);
|
||||
llWhisper(0, "You must not rez this card by itself!");
|
||||
}
|
||||
|
||||
on_rez(integer t){
|
||||
if(t==0){
|
||||
llResetScript();
|
||||
}else{
|
||||
llSay(0, "Card is trying to find a table");
|
||||
llListen(t, "", "", "");
|
||||
g_iStart=t;
|
||||
llSay(card_channel, llList2Json(JSON_OBJECT, ["type", "alive", "boot", t]));
|
||||
}
|
||||
}
|
||||
|
||||
listen(integer c,string n,key i,string m){
|
||||
if(c == g_iStart){
|
||||
if(llJsonGetValue(m, ["type"]) == "activate"){
|
||||
llListen(card_channel, "", i, "");
|
||||
llMessageLinked(LINK_SET,0,"","fw_reset");
|
||||
g_kTable = (key)llJsonGetValue(m,["table"]);
|
||||
}
|
||||
} else if(c == card_channel){
|
||||
if(llJsonGetValue(m,["type"]) == "position"){
|
||||
llSetPos((vector)llJsonGetValue(m,["pos"]));
|
||||
} else if(llJsonGetValue(m,["type"]) == "rotation"){
|
||||
llSetRot((rotation)llJsonGetValue(m,["rot"]));
|
||||
} else if(llJsonGetValue(m,["type"]) == "set"){
|
||||
string text = llJsonGetValue(m,["card", "text"]);
|
||||
integer color = (integer)llJsonGetValue(m,["card","color"]);
|
||||
integer num = (integer)llJsonGetValue(m,["card", "num"]);
|
||||
if(color){
|
||||
// black
|
||||
llSetLinkColor(LINK_ROOT, <0.2,0.2,0.2>, 1);
|
||||
llSetLinkColor(LINK_ROOT, <0.2,0.2,0.2>, 0);
|
||||
|
||||
llMessageLinked(LINK_SET, 0, "c=white", "fw_conf");
|
||||
}else {
|
||||
llSetLinkColor(LINK_ROOT, <1,1,1>,1);
|
||||
llSetLinkColor(LINK_ROOT, <1,1,1>,0);
|
||||
llMessageLinked(LINK_SET,0,"c=black", "fw_conf");
|
||||
}
|
||||
|
||||
llMessageLinked(LINK_SET,0,text, "fw_data : card_text");
|
||||
|
||||
if(num > 1){
|
||||
llMessageLinked(LINK_SET,0,"Pick ("+(string)num+")\nDraw ("+(string)num+")", "fw_data : card_helpertext");
|
||||
} else {
|
||||
llMessageLinked(LINK_SET,0,"Cards Against Humanity", "fw_data : card_helpertext");
|
||||
}
|
||||
} else if(llJsonGetValue(m, ["type"]) == "die"){
|
||||
llDie();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
321
SOURCE/LSL/HUD.lsl
Normal file
321
SOURCE/LSL/HUD.lsl
Normal file
|
@ -0,0 +1,321 @@
|
|||
integer g_iStartParam;
|
||||
key g_kUser;
|
||||
key g_kTable;
|
||||
|
||||
integer card_channel = -32988199;
|
||||
integer hud_channel = -328478727;
|
||||
|
||||
|
||||
s(string m){
|
||||
llInstantMessage(g_kUser,m);
|
||||
}
|
||||
list g_lCards;
|
||||
Cards(){
|
||||
integer x = 0;
|
||||
integer e = 10;
|
||||
integer CurCard = 1;
|
||||
integer NCard = 0;
|
||||
for(x=0;x<e;x++){
|
||||
if(llGetListLength(g_lCards) > x){
|
||||
string card_params = llList2String(g_lCards,x);
|
||||
llMessageLinked(LINK_SET,0,llJsonGetValue(card_params,["text"]), "fw_data : card_text"+(string)CurCard);
|
||||
} else {
|
||||
NCard++;
|
||||
llMessageLinked(LINK_SET,0,"", "fw_data : card_text"+(string)CurCard);
|
||||
}
|
||||
|
||||
llMessageLinked(LINK_SET,0,"Cards Against Humanity","fw_data : card_helpertext"+(string)CurCard);
|
||||
CurCard++;
|
||||
}
|
||||
|
||||
if(NCard>0){
|
||||
integer CardsToRequest = NCard;
|
||||
if(CardsToRequest == 0)return;
|
||||
else {
|
||||
llRegionSayTo(g_kTable,hud_channel, llList2Json(JSON_OBJECT, ["type","card_request","count", CardsToRequest]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
POS(){
|
||||
if(!llGetAttached())return;
|
||||
vector local = <0.02395, 0.47113, -0.15166>;
|
||||
llSetPrimitiveParams([PRIM_POS_LOCAL, local]);
|
||||
}
|
||||
|
||||
POS2(){
|
||||
if(!llGetAttached())return;
|
||||
vector local = <0.02395, 1.77734, -0.15166>;
|
||||
llSetPrimitiveParams([PRIM_POS_LOCAL, local]);
|
||||
}
|
||||
|
||||
list g_lSelected = [];
|
||||
|
||||
Highlight(){
|
||||
integer i=1;
|
||||
integer end = 10;
|
||||
for(i=1;i<=end;i++){
|
||||
if(llListFindList(g_lSelected,[i])==-1){
|
||||
integer x=0;
|
||||
integer end2 = llGetNumberOfPrims();
|
||||
for(x=1;x<=end2;x++){
|
||||
string LinkName = llGetLinkName(x);
|
||||
if(LinkName=="Card"+(string)i){
|
||||
llSetLinkColor(x, <1,1,1>, 2);
|
||||
jump stopFor;
|
||||
}
|
||||
}
|
||||
@stopFor;
|
||||
} else {
|
||||
integer x = 0;
|
||||
integer end2 = llGetNumberOfPrims();
|
||||
for(x=1;x<=end2;x++){
|
||||
string LinkName = llGetLinkName(x);
|
||||
if(LinkName == "Card"+(string)i){
|
||||
llSetLinkColor(x,<0,1,0>,2);
|
||||
jump stopFor2;
|
||||
}
|
||||
}
|
||||
@stopFor2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
integer g_iSelectNum=0;
|
||||
integer g_iCanSelect=0;
|
||||
integer g_iListen=-1;
|
||||
integer g_iChan;
|
||||
|
||||
ShowPrompt(){
|
||||
if(g_iListen==-1){
|
||||
g_iChan = llRound(llFrand(5493874));
|
||||
g_iListen = llListen(g_iChan, "", g_kUser, "");
|
||||
}
|
||||
|
||||
llDialog(g_kUser, "Do you want to submit your selected card(s)?", ["Yes", "No"], g_iChan);
|
||||
}
|
||||
|
||||
default
|
||||
{
|
||||
state_entry()
|
||||
{
|
||||
llWhisper(0, "HUD was not rezzed or attached using the game table");
|
||||
llWhisper(0, "Some functionality may not work");
|
||||
llMessageLinked(LINK_SET,0,"","fw_reset");
|
||||
llWhisper(0, "HUD is now activating");
|
||||
|
||||
g_kUser=llGetOwner();
|
||||
g_kTable = llGetOwner();
|
||||
|
||||
Highlight();
|
||||
}
|
||||
|
||||
on_rez(integer t){
|
||||
if(t==0){
|
||||
llResetScript();
|
||||
}else {
|
||||
llSetPrimitiveParams([PRIM_TEMP_ON_REZ,TRUE]);
|
||||
g_iStartParam = t;
|
||||
llListen(t, "", "", "");
|
||||
llSay(hud_channel, llList2Json(JSON_OBJECT, ["type", "alive", "boot", t]));
|
||||
}
|
||||
}
|
||||
|
||||
listen(integer c,string n,key i,string m){
|
||||
if(g_iStartParam == c){
|
||||
// listen for the UUID of who to attach the HUD to!
|
||||
if(llJsonGetValue(m,["type"])=="activate"){
|
||||
g_kTable = (key)llJsonGetValue(m,["table"]);
|
||||
llWhisper(0, "HUD now activating...");
|
||||
key g_kUser = (key)llJsonGetValue(m, ["user"]);
|
||||
llRequestPermissions(g_kUser, PERMISSION_ATTACH);
|
||||
//Cards();
|
||||
}
|
||||
}else if(c == hud_channel){
|
||||
//llSay(0, "HUD message: "+m);
|
||||
if(llJsonGetValue(m,["type"])=="card"){
|
||||
if(llJsonGetValue(m,["avatar"])==(string)g_kUser){
|
||||
if(llGetListLength(g_lCards)<10 && llListFindList(g_lCards,[llJsonGetValue(m,["card"])])==-1){
|
||||
g_lCards += llJsonGetValue(m,["card"]);
|
||||
s("Added card: "+llJsonGetValue(m,["card", "text"]));
|
||||
}
|
||||
}
|
||||
} else if(llJsonGetValue(m,["type"]) == "select"){
|
||||
if(llJsonGetValue(m,["czar"]) == (string)g_kUser){
|
||||
s("You are the Card Czar, hiding the HUD");
|
||||
POS2();
|
||||
g_iCanSelect=0;
|
||||
} else {
|
||||
g_iSelectNum = (integer)llJsonGetValue(m,["sel_count"]);
|
||||
POS();
|
||||
g_lSelected=[];
|
||||
Highlight();
|
||||
s("Select ("+(string)g_iSelectNum+") cards to submit");
|
||||
s("Card czar: secondlife:///app/agent/"+llJsonGetValue(m,["czar"])+"/about");
|
||||
Cards();
|
||||
g_iCanSelect=1;
|
||||
}
|
||||
} else if(llJsonGetValue(m,["type"]) == "judging"){
|
||||
s("Judging begun. HUD hidden!");
|
||||
POS2();
|
||||
g_lSelected=[];
|
||||
Highlight();
|
||||
g_iCanSelect=0;
|
||||
if(g_iListen!=-1){
|
||||
llListenRemove(g_iListen);
|
||||
g_iListen=-1;
|
||||
g_iChan=0;
|
||||
}
|
||||
} else if(llJsonGetValue(m,["type"])=="die"){
|
||||
llSay(0, "(DEBUG)\nm: "+m+"\n-> Table: "+(string)g_kTable+"\n-> User: "+(string)g_kUser);
|
||||
if(llJsonGetValue(m,["table"])==(string)g_kTable){
|
||||
if(llJsonGetValue(m,["avatar"])==(string)g_kUser || llJsonGetValue(m,["avatar"])==(string)NULL_KEY || llJsonGetValue(m,["avatar"])==""){
|
||||
llSay(0, "Deactivating HUD");
|
||||
state detach;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(g_iChan == c){
|
||||
if(m == "No"){
|
||||
// reshow prompt until user selects yes
|
||||
ShowPrompt();
|
||||
} else if(m == "Yes"){
|
||||
// Gather card data and send to table
|
||||
//llWhisper(0, "Locating the cards...");
|
||||
integer x = 0;
|
||||
integer end = llGetListLength(g_lSelected);
|
||||
string sActualCardData;
|
||||
if(end == 0 || end!= g_iSelectNum){
|
||||
s("You must select "+(string)g_iSelectNum+" cards!");
|
||||
}else {
|
||||
list lToRemove = [];
|
||||
for(x=0;x<end;x++){
|
||||
integer CardNum = llList2Integer(g_lSelected, x);
|
||||
string CardQuery = llList2String(g_lCards, (CardNum-1));
|
||||
lToRemove += CardQuery;
|
||||
sActualCardData = llJsonSetValue(sActualCardData, [x], CardQuery);
|
||||
}
|
||||
x=0;
|
||||
end=llGetListLength(g_lCards);
|
||||
for(x=0;x<end;x++){
|
||||
string CardData = llList2String(g_lCards, x);
|
||||
if(llListFindList(lToRemove, [CardData])!=-1){
|
||||
g_lCards = llDeleteSubList(g_lCards, x,x);
|
||||
x=-1;
|
||||
end = llGetListLength(g_lCards);
|
||||
}
|
||||
|
||||
}
|
||||
g_lSelected=[];
|
||||
Highlight();
|
||||
Cards();
|
||||
//llSay(0, "(DEBUG) Sending card(s) to table: "+sActualCardData);
|
||||
llRegionSayTo(g_kTable, hud_channel, llList2Json(JSON_OBJECT, ["type", "cards", "cards", sActualCardData]));
|
||||
POS2();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
touch_start(integer t){
|
||||
if(g_iCanSelect){
|
||||
llMessageLinked(LINK_SET,0,llGetLinkName(llDetectedLinkNumber(0)),"fw_touchquery : "+(string)llDetectedLinkNumber(0) + ":" + (string)llDetectedTouchFace(0));
|
||||
}else s("You can't select a card right now");
|
||||
}
|
||||
|
||||
run_time_permissions(integer p){
|
||||
if(p&PERMISSION_ATTACH){
|
||||
llAttachToAvatarTemp(ATTACH_HUD_CENTER_2);
|
||||
}
|
||||
}
|
||||
|
||||
attach(key id){
|
||||
if(id == NULL_KEY){
|
||||
llWhisper(0, "HUD is deactivating...");
|
||||
llRegionSayTo(g_kTable, hud_channel, llList2Json(JSON_OBJECT, ["type", "leave", "avatar", g_kUser]));
|
||||
//llRemoveInventory(llGetScriptName());
|
||||
} else {
|
||||
g_kUser=id;
|
||||
POS();
|
||||
llMessageLinked(LINK_SET,0,"","fw_reset");
|
||||
}
|
||||
}
|
||||
|
||||
link_message(integer s,integer n,string m,key i){
|
||||
if(i=="fw_ready"){
|
||||
llMessageLinked(LINK_SET,0,"c=black", "fw_conf");
|
||||
g_lCards=[];
|
||||
|
||||
llListen(hud_channel, "", "", "");
|
||||
Cards();
|
||||
POS2();
|
||||
|
||||
s("HUD initialization completed");
|
||||
}else if (i == "fw_touchreply") {
|
||||
list tokens = llParseStringKeepNulls(m, [":"], []);
|
||||
string boxName = llList2String(tokens, 0);
|
||||
integer dx = llList2Integer(tokens, 1);
|
||||
integer dy = llList2Integer(tokens, 2);
|
||||
string rootName = llList2String(tokens, 3);
|
||||
integer x = llList2Integer(tokens, 4);
|
||||
integer y = llList2Integer(tokens, 5);
|
||||
string userData = llList2String(tokens, 6);
|
||||
|
||||
ShowPrompt();
|
||||
|
||||
if(rootName == ""){
|
||||
integer CardNum = (integer)llGetSubString(userData, 4,-1);
|
||||
if(CardNum ==0)return;
|
||||
else {
|
||||
if(llListFindList(g_lSelected,[CardNum])!=-1){
|
||||
g_lSelected = llDeleteSubList(g_lSelected, llListFindList(g_lSelected, [CardNum]), llListFindList(g_lSelected, [CardNum]));
|
||||
} else{
|
||||
|
||||
if(llGetListLength(g_lSelected) == g_iSelectNum){
|
||||
s("You already have "+(string)g_iSelectNum+" selected cards. Deselect one before changing your selection");
|
||||
return;
|
||||
}
|
||||
g_lSelected += CardNum;
|
||||
}
|
||||
Highlight();
|
||||
}
|
||||
} else {
|
||||
list lParam = llParseString2List(rootName,["text"],[]);
|
||||
integer CardNum = (integer)llList2String(lParam,-1);
|
||||
if(CardNum==0)return;
|
||||
else{
|
||||
if(llListFindList(g_lSelected,[CardNum])!=-1){
|
||||
g_lSelected = llDeleteSubList(g_lSelected, llListFindList(g_lSelected, [CardNum]), llListFindList(g_lSelected, [CardNum]));
|
||||
} else{
|
||||
|
||||
if(llGetListLength(g_lSelected) == g_iSelectNum){
|
||||
s("You already have "+(string)g_iSelectNum+" selected cards. Deselect one before changing your selection");
|
||||
return;
|
||||
}
|
||||
g_lSelected += CardNum;
|
||||
}
|
||||
Highlight();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
state detach
|
||||
{
|
||||
state_entry(){
|
||||
integer i=0;
|
||||
integer end = llGetNumberOfPrims();
|
||||
for(i=1;i<=end;i++){
|
||||
llSetLinkPrimitiveParamsFast(i,[PRIM_SIZE,ZERO_VECTOR,PRIM_POS_LOCAL,ZERO_VECTOR,PRIM_ROT_LOCAL,ZERO_ROTATION]);
|
||||
}
|
||||
llSleep(2);
|
||||
llRequestPermissions(g_kUser,PERMISSION_ATTACH);
|
||||
}
|
||||
|
||||
run_time_permissions(integer p){
|
||||
if(p&PERMISSION_ATTACH){
|
||||
llDetachFromAvatar();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue