Advertisement
salahzar

Quiz Caccia al tesoro

May 2nd, 2013
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. string pass=""; //"1211"; // 1211"; // "" se è la prima tappa, nessuna password richiesta
  3. string nextpass="5688";
  4. string indovinello = "QUALE E' LA CAPITALE DELLA FRANCIA?";
  5. list risposte = [ "ROMA","*PARIGI","LONDRA" ];
  6. string indizio = "Il prossimo quiz lo trovi dietro i fiori verdi";
  7. list regali = [ "Oro","Argento","Bronzo" ]; // "" se non c'è
  8.  
  9. list uuids; // avatarid + tentativi + risultato
  10. integer indicegiusto;
  11.  
  12. integer ascolto;
  13. key avatar;
  14. string stato;
  15. integer listener=0;
  16. string occupato;
  17. string ipass;
  18.  
  19. list avatars;
  20.  
  21. integer found;
  22. integer tentativi;
  23. integer risultato;
  24.  
  25. mostra(string name)
  26. {
  27.     llSetText(llGetObjectName()+"\n ("+name+")",<1,1,1>,1);
  28. }
  29. faidomanda()
  30. {
  31.     mostra(occupato+" ?");
  32.    
  33.     string scelte=""; list bottoni=[];
  34.     integer i;
  35.     for(i=0;i<llGetListLength(risposte);i++)
  36.     {
  37.         string r=llList2String(risposte,i);
  38.         if(llGetSubString(r,0,0)=="*")
  39.         {
  40.             indicegiusto=i;
  41.             r=llGetSubString(r,1,-1);
  42.         }
  43.         scelte+="\n"+(string)(i+1)+":"+r;
  44.         bottoni+= [ (string)(i+1) ];
  45.     }
  46.    
  47.     llDialog(avatar,indovinello+scelte+"\n Tentativo: "+(string)(tentativi+1),bottoni,1);
  48.     stato="risposta";
  49.     llSetTimerEvent(30);
  50. }
  51. tastierino()
  52. {
  53.         llDialog(avatar,"Digita PWD\n<"+ipass+">", ["<+","0","<Invio>","1","2","3","4","5","6","7","8","9"], 1);
  54.         llSetTimerEvent(10);
  55.        
  56.         stato="chiave";
  57.    
  58. }
  59.  
  60. reset()
  61. {
  62.         llSetTimerEvent(0);
  63.         llListenRemove(listener);
  64.         listener=0;
  65.         mostra("");
  66.         stato="pronto";
  67.    
  68. }
  69. okayprossimoindizio()
  70. {
  71.         llDialog(avatar,"RISPOSTA GIUSTA!\nPROSSIMA PASS: "+nextpass+"\nPROSSIMO INDIZIO: \n"+indizio,["OK"],1);
  72.        
  73.         reset();
  74.  
  75. }
  76. default
  77. {
  78.     state_entry()
  79.     {
  80.         mostra("");
  81.         stato = "pronto";
  82.         llListen(100,"",llGetOwner(),"");
  83.     }
  84.     touch_start(integer count)
  85.     {
  86.         if(listener!=0) return;
  87.        
  88.         ipass="";
  89.        
  90.         avatar=llDetectedKey(0);
  91.        
  92.         found=llListFindList(uuids,[avatar]);
  93.         if(found>=0)
  94.         {
  95.             tentativi=llList2Integer(uuids,found+2);
  96.             risultato=llList2Integer(uuids,found+3);
  97.         }
  98.         else
  99.         {
  100.             tentativi=0;
  101.             risultato=0;
  102.             uuids+=[avatar,llDetectedName(0),0,0];
  103.             found=llGetListLength(uuids)-4;
  104.         }
  105.        
  106.         if(risultato==1)
  107.         {
  108.             okayprossimoindizio();
  109.             return;
  110.         }
  111.        
  112.        
  113.         occupato=llDetectedName(0);
  114.        
  115.         llListen(1,"",avatar,"");
  116.         if(pass=="")
  117.         {
  118.             faidomanda();
  119.            
  120.             return;
  121.         }
  122.         mostra(occupato+" ! ");
  123.         tastierino();
  124.     }
  125.     listen(integer channel, string name, key id, string str)
  126.     {
  127.         if(channel==100)
  128.         {
  129.             if(str=="RESET")
  130.             {
  131.                 llOwnerSay("Reset");
  132.                 llResetScript();
  133.                 return;
  134.             }
  135.             if(str=="LIST")
  136.             {
  137.                 integer i;
  138.                 for(i=0;i<llGetListLength(uuids);i+=4)
  139.                 {
  140.                     llOwnerSay(llList2String(uuids,i+1)+": Tentativi "+(string)llList2String(uuids,i+2)+" risultato "+(string)llList2String(uuids,i+3));
  141.                    
  142.                 }
  143.             }
  144.         }
  145.         if(stato=="chiave")
  146.         {
  147.             if(str=="<+"){
  148.                if(llStringLength(ipass)>0)
  149.                     if(llStringLength(ipass)==1) ipass="";
  150.                     else
  151.                         ipass=llGetSubString(ipass,0,-2);
  152.                
  153.                tastierino();
  154.                return;
  155.             }
  156.             if(str=="<Invio>")
  157.             {
  158.                 if(ipass==pass)
  159.                 {
  160.                     faidomanda();
  161.                     return;
  162.                 }
  163.                 else
  164.                 {
  165.                     mostra(occupato+" :(");
  166.                     llDialog(avatar,"NON E' LA PAROLA CHIAVE GIUSTA",["OK"],-1);
  167.                     reset();
  168.                     return;
  169.                    
  170.                 }
  171.             }
  172.             //llOwnerSay("chiave");
  173.             ipass=ipass+str;
  174.             tastierino();
  175.             return;
  176.         }
  177.         if(stato=="risposta"){
  178.             tentativi++;
  179.             if( (integer)(str) == indicegiusto+1)
  180.             {
  181.                 mostra(occupato+" :)");
  182.                
  183.                 string regalo=llList2String(regali,tentativi-1);
  184.                 if(regalo!="") {
  185.                     llSay(0,"Consegnato "+regalo+" a "+occupato);
  186.                     llGiveInventory(avatar,regalo);
  187.                 }
  188.                
  189.                 uuids=llListReplaceList(uuids,[avatar, occupato, tentativi, 1 ],found,found+3);
  190.                
  191.                 okayprossimoindizio();
  192.                 return;
  193.                
  194.             }
  195.             else {
  196.                 mostra(occupato+" :(");
  197.                 uuids=llListReplaceList(uuids,[avatar,occupato,tentativi, 0 ],found,found+3);
  198.                  llDialog(avatar,"RISPOSTA SBAGLIATA!\nPUOI RIPROVARE :)",["OK"],1);
  199.                 reset();
  200.                 return;
  201.             }
  202.         }
  203.     }
  204.     timer()
  205.     {
  206.         llDialog(avatar,"TEMPO SCADUTO",["OK"],1);
  207.         reset();
  208.     }
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement