Jump to content
The Dark Mod Forums

Help for short Script


Destined

Recommended Posts

Hi Guys,

 

Happy New Year! I have just recently started mapping with TDM and was able (thanks to Fidkal's great tutorial) to make my first mission. But in this mission I would like to introduce a wrench (just like in the new Thief game). Since I have no experience with modeling whatsoever, I thought about circumventing the problem by adding it after searching a toolbox. This needs no new models, but instead I need a simple script, that adds the wrench to the inventory, after frobbing a toolbox. Sadly, my sriping is in no way better than my modeling :-( and the Tutorial started by Fidkal is not finished yet. So my question would be: could someone write the few lines, I would need for this script? Just an example file, where I only need to insert the ID of the wrench.

Perhaps this could also be quite easily implemented in Dark Radiant: A Response, that adds an item to the inventory. At least it does not seem like a big deal.

 

I hope you can help me and thanks in Advance!

 

Link to comment
Share on other sites

Hi, and welcome. I guess you have an inventory icon sorted out, just not a 3d model?

 

Assuming you have an entityDef for your new wrench and its classname is "myWrench" and that your map is called "mymap.map".

 

Create an empty text file in the same folder as mymap.map and call it mymap.script

 

In mymap.script put the following text:

 

void giveWrench()
{
   entity w = sys.spawn("myWrench");
   w.addItemToInv($player1);
}

 

On your toolbox, add the spawnarg: "frob_action_script" "giveWrench"

Link to comment
Share on other sites

Thank you, SteveL, for the (quicker than expected) answer. As you expected, I have an inventory icon, but no 3D model.

To be honest, I have so far not been working with the def-files, so it took some time, to figure it all out, but with the help of the Wiki I was able to get it working. There are still some issues, like actually not wanting the wrench to appear in the Keys section (as it currently does, since I am using the same mechanism as the keys to use the wrench) and another sound on adding it to the Inventory, but I think, I can figure that out on my own.

Thank you again!

Link to comment
Share on other sites

Hey Destined,

 

You can set which inventory section an object will appear in by using the "inv_category" spawnarg on the object, and the "snd_acquire" spawnarg determines which sound will play on pickup.

But you should walk having internal dignity. Be a wonderful person who can dance pleasantly to the rhythm of the universe.

-Sun Myung Moon

 

My work blog: gfleisher.blogspot.com

Link to comment
Share on other sites

Also, it occurs to me that my simple script above will give the player a wrench every time they frob the box. If you want it to happen only once, the following change will do the trick:

 

 

float wrenchGiven;

void giveWrench()
{
   if (wrenchGiven == 0)
   {
      entity w = sys.spawn("myWrench");
      w.addItemToInv($player1);
      wrenchGiven = 1;
   }
}

void main()
{
   wrenchGiven = 0;
}
Link to comment
Share on other sites

Thanks for the help and further tips!

Can I define these spawnargs in the def-file? I would assume that I can just type

"inv_category" "Category"

"snd_aquire" "Soundfile"

in the def-file, just like other spawnargs are defined?

 

I have avoided repeating the script by a stim/response set, that makes the toolbox unfrobable after being frobbed. Thus the script can only run once. I am also thinking about a little search sequence, where some conainers have to be searched, before the wrench is acquired and wanted to use the same stim/response set for other containers, so that the player can frob each container only once. To avoid that the player can lose the wrench I would just make it non-dropable. This reminds me, that I would have to define that in the def-file again.

 

Again: thanks for the input! It is great that you guys help so much!

Link to comment
Share on other sites

You should be fine putting everything in the def file, if you don't need different wrenches with different properties.

 

If you wanted to spawn individual wrenches in the map, so that you could give them different snd_aquire spawnargs, for example, you can do it, you'd just put them in a blueroom (a separate room in the map which the player will never see). I'm not sure off-hand whether you'd need to add some kind of visible model or not, but it doesn't matter because the player would never see them. If you made them without models and found the map crashed at startup, you would just make little brush cubes in your blueroom and select them in DR and Create Entity > myWrench. The brush cube would become the visible model that got used out-of-sight until the wrench got put in the player's inventory.

 

You can also get scripts to apply different spawnargs to an entity that they spawn, if you need a more complex setup.

Link to comment
Share on other sites

I think I am fine for now. I have not planned to use different wrenches, but it is actually a good idea to lead the player through a level. On the other hand, this would lead to a scenario where the wrenches replace the function of keys (actually in German they are called "Schraubenschlüssel" which literally translates to "screwing key"). Only the doors are a bit different... But as it is said in Fidkal's tutorial: one should start small and since this is my first FM I should not overdo it. For now it will be a tool to get around easier and maybe get access to some secret rooms, that are not accessible otherwise. So for now I am glad, when I get the wrench to work as it is.

Regarding your suggestion to create entities in a blue room for the use of different wrenches: Is it possible to add objects on the map to the inventory? The script you gave me spawns the wrench directly in the inventory, but this also means that I have to define all spawnargs in the def-file. It might be more convenient to create the wrench as an entitiy (as you suggested) so the spawnargs can be modified directly in DR, but this means it has to be moved to and not spawned in the inventory.

Man, I just noticed, that I will not get around learning to script myself. It opens quite a lot of possibilities, that are otherwise not available. But for now I will work with the things I can actually do and in other missions to come, I can include more comlicated stuff.

Link to comment
Share on other sites

The script doesn't spawn the wrench directly in the inventory, but in the map. It gets added by the second command. Regarding def files, the way you add spawnargs there is the same as in DR. And if it should become an inventory object anyways, it doesn't neccessarely need a model. But as entities without models are hard to select in DR and if you want to place them in a blue room either you can just give them a placeholder model for easier selection in DR.

 

Regarding scriptin: Yeah, learn it. It's not the most challenging part of mapping :)

FM's: Builder Roads, Old Habits, Old Habits Rebuild

Mapping and Scripting: Apples and Peaches

Sculptris Models and Tutorials: Obsttortes Models

My wiki articles: Obstipedia

Texture Blending in DR: DR ASE Blend Exporter

Link to comment
Share on other sites

Sorry for being a noob once again: OK, I can see in the script, that the wrench is first spawned and the given to the player (as you described, Obsttorte). But I would like to understand the whole script (as a first step to learn). Please correct me, if I am wrong, but as far as I understand it, you define an entity as "w", that is then spawned via the "sys.spawn" command. Then the entity "w" is given to the player via "w.addItemToInv($player1)". Or does the "w" have another meaning?

Sorry again for asking here, maybe I should look for a tutorial (other than Fidcal's, since it is not finished), but I just wanted to understand this script and then finish my map.

Link to comment
Share on other sites

No, 'w' doesn't have any meaning. It's just a label. You need to give a name to your new wrench so that the script can do stuff with it, and I was being lazy so I chose 'w' as short for 'wrench'.

 

I'd like to write a scripting tutorial myself -- one of my favourite hobbies -- but I've been working on other stuff and not found the time.

Link to comment
Share on other sites

  • 1 year later...

I am working on another script, that should be much easier than the last one, but it does not work and I don't know why. All the script should do is, count upwards wit heach food entity found and when the number 10 is reached, it should mark the objective complete. This is how it looks so far:

 

// Searching for food

float FoodNumber = 0;

void FoodSearch()
{

FoodNumber = FoodNumber+1;
sys.print("\nCurrent FoodNumber="+FoodNumber);

//Found enough food
if (FoodNumber = 10)
{
$player1.setObjectiveState(3, OBJ_COMPLETE);
sys.print("\nCurrent FoodNumber="+FoodNumber);
}
}

 

But as soon as I pick up the first entity (this entity has the stim: frob and responses: run script "FoodSearch" and remove self. Can someone tell me, what I am doing wrong?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recent Status Updates

    • nbohr1more

      The FAQ wiki is almost a proper FAQ now. Probably need to spin-off a bunch of the "remedies" for playing older TDM versions into their own article.
      · 1 reply
    • nbohr1more

      Was checking out old translation packs and decided to fire up TDM 1.07. Rightful Property with sub-20 FPS areas yay! ( same areas run at 180FPS with cranked eye candy on 2.12 )
      · 3 replies
    • taffernicus

      i am so euphoric to see new FMs keep coming out and I am keen to try it out in my leisure time, then suddenly my PC is spouting a couple of S.M.A.R.T errors...
      tbf i cannot afford myself to miss my network emulator image file&progress, important ebooks, hyper-v checkpoint & hyper-v export and the precious thief & TDM gamesaves. Don't fall yourself into & lay your hands on crappy SSD
       
      · 7 replies
    • OrbWeaver

      Does anyone actually use the Normalise button in the Surface inspector? Even after looking at the code I'm not quite sure what it's for.
      · 7 replies
    • Ansome

      Turns out my 15th anniversary mission idea has already been done once or twice before! I've been beaten to the punch once again, but I suppose that's to be expected when there's over 170 FMs out there, eh? I'm not complaining though, I love learning new tricks and taking inspiration from past FMs. Best of luck on your own fan missions!
      · 4 replies
×
×
  • Create New...