|
bon, j'ai fais sur commande (hu hu hu ) pour un poto cette après midi, pis comme ca marchait aps trop mal, me suis dit que j'allais le mettre ici tant qu'a faire, si ca peut servir
alors, c'est un "petit" script qui anime un peu une zone, genre une taverne, ou ds l'exemple un espèce de vente au enchères . . .
pour ceux qui commencent y a moyen d'adapter ca a n'importe quelle situation avec un minimum d'effort
c'est pas mal commenté, alors je n'en dis pas plus
il y en a un dans le onenter, et un autre à mettre dans le onexit
enjoy
onexit
void main() { object oPC = GetExitingObject(); if(GetIsPC(oPC)) //seulement si c un PC qui sors { int nNbPJ = GetLocalInt(GetArea(oPC), "NB_PJ"); nNbPJ --; SetLocalInt(GetArea(oPC), "NB_PJ", nNbPJ); //security truc if(nNbPJ <= 0) SetLocalInt(GetArea(oPC), "NB_PJ", 0); } }
on enter
//:://///////////////////////////////////////////// //:: Dialogue aleatoire //:: Copyright (c) Reyan ^_^ //::////////////////////////////////////////////// /* OnEnter on peut mettre autant de phrases qu'on veut, changer la frquence moyenne mais il faut prcisert le nb de phrases qu'on a mis y a celle des acheteurs, avec leur frequence celle des gardes avec leur frequences et celle du vendeur avec leurs frequence
comment ca marche : - mettre dans onenter -mettre le script associ dans le onexit -on peu rajouter autantde phrases possible que l'on veut il faut les separer par un "@" comme dans les exemples pour une mise en page plus clair regardez les exemple -il faut imperativement signaler le nb de phrases inscrites -il faut donner une frequence moyenne en secone -et une maximale de variation de frequence, inferieur a le frequence
-il faut spcifier le tag des acheteurs, qui ont tous le meme -de meme pour garde et vendeur
!!! il ne faut pas depasser les 510 caracteres en tout pour un type de PNJ toutes phrases comprises. */ //::////////////////////////////////////////////// //:: Created By: Reyan //:: Created On: 04/04/2003 //:://////////////////////////////////////////////
//declaration des fonction de dia void AchetSpeak(float fF, int nVar, object oArea, int nNbsAchet, string sAchet, string sTag); void GardSpeak(float fF, int nVar, object oArea, int nNbsGard, string sGard, string sTag); void VendSpeak(float fF, int nVar, object oArea, int nNbsVend, string sVend, string sTag);
string StrBefore(string sSource, string sPattern); string StrAfter(string sSource, string sPattern);
string GetStrNB(string sStr, int nNb);
void main() {
//::////////////////////////////////////////////// //:: Zone editable //::////////////////////////////////////////////// float fFsAchet = 4.0;//frequence moyenne en secondes acheteur int nVarAchet = 2; //variation de la frequence entre chaque, en seconde, inferieur a la frequence acheteur float fFsGard = 12.0;//frequence moyenne en secondes garde int nVarGard = 5; //variation de la frequence entre chaque, en seconde, inferieur a la frequence garde float fFsVend = 12.0;//frequence moyenne en secondes vendeur int nVarVend = 5; //variation de la frequence entre chaque, en seconde, inferieur a la frequence vendeur
string sTagAchet = "TAGDESACHETEURS"; //a modifier string sTagGard = "TAGDESGARDES"; //a modifier string sTagVend = "TAGDUVENDEUR"; //a modifier
//phrases de l'acheteur string sAchet = "Moi j'en prend !@"+ "A boire !@"+ "Comment ca va vieux !@"+ "bla bla bla bla@"+ ". . . le cours des bovins a ouall strit . . .@"+ "Vous connaissez celle du fou qui repeint son plafond ?@"+ "Mmm, qu'est ce qu'elle cache sous sa jupe celle la !@"+ "* baille *@"+ ". . . et alors la il lui dit . . .@"+ "J'ai plus d'inspiration pour les exemples . . .@"+ "C'est bon vous voyez coment faire ?@"+ "c marrant, c sense etre plus rp et y a des fautes partout . . ."; int nNbsAchet = 12; //nb de phrase des acheteurs
//prases des gardes string sGard = "Altes !@"+ "Rengez votre arme !@"+ "Dis donc, t'as vu Bart ? C'est lui qui doit me revlever . . .@"+ "Ah Ah AH !! Elle est bien bonne !@"+ "Chut, voila le sergent !@"+ "* s'ennui a mourir *@"; int nNbsGard = 6; //nb de phrase des gardes
//prases du vendeur string sVend = "500, nous avons 500 ici !@"+ "Pour la grose dame en verte avec les coliers ridicule la au troisieme rang !@"+ "* se dure le nez *@"+ "*Bam Bam Bam*@"+ "Adjuge au gnome rougeaud la bas !"; int nNbsVend = 5; //nb de phrase des vendeur
//::////////////////////////////////////////////// //:: fin de Zone editable //:://////////////////////////////////////////////
object oPC = GetEnteringObject(); if(GetIsPC(oPC)) { int nNbPJ = GetLocalInt(GetArea(oPC), "NB_PJ"); if(nNbPJ <= 0) { SetLocalInt(GetArea(oPC), "NB_PJ", 1); PrintString("lancement des fonctions"); AchetSpeak(fFsAchet, nVarAchet, GetArea(oPC), nNbsAchet, sAchet, sTagAchet); GardSpeak(fFsGard, nVarGard, GetArea(oPC), nNbsGard, sGard, sTagGard); VendSpeak(fFsVend, nVarVend, GetArea(oPC), nNbsVend, sVend, sTagVend); } else { nNbPJ++; SetLocalInt(GetArea(oPC), "NB_PJ", nNbPJ); } } }
//::////////////////////////////////////////////// //:: Fonctions //:://////////////////////////////////////////////
void AchetSpeak(float fF, int nVar, object oArea, int nNbsAchet, string sAchet, string sTag) { if(GetLocalInt(oArea, "NB_PJ") <= 0) return; //si y a peu personne, ca sert a rien de parler
object oPNJ = GetFirstObjectInArea(oArea); int i; while(GetIsObjectValid(oPNJ)) { if(GetTag(oPNJ) == sTag) i++; // on compte le nb de PNJ oPNJ = GetNextObjectInArea(oArea); } oPNJ = GetFirstObjectInArea(oArea); while((i>0) && GetIsObjectValid(oPNJ)) { if(GetTag(oPNJ) == sTag) { if(Random(i) == 0) //meme proba pour tt les PNJ { string sTalk = GetStrNB(sAchet, Random(nNbsAchet)+1); AssignCommand(oPNJ, SpeakString(sTalk)); //dit une phrase au hasard i=0; } i--; } oPNJ = GetNextObjectInArea(oArea); }
int nRdm = Random(nVar+1); float fF2 = fF; if(Random(2)) fF2 -= IntToFloat(nRdm); else fF2 += IntToFloat(nRdm);
DelayCommand(fF2, AchetSpeak( fF, nVar, oArea, nNbsAchet, sAchet, sTag)); return; }
void GardSpeak(float fF, int nVar, object oArea, int nNbsGard, string sGard, string sTag) { if(GetLocalInt(oArea, "NB_PJ") <= 0) return; //si y a peu personne, ca sert a rien de parler
object oPNJ = GetFirstObjectInArea(oArea); int i; while(GetIsObjectValid(oPNJ)) { if(GetTag(oPNJ) == sTag) i++; // on compte le nb de PNJ oPNJ = GetNextObjectInArea(oArea); } oPNJ = GetFirstObjectInArea(oArea); while((i>0) && GetIsObjectValid(oPNJ)) { if(GetTag(oPNJ) == sTag) { if(Random(i) == 0) //meme proba pour tt les PNJ { string sTalk = GetStrNB(sGard, Random(nNbsGard)+1); AssignCommand(oPNJ, SpeakString(sTalk)); //dit une phrase au hasard i=0; } i--; } oPNJ = GetNextObjectInArea(oArea); }
int nRdm = Random(nVar+1); float fF2 = fF; if(Random(2)) fF2 -= IntToFloat(nRdm); else fF2 += IntToFloat(nRdm);
DelayCommand(fF2, GardSpeak( fF, nVar, oArea, nNbsGard, sGard, sTag)); return; }
void VendSpeak(float fF, int nVar, object oArea, int nNbsVend, string sVend, string sTag) { if(GetLocalInt(oArea, "NB_PJ") <= 0) return; //si y a peu personne, ca sert a rien de parler
object oPNJ = GetFirstObjectInArea(oArea); int i; while(GetIsObjectValid(oPNJ)) { if(GetTag(oPNJ) == sTag) i++; // on compte le nb de PNJ oPNJ = GetNextObjectInArea(oArea); } oPNJ = GetFirstObjectInArea(oArea); while((i>0) && GetIsObjectValid(oPNJ)) { if(GetTag(oPNJ) == sTag) { if(Random(i) == 0) //meme proba pour tt les PNJ { string sTalk = GetStrNB(sVend, Random(nNbsVend)+1); AssignCommand(oPNJ, SpeakString(sTalk)); //dit une phrase au hasard i=0; } i--; } oPNJ = GetNextObjectInArea(oArea); }
int nRdm = Random(nVar+1); float fF2 = fF; if(Random(2)) fF2 -= IntToFloat(nRdm); else fF2 += IntToFloat(nRdm);
DelayCommand(fF2, VendSpeak( fF, nVar, oArea, nNbsVend, sVend, sTag)); return; }
string GetStrNB(string sStr, int nNb) { string sF; string sT = sStr; int i=1; while(i<=nNb) { sF = StrBefore(sT, "@"); sT = StrAfter(sT, "@"); i++; } return sF; }
//:://///////////////////////////////////////////// //:: Gestion avancee des chaines de caracteres //:: inc_strings.nss //:: Copyright (c) Althea 2002 //::////////////////////////////////////////////// /* Bibliotheques de fonction de traitement avance des chaines de caracteres. */ //::////////////////////////////////////////////// //:: Créé par : Tynril //:: Créé le : 21/09/2002 //::////////////////////////////////////////////// //---------------------------------------------------------------------------- // ACTUAL FUNCTION SOURCES
// FUNCTION: StrBefore // // Returns the portion of sSource which is before the first occurance of // sPattern. For example, Strbefore("Foo bar"," ") -> "Foo" // // If the pattern does not exist in the string, the entire string is returned. string StrBefore(string sSource, string sPattern) { int iMarker; string sResult;
// Sanity check! if ((sPattern == "") || (sSource == "")) return sSource;
iMarker = FindSubString(sSource,sPattern);
if (iMarker >= 0) { sResult = GetSubString(sSource,0,iMarker); } else { sResult = sSource; }
return sResult; }
// FUNCTION: StrAfter // // Returns the portion of sSource which is after the first occurance of // sPattern. For example, Strbefore("Foo bar"," ") -> "bar" // // If the pattern does not exist in the string, an empty string is returned. string StrAfter(string sSource, string sPattern) { int iMarker, iMarkerLength; string sResult;
// Sanity check! if ((sPattern == "") || (sSource == "")) return "";
iMarkerLength = GetStringLength(sPattern); iMarker = FindSubString(sSource,sPattern);
if (iMarker >= 0) { sResult = GetSubString(sSource,iMarker + iMarkerLength, GetStringLength(sSource) - (iMarker + iMarkerLength)); } else { sResult = ""; }
return sResult; }
si il y a des bugs, des commentaires, dans conseils, des mars, comme d'habitude je suis preneur
(j'avais pensé à un bug à un moment mais g oublié, donc bon . . .s'en est p-e bien truffé )
|