Problème de quiche : le compteur

Répondre
Partager Rechercher
Code PHP:

int nCount GetLocalInt(TIREUR,"NOMBRELANCER");
int nAppelePar GetUserDefinedEventNumber();
void main()
{
switch(
nAppelePar)
 {
 case 
1001//appelle le nombre de fois lance.
 
ActionSpeakString("Le score est de"+IntToString(nCount)+"lances.");
 break;
 }

Je fais les cours de scripts pour les quiches et j'ais donné ce scripts au compteur, seulement je ne sais pas si j'ai le droit de récupérer la variable nCount à partir d'un autre personnage - ici le lanceur, qui apour Tag TIREUR - Il me met without type. Si vous pouviez m'indiquer comment récupérer le variable NOMBRELANCER qui se trouve dans un scripts accroché au TIREUR par OBJECT_SELF (est-ce la que ça coince ?), ce serait très très sympa. surtout ne me donnez pas d'autres infos : juste ça. Je veux trouver la solution seul.

Merci d'avance
Ba dans le script que tu donnes, la variable TIREUR n'est pas initialisé.
Si l'évènement est déclenché par le tireur lui même, OBJECT_SELF a la place de TIREUR devrai permettre la compilation
Sinon, il te faut recuperer l'objet "TIREUR" le plus proche pour l'utiliser a la place ...

(j'avoue quand même avoir du mal a suivre ton explication )
Ca marche toujours pas !!!
Je te donnes mes scripts j'esplique mal et je débute...
Voici le On Spawn du tireur :
Code PHP:

// objects oSupr = GetLinesDeletedByMe() -lol-
void main()
{
SetLocalInt(OBJECT_SELF"NOMBRELANCER",0);
SetLocalInt(OBJECT_SELF,"ETATCIBLE",1);
// OPTIONAL BEHAVIORS (Comment In or Out to Activate ) ****************************************************************************
     //SetSpawnInCondition(NW_FLAG_SPECIAL_CONVERSATION);
     //SetSpawnInCondition(NW_FLAG_SPECIAL_COMBAT_CONVERSATION);
                // This causes the creature to say a special greeting in their conversation file
                // upon Perceiving the player. Attach the [NW_D2_GenCheck.nss] script to the desired
                // greeting in order to designate it. As the creature is actually saying this to
                // himself, don't attach any player responses to the greeting.

     //SetSpawnInCondition(NW_FLAG_SHOUT_ATTACK_MY_TARGET);
                // This will set the listening pattern on the NPC to attack when allies call
     //SetSpawnInCondition(NW_FLAG_STEALTH);
                // If the NPC has stealth and they are a rogue go into stealth mode
     //SetSpawnInCondition(NW_FLAG_SEARCH);
                // If the NPC has Search go into Search Mode
    
SetSpawnInCondition(NW_FLAG_SET_WARNINGS);
                
// This will set the NPC to give a warning to non-enemies before attacking

     //SetSpawnInCondition(NW_FLAG_SLEEP);
                //Creatures that spawn in during the night will be asleep.
     //SetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING);
     //SetSpawnInCondition(NW_FLAG_APPEAR_SPAWN_IN_ANIMATION);
     //SetSpawnInCondition(NW_FLAG_IMMOBILE_AMBIENT_ANIMATIONS);
     //SetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS);
                //This will play Ambient Animations until the NPC sees an enemy or is cleared.
                //NOTE that these animations will play automatically for Encounter Creatures.

    // NOTE: ONLY ONE OF THE FOLOOWING ESCAPE COMMANDS SHOULD EVER BE ACTIVATED AT ANY ONE TIME.
    //SetSpawnInCondition(NW_FLAG_ESCAPE_RETURN);    // OPTIONAL BEHAVIOR (Flee to a way point and return a short time later.)
    //SetSpawnInCondition(NW_FLAG_ESCAPE_LEAVE);     // OPTIONAL BEHAVIOR (Flee to a way point and do not return.)
    //SetSpawnInCondition(NW_FLAG_TELEPORT_LEAVE);   // OPTIONAL BEHAVIOR (Teleport to safety and do not return.)
    //SetSpawnInCondition(NW_FLAG_TELEPORT_RETURN);  // OPTIONAL BEHAVIOR (Teleport to safety and return a short time later.)

// CUSTOM USER DEFINED EVENTS
/*
    The following settings will allow the user to fire one of the blank user defined events in the NW_D2_DefaultD.  Like the
    On Spawn In script this script is meant to be customized by the end user to allow for unique behaviors.  The user defined
    events user 1000 - 1010
*/
    
SetSpawnInCondition(NW_FLAG_HEARTBEAT_EVENT);        //OPTIONAL BEHAVIOR - Fire User Defined Event 1001
    //SetSpawnInCondition(NW_FLAG_PERCIEVE_EVENT);         //OPTIONAL BEHAVIOR - Fire User Defined Event 1002
    //SetSpawnInCondition(NW_FLAG_ATTACK_EVENT);           //OPTIONAL BEHAVIOR - Fire User Defined Event 1005
    //SetSpawnInCondition(NW_FLAG_DAMAGED_EVENT);          //OPTIONAL BEHAVIOR - Fire User Defined Event 1006
    //SetSpawnInCondition(NW_FLAG_DISTURBED_EVENT);        //OPTIONAL BEHAVIOR - Fire User Defined Event 1008
    //SetSpawnInCondition(NW_FLAG_END_COMBAT_ROUND_EVENT); //OPTIONAL BEHAVIOR - Fire User Defined Event 1003
    //SetSpawnInCondition(NW_FLAG_ON_DIALOGUE_EVENT);      //OPTIONAL BEHAVIOR - Fire User Defined Event 1004
    //SetSpawnInCondition(NW_FLAG_DEATH_EVENT);            //OPTIONAL BEHAVIOR - Fire User Defined Event 1007

// DEFAULT GENERIC BEHAVIOR (DO NOT TOUCH) *****************************************************************************************
    
SetListeningPatterns();    // Goes through and sets up which shouts the NPC will listen to.
    
WalkWayPoints();           // Optional Parameter: void WalkWayPoints(int nRun = FALSE, float fPause = 1.0)
                               // 1. Looks to see if any Way Points in the module have the tag "WP_" + NPC TAG + "_0X", if so walk them
                               // 2. If the tag of the Way Point is "POST_" + NPC TAG the creature will return this way point after
                               //    combat.
    
GenerateNPCTreasure();     //* Use this to create a small amount of treasure on the creature

Son User Defined

Code PHP:

void main()
{
int nAppelePar GetUserDefinedEventNumber();
object oCible GetNearestObjectByTag("CIBLE");
int nCiblePrete GetLocalInt(OBJECT_SELF,"ETATCIBLE");
int nCount GetLocalInt(OBJECT_SELF,"NOMBRELANCER");
//
switch(nAppelePar)
 {
 case 
1001//appele par OHB
 //
 //nCiblePete est a 1 si cible est prete
 //
 
if((GetIsObjectValid(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND)))
 &&(
nCiblePrete==1))
  {
  
ClearAllActions();
  
ActionAttack(oCible,TRUE);
  }
  else
  {
  if(
nCiblePrete==1)
   {
   
SetLocalInt(OBJECT_SELF,"ETATCIBLE",2);
   
ActionMoveToObject(oCible);
   
ActionWait(0.5);
   
nCount nCount+1;
   
ActionPlayAnimation(ANIMATION_LOOPING_GET_MID,1.0,1.0);
   
ActionWait(0.5);
   
nCount nCount+1;
   
ActionPlayAnimation(ANIMATION_LOOPING_GET_MID,1.0,1.0);
   
ActionWait(0.5);
   
nCount nCount+1;
   
ActionPlayAnimation(ANIMATION_LOOPING_GET_MID,1.0,1.0);
   
object oDestination GetNearestObjectByTag("CIBLEWP001");
   
ActionMoveToObject(oDestination);
   
CreateItemOnObject("nw_wthdt001",OBJECT_SELF,3);
   
ActionEquipMostDamagingRanged();
   
ActionDoCommand(SetLocalInt(OBJECT_SELF,"ETATCIBLE",1));
   }
  }
  break;
 }

Le on Spawn du compteur :

Code PHP:

//oSupr
void main()
{
// OPTIONAL BEHAVIORS (Comment In or Out to Activate ) ****************************************************************************
     //SetSpawnInCondition(NW_FLAG_SPECIAL_CONVERSATION);
     //SetSpawnInCondition(NW_FLAG_SPECIAL_COMBAT_CONVERSATION);
                // This causes the creature to say a special greeting in their conversation file
                // upon Perceiving the player. Attach the [NW_D2_GenCheck.nss] script to the desired
                // greeting in order to designate it. As the creature is actually saying this to
                // himself, don't attach any player responses to the greeting.

     //SetSpawnInCondition(NW_FLAG_SHOUT_ATTACK_MY_TARGET);
                // This will set the listening pattern on the NPC to attack when allies call
     //SetSpawnInCondition(NW_FLAG_STEALTH);
                // If the NPC has stealth and they are a rogue go into stealth mode
     //SetSpawnInCondition(NW_FLAG_SEARCH);
                // If the NPC has Search go into Search Mode
    //SetSpawnInCondition(NW_FLAG_SET_WARNINGS);
                // This will set the NPC to give a warning to non-enemies before attacking

     //SetSpawnInCondition(NW_FLAG_SLEEP);
                //Creatures that spawn in during the night will be asleep.
     //SetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING);
     //SetSpawnInCondition(NW_FLAG_APPEAR_SPAWN_IN_ANIMATION);
     //SetSpawnInCondition(NW_FLAG_IMMOBILE_AMBIENT_ANIMATIONS);
     //SetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS);
                //This will play Ambient Animations until the NPC sees an enemy or is cleared.
                //NOTE that these animations will play automatically for Encounter Creatures.

    // NOTE: ONLY ONE OF THE FOLOOWING ESCAPE COMMANDS SHOULD EVER BE ACTIVATED AT ANY ONE TIME.
    //SetSpawnInCondition(NW_FLAG_ESCAPE_RETURN);    // OPTIONAL BEHAVIOR (Flee to a way point and return a short time later.)
    //SetSpawnInCondition(NW_FLAG_ESCAPE_LEAVE);     // OPTIONAL BEHAVIOR (Flee to a way point and do not return.)
    //SetSpawnInCondition(NW_FLAG_TELEPORT_LEAVE);   // OPTIONAL BEHAVIOR (Teleport to safety and do not return.)
    //SetSpawnInCondition(NW_FLAG_TELEPORT_RETURN);  // OPTIONAL BEHAVIOR (Teleport to safety and return a short time later.)

// CUSTOM USER DEFINED EVENTS
/*
    The following settings will allow the user to fire one of the blank user defined events in the NW_D2_DefaultD.  Like the
    On Spawn In script this script is meant to be customized by the end user to allow for unique behaviors.  The user defined
    events user 1000 - 1010
*/
   
SetSpawnInCondition(NW_FLAG_HEARTBEAT_EVENT);        //OPTIONAL BEHAVIOR - Fire User Defined Event 1001
    //SetSpawnInCondition(NW_FLAG_PERCIEVE_EVENT);         //OPTIONAL BEHAVIOR - Fire User Defined Event 1002
    //SetSpawnInCondition(NW_FLAG_ATTACK_EVENT);           //OPTIONAL BEHAVIOR - Fire User Defined Event 1005
    //SetSpawnInCondition(NW_FLAG_DAMAGED_EVENT);          //OPTIONAL BEHAVIOR - Fire User Defined Event 1006
    //SetSpawnInCondition(NW_FLAG_DISTURBED_EVENT);        //OPTIONAL BEHAVIOR - Fire User Defined Event 1008
    //SetSpawnInCondition(NW_FLAG_END_COMBAT_ROUND_EVENT); //OPTIONAL BEHAVIOR - Fire User Defined Event 1003
    //SetSpawnInCondition(NW_FLAG_ON_DIALOGUE_EVENT);      //OPTIONAL BEHAVIOR - Fire User Defined Event 1004
    //SetSpawnInCondition(NW_FLAG_DEATH_EVENT);            //OPTIONAL BEHAVIOR - Fire User Defined Event 1007

// DEFAULT GENERIC BEHAVIOR (DO NOT TOUCH) *****************************************************************************************
    
SetListeningPatterns();    // Goes through and sets up which shouts the NPC will listen to.
    
WalkWayPoints();           // Optional Parameter: void WalkWayPoints(int nRun = FALSE, float fPause = 1.0)
                               // 1. Looks to see if any Way Points in the module have the tag "WP_" + NPC TAG + "_0X", if so walk them
                               // 2. If the tag of the Way Point is "POST_" + NPC TAG the creature will return this way point after
                               //    combat.
    
GenerateNPCTreasure();     //* Use this to create a small amount of treasure on the creature

Son user defined

Code PHP:

object oTireur GetNearestObjectByTag("TIREUR");
int nCount GetLocalInt(oTireur,"NOMBRELANCER");
int nAppelePar GetUserDefinedEventNumber();
void main()
{
switch(
nAppelePar)
 {
 case 
1001//appelle le nombre de fois lance.
 
ActionSpeakString("Le score est de"+IntToString(nCount)+"lances.");
 break;
 }

Je ne crois pas que les user defined et on spawn de la cible soit importants, non ? La cible fait **Thung** à chaque fois qu'elle est touchée. J'ai penser à mettre le nCount sur la cible à chaque fois qu'elle fait Thung le problème c'est que du coup si un pj l'attaque elle fera Thung aussi... Ou alors je la configure pour ne pas renvoyer nCount si c'est un autre que TIREUR qui l'attaque le problème c'est que ce n'est pas tout à fait ce qui est demandé... Et quitte à faire l'exercice, si je le fais pas dans les règles... J'ai supprimé dans ce post les longues lignes de Bioware pour que les scripts soient lisibles (celles qui ne sont pas essentielles et qu'on modifie rarement) j'espère que je n'ai pas mal fait mais sinon j'ai 12 267 caractère alors... Elles sont notées oSupr. Merci beaucoup de ton aide.


ps : tous les scripts sont compilés, mais le pnj compteur me met sans arrêt : 0 lancés. 0 lancés. J'en conclue que ce n'est pas une faute de typographie mais de logique. Je reste une quiche.
J'ai essayé de récupérer la variable dans le onSpawn, j'ai initialisé un object oTireur dans tous les scripts où il y avait OBJECT_SELF, et j'ai remplacé tous les objects Self par des oTireur. Maintenant, le tireur ne tire même plus Bwahhahha...
Ok c'est bon je l'ai retrouvé :
Code PHP:

// Script de « OnDamaged » : tm_cible_dm
// Script de Cible.
// Produit un "thunk" lorsqu’elle est touchée //
void main()
{
    if (
GetWeaponRanged(GetLastWeaponUsed(GetLastAttacker())))
    {
    
SpeakString("**Thunk**");
    }

L'idée est la suivante : tu veux dans un premier temps que ton c(omp|on)teur dise toutes les six secondes combien de fois le lanceur de fléchette a tiré au but, en tout.

Le plus simple c'est de modifier le OnDamaged ainsi :
Code PHP:

// Script de « OnDamaged » : tm_cible_dm
// Script de Cible.
// Produit un "thunk" lorsqu’elle est touchée //
void main()
{
    if (
GetWeaponRanged(GetLastWeaponUsed(GetLastAttacker())))
    {
    
SpeakString("**Thunk**");

    if( 
GetLastAttacker() == GetNearestObjectByTag"le tag du lanceur") )
    {
        
SetLocalIntGetObjectByTag"le tag du compteur" ), "nCount"GetLocalIntGetObjectByTag"le tag du compteur" ), "nCount" ) + );
    }
    }

Hum oui c'est du script de barbare, tu peux le désosser de façon à gagner en clarté...

Maintenant l'UDE du compteur, beaucoup plus facile à écrire :
Code PHP:

void main()
{
//mets les variables à l'intérieur du main(), sauf lorsque tu
//veux simuler une constante (c'est une convention)
int nCount GetLocalIntOBJECT_SELF"nCount");
int nAppelePar GetUserDefinedEventNumber();

switch(
nAppelePar)
 {
 case 
1001//appelle le nombre de fois lance.
 
ActionSpeakString("Le score est de"+IntToString(nCount)+"lancers réussis.");
 break;
 }

Voilà, ça devrait marcher, maintenant petit exercice supplémentaire : faire en sorte que le score soit remis à 0 toutes les 30 secondes (attention, c'est plus dur... ).
Heu ? N'oublie pas que je ne veux pas comptabiliser les dégâts faits par autre chose que le TIREUR en question... J'y ai pensé aussi mais je crois que ce n'est pas la consigne... Enfin bon.
Code PHP:

//Script brouillon demande correction fm_cible_dm
//By Ange Musicien
int nCount GetLocalInt(OBJECT_SELF,"NOMBRELANCER2");
object oTireur GetNearestObjectByTag("TIREUR");
object oAttack GetLastAttacker();
void main()
{
if((
GetWeaponRanged(GetLastWeaponUsed(GetLastAttacker())))
&&(
oAttack==oTireur))
 {
 
SpeakString("**Thung**");
 
nCount nCount+1;
 }
 else;
 {
 
SpeakString("**Tire pas sur moi, abruti de Joueur !**");
 }

Script écrit vite fait, désolé. Il y a sûrement des tonnes de fautes... Le onSpawn de la Cible est tout bête :
Code PHP:

//By Ange Musicien : fm_cible_os
void main()
{
SetLocalInt(OBJECT_SELF,"NOMBRELANCER2",0);

Voilà j'ai essayé de t'épargner du boulot en préfaisant un script possible....
C'est pas mal mais ça marche pas...

Tu as oublié de mettre à jour ta variable locale dans le OnDamaged de la cible : tu incrémente bien nCount mais tu ne le restocke pas dans le local int "NOMBRELANCER", donc aucun effet. (sinon j'aime bien la phrase alternative )

Par ailleurs le OnSpawn de la cible est inutile : lorsqu'on essaie de récupérer la valeur d'un local int non initialisé, la réponse est toujours 0 (à ce propos lit le vieux post que j'ai déterré).

Et puis c'est pas tout ça mais là tu me mets pas le script du compteur !!

Essaie donc l'exo que je t'ai donné, il est pas trop dur pourvu que tu comprenne un peu ce que tu fait.
Tu m'as pas donné un exo trop dur... Il suffit de mettre au même endroit de l'initualisation un script qui dit (je n'ai pas le temps, là, après demain j'essaierais) :

-Initialisation
-ActionWait(5)
-Execute script1
On attache deux scripts :

le premier
-nCount = 0
Wait..(5)
Execute SCript2

le deuxième :
nCount=0
Wait 5
Execute script1

Et hop on fait une boucle qui remets à zéro tous les 30 rounds. C'est schématique. C'est pas très très dur il m'a pas fallut 3 minutes. Par contre je sais pas renvoyer une variable j'ai oublié je vai pioché dans mes leçons de scripts pour les quiches. Mais ce soir j'ai encore 10 heures de boulot je vais me coucher à 4 heures pour me lever à 6h30. Donc je m'y met. Merci ! Pas la peine de répondre j'éditerais Mercredi pour que ce soit plus propre ti corrigeras alors.
Voui, c'est DelayCommand() pour retarder une fonction, attention ça ne fait pas 'attendre' l'ordi : ça retarde juste la fonction passé en paramètre.
Exemple :
Code PHP:

void main()
{
    
DelayCommand1.0fSpeakString"1" ) );
    
DelayCommand0.5fSpeakString"2" ) );
    
SpeakString"3" );

Contrairement à ce dont on pourrait avoir l'intuition, le PNJ va dire : "3" puis, après 0.5 s "2", puis après encore 0.5 s "1".
Donc faut faire attention.

De plus pour mon exo, nul besoin de faire un ExecuteScript() (encore moins avec deux scripts différents : un seul aurait suffit), vu que 30 est un multiple de 6 et qu'on utilise déjà le OHB, la solution la plus classique consisterait en un compteur sur le OHB qui déclencherait la remise à 0 toutes les 30 s.

On peut utiliser les DelayCommand( f, ExecuteScript() ), mais il est alors recommandé de se montrer prudent dans l'emploi des variables, étant donné qu'un DelayCommand() est consommateur de ressources en proportions du nombre de variables dans son script.

Si tu veux tu peux m'écrire les deux solutions !
Répondre

Connectés sur ce fil

 
1 connecté (0 membre et 1 invité) Afficher la liste détaillée des connectés