Jump to content
The Dark Mod Forums

games-furious

Member
  • Posts

    24
  • Joined

  • Last visited

Posts posted by games-furious

  1. i wish now can write the health of monsters when hited may be can use with scriptEvent entity getAttacker() ? using threads may be?

    but in my doubt in entityDef can be write the params in runtime? example is

    "inv_name" "Hited! cb_demon health is monster_boss_cyber_demon_1.getHealth()"

    or any idea how can i write on the screen the message?

    thanks

  2. Yes if you read the idtech 4 wiki https://modwiki.dhewm3.org/Scripting_basics

     

    this is what it says about script namespaces

     

     

     

     

     

     

    Have you included your map script inside the doom_main.script? Also see above how to access functions inside a namespace, I would also recommend that you read about OOP (object oriented programing) because doom script follows c++ OOP rules.

     

    no not added my map inside doom_main.script yet. i include many scripts inside my map.script working like threads this scripts not working like mods but only for my map.
  3.  

    You are certainly right and that was how idSoftware did it and that should be what he should ultimally use, what I said was just because for some reason that was not working for him. You can also use the "pointer" symbol $ for any entity that exist in the map.

     

    But in my defence, i'm sure you know the base for all classes in the engine is idEntity including the idActor class from where the player is based so sys.getEntity should work even for the player.

     

    The kill script function is really for idAI like monsters and stuff, so i assume it doesn't work for the player, you can kill the player with a cvar so you could try that, call the console cmd "kill" that will kill the player instantly no matter what health value he has.

     

    Btw the player is one of the entities where most of its functionality is handled in c++ not by script, so some things you will be able to do only by editing the source code i'm afraid.

     

    Don't know if this will work but try it.

     

    sys.setcvar( "kill", "1" );

     

    sys.setcvar make nothing

     

    like i said if possible got real health o player1 i think is possible setHealth but for now got only health = 0 with player1 and in HUD appear 100 lol

  4. void main () {         
    sys.waitFrame(); // always wait one frame before doing anything in main()
    // this ensures that the init() routines have all finished

    sys.wait(100); // wait 100 seconds

    /* $entityName here acts upon a specific entity. Be careful, if you rename
    the entity in DR, your script will break! $player1 is the player entity,
    and this only works in single player mode. However, there is no multiplayer
    in TDM, so we can safely use it for now: */

    // put some information in the console
    sys.println("Going to kill the entity " + $player1.getName() );

    $player1.kill(); // kill the player
    }
  5. I just made a test with script here from darkmod but i put $player1 and not work after $info_player_start_1 and nothing.

    If possible help me. please.

     

    Create the script file

    If your map is called for example maps/mydir/mymap.map, you must create a text file maps/mydir/mymap.script.

     

    The contents

    The map script needs to contain a main function. This function is called at the very start of your map, e.g. when the map is loaded for the first time. So if you want something to happen later, you need to pause the script and then do something. Here is an example:

  6. No problem glad to help.

     

    Btw sorry if you already know this but Imo global variables are "evil", they can cause all sort of very hard to debug bugs, because they are accessible anywhere in the code (in the same namespace or compilation unit...c++ jargon), even outside the file they are written, so they can clash with variables defined in other script files (if the script is included in some other script) and cause havoc but they do work for stuff like that.

     

    If you don't want that to happen, you can use for map scripts:

     

    namespace my_map{

    //put map code here

    }

     

    For object scripts use old c preprocessor technique

     

    #ifndef __MYCODE__

    #define __MYCODE__

     

    Put your code here

     

    #endif // __MYCODE__

    in this case you tell for i write like this?

     

    namespace my_map{
      //put map code here
      float killed;
        
         void kill_player()
         {
          code
             ......
              ..........
                ...............
          code
     
         }
    
    }
  7. I find this may be if possible use global variable then killed can be update everytime when void function started and health < = 0 look image but editor can compile #include <iostream> ???? or if anybody have a sugestion how use global variable with scripts please post.thanks

     

    SOLVED! I just put variable out of Void then it work like Global Map Variable very good

    Now i can SUM monsters for make one map for ARCADE style for kill monsters in limit of TIME if example kills 20 monsters in 5 minutes you won if you dont you lose kill player and go to restart current level ;)

    float killed;  // here variable work like Global Map variable then will increment ++ inside void player( ) when monster killed
     
    void kill_player()
    {
      code
      ......
      ..........
      ...............
      code
     
    }

    thanks for all replies here help me a lot =D

     

     

    • Like 1
  8. but this is solved thanks the problem now is how increment and save value in var float killed.Like i said i using a trigger multiple for restart function then all values except time by sys.getTime() the value update everytine sure.

    Hum thanks for the info, that is good to know, I code on c++ for the most part so some scripting things are lost to me.

     

     

     

     

    My bad I code on my idtech 4 game 99.9% of the time in c++, i've been pretty much neglecting Doom script for years now (I can do more stuff in c++ anyway), so I just forget how script works sometimes, sorry for that.

     

    That error happens because entity type is not the same as a float type and that is totally right. In c++ you can cast a type to another but script is more restrict, for ease of use.

     

    It should have been:

     

    if (new_monster) // or even if(new_monster != $null_entity)}      if(new_monster.getHealth( ) < 1))      {         killed += 1;         string myStr = new_monster.getKey("name");         myStr = "The name of zombie_fat is " + myStr + "killed = "  + killed +  "\n";         sys.println(myStr);   // Print the text to the console      }}
    but this is solved thanks the problem now is how increment and save value in var float killed.Like i said i using a trigger multiple for restart function then all values reseted, except time var float t by sys.getTime() the value update everytine sure.
  9. void kill_player() // is for enemy single player in this case
    {

    //sys.waitFrame();
    float t;
    float killed;

    //$player1.setKey("health", "0.0");
    //float killed = 0;
    t = sys.getTime();
    sys.print(t);
    //float zombie_health = new_monster.getFloatKey("health");
    //sys.println("health is " + zombie_health + "\n");
    //sys.println("health by getHealth is " + $monster_zombie_fat_3.getHealth() + "\n");
    if (t > 5)
    {
    //Code for spawn enemies Wherever you wish on the map


    entity new_monster;
    sys.setSpawnArg("name", "monster_zombie_fat_3"); // set spawnarg before spawning the entity
    new_monster = sys.spawn("monster_zombie_fat"); // example monster_zombie_fat or any class enemy name
    new_monster.setOrigin('-136 -120 11');

    //sys.println("health is " + zombie_health + "\n");
    //sys.println("health by getHealth is " + $monster_zombie_fat_3.getHealth() + "\n");

    entity spawn_effects = sys.spawn("func_fx");
    spawn_effects.setOrigin('-136 -120 11');
    spawn_effects.startFx("fx/teleporter");
    //float health = $monster_zombie_fat_3.getHealth();

    sys.wait(10); // not good have a time limit for kill zombie or never will print value to console


    if ($monster_zombie_fat_3.getHealth() <= 0){
    killed += 1; // ERROR ONLY UPTADE FROM 0 TO 1 everytime i triggered function call
    string myStr = new_monster.getKey("name");
    myStr = "The name of zombie_fat is " + myStr + " killed = " + killed + " HEALTH is " + $monster_zombie_fat_3.getHealth() + "\n";
    sys.println(myStr); // Print the text to the console
    }

    }

    }
  10. THIS CODE WORK but only with sys.wait(10) i need kill zombie before time wait 10 or i lost time to write a values to variables.

     

    But another problem is killed update only from 0 to 1 everytime. The function is restarted by trigger multiple then every values reseted. I need storage this values

    for used in game in this case de killed variable

     

    Need may be storage in cfg for get value of variable killed but how make this?

  11.  

     

     

    Are you sure the line monster = sys.getEntity("monster_name"); returned a valid entity? For that code to work the monster has to already be spawned in the game.

     

    If there's no valid entity or valid health value, the code example i gave initializes mhealth to zero ( afaik script engine does that even if you don't), so because of the way the if block makes the test it will be always true.

     

    Btw truth be told I never really worked with AI before, i'm not sure if the health value in the def file is a static value or a value that gets updated each time the monster is hurt, so i'm not really sure if doing it the way I posted is the correct way.

     

     

    Also I looked at the c++ AI source code for the script function getHealth(); and afaik it should work. Behind the scenes it returns the health variable defined in all entities classes in c++.

    /*
    =====================
    idAI::Event_SetHealth
    =====================
    */
    void idAI::Event_SetHealth( float newHealth ) {
    	health = newHealth;
    	fl.takedamage = true;
    	if ( health > 0 ) {
    		AI_DEAD = false;
    	} else {
    		AI_DEAD = true;
    	}
    }
    
    /*
    =====================
    idAI::Event_GetHealth
    =====================
    */
    void idAI::Event_GetHealth( void ) {
    	idThread::ReturnFloat( health );
    }
    

    So if it is not working you must be doing something wrong, perhaps you are spawning the monster in the wrong way? You could try seeing how idsoftwared scripted their monsters by looking at their scripts, is the way I learned many stuff about this engine.

     

    Try this code.

    t = sys.getTime();
    sys.print(t);
    if (t > 5)
    {
      //Code for spawn enemies Wherever you wish on the map 
      float killed = 0.0;
      
      sys.wait(1.8);
     
      entity new_monster;
      sys.setSpawnArg("name", "monster_zombie_fat_3"); // set spawnarg before spawning the entity
      new_monster = sys.spawn("monster_zombie_fat");
      new_monster.setOrigin('-136 -120 11');
      
      if (new_monster && (new_monster.getHealth( ) < 1)){
             killed += 1;
             string myStr = new_monster.getKey("name");
             myStr = "The name of zombie_fat is " + myStr + "killed = "  + killed +  "\n";
             sys.println(myStr);   // Print the text to the console
       }
    }
    

    your code dont work get type mismatch error for ---> if (new_monster && (new_monster.getHealth( ) < 1)) // then a put just if (new_monster.getHealth( ) and nothing happning

     

    everytime the value is 0 dont get by run time

     

     

    with this code in main ( ) or call triger function i got the first value of health 100 but he dont uptade decrease when zombie hited. THE problem now s how update value in runtime?

     

    void main()
      {
     
       sys.waitFrame();
       /*  float killed = 0;
       float mhealth;
       
       
       
       sys.println("zombie health  " + mhealth + "\n");   
      
       sys.wait(20);
        
          
       entity new_monsterz = sys.getEntity("monster_zombie_fat_3");
       mhealth = new_monsterz.getFloatKey("health");
       sys.println("zombie health  " + mhealth + "\n");
       if (mhealth > 50.0){
    sys.println("new_monsterz DEAD!");
    }
       
       if (mhealth > 50.0){
    killed += 1;
         string myStr = new_monsterz.getKey("name");   // Retrieve the value of the "name" spawnarg of the player entity
             myStr = "The zombie_fat " + myStr + "is killed = " + killed + "\n";
             sys.println(myStr);   // Print the text to the console
        }  */
       
        sys.wait(10);
        entity new_monster;
        sys.setSpawnArg("name", "monster_zombie_fat_3"); // set spawnarg before spawning the entity
        new_monster = sys.spawn("monster_zombie_fat"); // example monster_zombie_fat or any class enemy name
        new_monster.setOrigin('-136 -120 11');
        float zombie_health = new_monster.getFloatKey("health");
        sys.println("health is " + zombie_health + "\n");
        float killed = 0;
        if (zombie_health <= 0){
              killed += 1;
              string myStr = new_monster.getKey("name");
              myStr = "The name of zombie_fat is " + myStr + " killed = "  + killed +  " HEALTH is " + zombie_health +  "\n";
              sys.println(myStr);   // Print the text to the console
         }
     
     
    }

     

  12.  

     

    Are you sure the line monster = sys.getEntity("monster_name"); returned a valid entity? For that code to work the monster has to already be spawned in the game.

     

    If there's no valid entity or valid health value, the code example i gave initializes mhealth to zero ( afaik script engine does that even if you don't), so because of the way the if block makes the test it will be always true.

     

    Btw truth be told I never really worked with AI before, i'm not sure if the health value in the def file is a static value or a value that gets updated each time the monster is hurt, so i'm not really sure if doing it the way I posted is the correct way.

     

     

    Also I looked at the c++ AI source code for the script function getHealth(); and afaik it should work. Behind the scenes it returns the health variable defined in all entities classes in c++.

    /*
    =====================
    idAI::Event_SetHealth
    =====================
    */
    void idAI::Event_SetHealth( float newHealth ) {
    	health = newHealth;
    	fl.takedamage = true;
    	if ( health > 0 ) {
    		AI_DEAD = false;
    	} else {
    		AI_DEAD = true;
    	}
    }
    
    /*
    =====================
    idAI::Event_GetHealth
    =====================
    */
    void idAI::Event_GetHealth( void ) {
    	idThread::ReturnFloat( health );
    }
    

    So if it is not working you must be doing something wrong, perhaps you are spawning the monster in the wrong way? You could try seeing how idsoftwared scripted their monsters by looking at their scripts, is the way I learned many stuff about this engine.

     

    Try this code.

    t = sys.getTime();
    sys.print(t);
    if (t > 5)
    {
      //Code for spawn enemies Wherever you wish on the map 
      float killed = 0.0;
      
      sys.wait(1.8);
     
      entity new_monster;
      sys.setSpawnArg("name", "monster_zombie_fat_3"); // set spawnarg before spawning the entity
      new_monster = sys.spawn("monster_zombie_fat");
      new_monster.setOrigin('-136 -120 11');
      
      if (new_monster && (new_monster.getHealth( ) < 1)){
             killed += 1;
             string myStr = new_monster.getKey("name");
             myStr = "The name of zombie_fat is " + myStr + "killed = "  + killed +  "\n";
             sys.println(myStr);   // Print the text to the console
       }
    }
    

    your code dont work get type mismatch error for ---> if (new_monster && (new_monster.getHealth( ) < 1)) // then a put just if (new_monster.getHealth( ) and nothing happning

     

    everytime the value is 0 dont get by run time

  13. How do you run your script? As far as I know, you need a function that calls the script. If you can set an "on death: run script" for the zombie, you can skip the condition with the health check and simply use the remaining part that counts and prints the "killed" value.

    i run script by trigger multiply key/val call / function_name and with key/val wait / 20 condition then if triggered, spawn class name, the zombies dont exist in map like monster_zombie_fat_1, monster_zombie_fat_2,... using this method for performance using script to spawn.I need real value of health for count real zombie killed's

  14. The monster health is saved in his def file so you can get the value using something like &entity.getFloatKey("health");

     

     

     

    Or:

     

    float mhealth = 0.0;entity monster = sys.getEntity("monster_name");if(monster){     mhealth = monster.getFloatKey("health");}if( mhealth <= 0.0){    println("Monster DEAD!!");}
    dont work for mhealth got every time 0 print Monster Dead! with zombie live i see dont get real value o health
  15. The monster health is saved in his def file so you can get the value using something like &entity.getFloatKey("health");

    thanks for reply i go try this first.

    Just you got this getFloatKey("health") from monster_.....def ?

     

    Or:

     

    float mhealth = 0.0;entity monster = sys.getEntity("monster_name");if(monster){     mhealth = monster.getFloatKey("health");}if( mhealth <= 0.0){    println("Monster DEAD!!");}
  16. As I read this, if it runs in the first 5 seconds after map load it does nothing; if it runs later, it spawns a zombie, immediately checks whether it has health, and does nothing unless the zombie has spawned with no health. Is that what you wanted, or are you trying to check for when the zombie has been killed?

    look i need know a health value of zombie spawned by script then if got 0 write to console zombie Killed 1, 2, 3....

    this zombie have a default health 125 when spawned

     

    but the event float getHealth( ) is not working dont get error on console but dont get value lol.

  17. I,m trying getHealth () from enemy with script but without sucess. If possible help me


    t = sys.getTime();
    sys.print(t);
    if (t > 5)
    {
    //Code for spawn enemies Wherever you wish on the map
    float killed = 0.0;

    sys.wait(1.8);


    entity new_monster = sys.spawn("monster_zombie_fat"); // example monster_zombie_fat or any class enemy name
    new_monster.setKey("name", "monster_zombie_fat_3");
    new_monster.setOrigin('-136 -120 11');

    if ($monster_zombie_fat_3.getHealth( ) < 1){ // Not Working cant get value of health
    killed += 1;
    string myStr = new_monster.getKey("name"); // Retrieve the value of the "name" spawnarg of the player entity
    myStr = "The name of zombie_fat is " + myStr + "killed = " + killed + "\n";
    sys.println(myStr); // Print the text to the console
    }
    }
  18. i try give me error

    Unknown value "startFX"

     

    I write startFX and correct is startFx then used with referenced class name func_fx then work. thanks a lot

     

    code
    if (t > 5){  //Code for spawn enemies Wherever you wish on the map     sys.wait(1.8);     entity new_monster = sys.spawn("monster_zombie_fat"); // example monster_zombie_fat or any class enemy name  new_monster.setKey("name", "monster_zombie_fat_3");      new_monster.setOrigin('-136 -120 11');  entity spawn_effects = sys.spawn("func_fx");  spawn_effects.setOrigin('-136 -120 11');  spawn_effects.startFx("fx/teleporter");      sys.wait(1.8);    entity new_monster2 = sys.spawn("monster_demon_imp"); // example monster any class enemy name  new_monster2.setOrigin('-136 -50 11');  spawn_effects.setOrigin('-136 -50 11');  spawn_effects.startFx("fx/teleporter");    string myStr = new_monster.getKey("name");   // Retrieve the value of the "name" spawnarg of the player entity      myStr = "The name of zombie_fat is " + myStr + "\n";      sys.println(myStr);   // Print the text to the console  t = 0; }

     

    • Like 1
×
×
  • Create New...