News:

One Minute Game Review by The Happy Friar: https://ugetube.com/@OneMinteGameReviews
Also on Rumble: https://rumble.com/c/c-1115371

idTech 4 (aka Doom 3 tech) Discord Server! https://discord.gg/9wtCGHa

Main Menu

Another Material Question

Started by spamclark15, August 14, 2017, 11:27:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

argoon

#15
Quote from: bitterman on August 31, 2017, 11:44:12 AM
argoon thanks for your posts.

Сan I ask a few questions about example above?

1. What is the expression '#ifndef' (it's not about general purpose, it's about D3 scripting)?

2. If entity on the map have a scriptobject and init() as described above then it (init) will be start at start of level? IMO this is not typical behavior for level script wich must be placed in /maps, not in /script.

Those are called pre-processor keywords on c and c++, they are special keywords that are run before the script compiler, they are used by script engine to create macros and Global variables, etc. In this case i'm defining _LOOK_AT_  before compilation so any variable i put inside this script doesn't conflits with variables with the same name on other script files.  Is akin to using the:  "using namespace mapname" keyword for map scripts.

About the second question, this is not a map script, this is a object script and those go on the script folder, init() in a object script is just like constructors in c++, so any function inside init() will run at the exact moment the entity (object) spawns in the game, it can be at level start or not.

QuoteYou mention the entity and the map, but it's not a single entity but rather all instances of a material I need it to work on, and that's on any map.

object scripts run on any map the object exists, because they are called by the entities them self's at spawn time.

To know more about this i recommend that you guys read about OOP programming (Object Oriented Programming).   

spamclark15

Would love to learn more, but I'm already busy now studying something else. :|

I'm wondering what I should put in for "$entityName". I'm working with models/mapobjects/tablecart1ball, so would tablecart1ball be the entity name?

bitterman

#17
Btw when I try to replace 'while(1)' to 'eachFrame' (for level script) I get an error "Built-in function can't be used without an object".


Phrozo


Phrozo

Quote from: spamclark15 on August 31, 2017, 04:35:12 AM
models/mapobjects/tablecart1ball

This is the object that I want it to apply to. When you say player script, you mean doom_main.script? There's no player.script. Is this all 1 set of instructions or 2 ways of doing it?

That isn't a object, its a material. That script won't help you without one.

argoon

#20
Quote from: bitterman on September 01, 2017, 11:44:28 PM
Btw when I try to replace 'while(1)' to 'eachFrame' (for level script) I get an error "Built-in function can't be used without an object".

Hum I didn't knew that was locked to objects only, need to study why, I'm working on engine c++ so have not scripted any level for a while now.
I'm not near my computer tho so will see later, for now continue using while loop for level scripting as always, sorry.

Quote from: Phrozo on September 02, 2017, 09:13:35 AM
Try sys.eachFrame

sys is indeed a object but eachframe that I recommend is not a c++ function, callable by sys, is just a script macro made using #define, it is written at the bottom of the doom_defs.script if I'm recalling correctly.


Quote from: Phrozo on September 02, 2017, 09:35:16 AM
Quote from: spamclark15 on August 31, 2017, 04:35:12 AM
models/mapobjects/tablecart1ball

This is the object that I want it to apply to. When you say player script, you mean doom_main.script? There's no player.script. Is this all 1 set of instructions or 2 ways of doing it?

That isn't a object, its a material. That script won't help you without one.

Exactly my script needs to be assigned to a entity in the editor or on a def file, it has no knowledge of materials it will only change the yaw (rotation) of a object no matter the materials on its surface.



bitterman add a thought, I assume you're calling your map script from within the map folder, using the script with the map name next to the map file,  perhaps that is why it doesn't work, if you open the script folder you see Id software put map scripts there as well, and call them from the doom_main.script just like with objects. The difference with this method is that you need to enclose your script code inside a "use namespace mapname" or all function/variables names will conflict with each other.

spamclark15

Quote from: Phrozo on September 02, 2017, 09:35:16 AM
Quote from: spamclark15 on August 31, 2017, 04:35:12 AM
models/mapobjects/tablecart1ball

This is the object that I want it to apply to. When you say player script, you mean doom_main.script? There's no player.script. Is this all 1 set of instructions or 2 ways of doing it?

That isn't a object, its a material. That script won't help you without one.

So much for that...

argoon

Quote from: spamclark15 on September 03, 2017, 03:55:00 AM
Quote from: Phrozo on September 02, 2017, 09:35:16 AM
Quote from: spamclark15 on August 31, 2017, 04:35:12 AM
models/mapobjects/tablecart1ball

This is the object that I want it to apply to. When you say player script, you mean doom_main.script? There's no player.script. Is this all 1 set of instructions or 2 ways of doing it?

That isn't a object, its a material. That script won't help you without one.

So much for that...

Materials are attached to objects, deform sprite also rotates the object not the material itself plus deform sprite requires models made of a single flat face (a plane), wheres my script works with any object.
You need to find, using the editor, all the objects using that material, Dark Radiant (from the DarkMod) has a option where it will select all objects using the same material, with all selected you can assign the key value, i suggested, to all of them at the same time.

spamclark15

There are table carts throughout the game though.

Phrozo

#24
Try finding the entity def of these table carts you are talking about.

If I recall r_showSurfaceInfo set to 1 should show the entity def of what you are looking at. If not try grabbing the table cart with editAFs. If not that, type editDecls in console and search for 'models/mapobjects/tablecart1ball'. Check under entityDefs for any possible hits.

spamclark15

#25
r_showsurfaceinfo comes back with models/mapobjects/tablecart2 and the files for them are in models/mapobjects/lab/tablecart1 and tablecart2

Phrozo


spamclark15

#27
moveable_compcart, moveable_tablecart1, moveable_tablecart2

These are the entity defs. These 3 all use that wheel material.

Phrozo

Now you can try scripting for these table carts. Make a new script file if you haven't already.


If you are not sure which one to edit just edit all of them and add the key "scriptobject" with the name of the script object you made in quotes. Then when they spawn, each table cart will run that script.

spamclark15

Alright, created lookat.script, containing:

#ifndef _LOOK_AT_
#define _LOOK_AT_

object lookAT {


vector plAngles;

entity player;


void init();
void lookAtPlayer();
};

void lookAT::init()
{
player = $player1;

        thread lookAtPlayer();
}


void lookAT::lookAtPlayer()
{
      eachFrame
      {
           plAngles = player.getViewAngles();

   plAngles_x = 0;
   plAngles_y = plAngles_y + 90;
   plAngles_z = 0;
   self.setAngles(plAngles);
      }
}
#endif


Changed doom_main.script to contain:

#include "script/ai_base.script"
#include "script/lookat.script"


The 3 carts are found within moveable.def. Other than map files, this is the only file that makes reference to those entity defs. I'm not clear on what to do next. I'm adding "lookat" to another script file?