integer g_iStartParam; key g_kUser; key g_kTable; key g_kActualTable; integer DEBUG=FALSE; 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; if(DEBUG)llSay(0, "CARD LIST: "+llDumpList2String(g_lCards, " - ")); for(x=0;x x){ string card_params = llList2String(g_lCards,x); if(DEBUG)llSay(0,"Card Parameters: "+card_params); 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)CardsToRequest=1; if(CardsToRequest == 0)return; else { llOwnerSay("Drawing "+(string)CardsToRequest+" cards"); llRegionSayTo(g_kActualTable,hud_channel, llList2Json(JSON_OBJECT, ["type","card_request","count", CardsToRequest])); } } } integer g_iVis=0; POS(){ if(!llGetAttached())return; g_iVis=1; vector local = <0.02395, 0.47113, -0.15166>; llSetPrimitiveParams([PRIM_POS_LOCAL, local]); } POS2(){ if(!llGetAttached())return; g_iVis=0; 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(DEBUG)llSay(0, 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"]); g_kActualTable = i; 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"])); Cards(); } } } else if(llJsonGetValue(m,["type"]) == "select"){ if(g_kTable != (key)llJsonGetValue(m,["table"]))return; if(llJsonGetValue(m,["czar"]) == (string)g_kUser){ s("You are the Card Czar, hiding the HUD"); POS2(); g_iCanSelect=0; Cards(); } 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"){ if(g_kTable != (key)llJsonGetValue(m,["table"]))return; 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"){ if(DEBUG)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