Jump to content
The Dark Mod Forums

How to call a script repeatedly while lockpicking?


x0nic

Recommended Posts

Hey folks,

I am looking to call a certain script in my map.script-file repeatedly while lockpicking a door.

The goal is to check if any guards (which are spawning as "neutral") are able to see me lockpicking, and change their relation to the player accordingly. Like this:

void witnessCheck(string entity_name)
{
	ai theAI = sys.getEntity(entity_name);
	
	if(theAI.canSeeExt($player1, 1, 1)) 
	{
		sys.println(theAI.getName() + " has witnessed a crime!");
		theAI.lookAt($player1, 3);
		theAI.setEntityRelation($player1, -1);	// theAI is now hostile
	}
	else
	{
		sys.println(theAI.getName() + " didn't see anything suspicious.");
	}
}

void crime_lockpick()
{
	sys.println("You commited a crime! Check for witnesses...");
	
	// call one check for each guard entity on the map
	witnessCheck("atdm_ai_citywatch_1");
	// ....
}

with crime_lockpick() being called repeatedly while lockpicking. (It's a simplified version of the code suggested in https://wiki.thedarkmod.com/index.php?title=AI_Ignore_Player )

A frob-response of the door entity with a "run script"-effect is only called once, and I see no way of telling the script if the player is currently lockpicking or not, hence missing the break condition for any while-loop.

Furthermore, there's no distinction between frobbing/opening an unlocked door and lockpicking a locked one using this method. Sadly, the get-method in

void getDoorStatus(entity door)
{
	if(door.getBoolKey("locked")) sys.println("This door is locked.");
	else sys.println("This door is unlocked.");
}

always returned 0.

A used_action_script as described in https://wiki.thedarkmod.com/index.php?title=Tool,_Key,_custom_used_by_inventory_actions  would be neat (calling the func every frame in respect of the used inventory item, i.e. a lockpick), but doesn't work on doors apparently.

I wasn't able to wrap my head around the whole door mechanics yet, and obviously lack knowledge of idtech4 in general. Thus, I hope that any experienced DarkRadiant user might point me in the right direction.

Thanks in advance ❤️ have a good one

Edited by x0nic
Link to comment
Share on other sites

  • x0nic changed the title to How to call a script repeatedly while lockpicking?

do what joebarnin said the .getBoolKey(string), or .getKey(string), etc, are used to get key value pares, also called spawn arguments or spawn args that you defined in the entity definition file the .def file.

Is not a hard rule but those functions/methods should be used at entity spawn/init, why, because is way faster, to save the spawn arg value into a script variable and then use that during real gameplay, than opening from disk, a entire text file to read, loop through it and get data from it, that is obviously slower than just reading a float from memory. 

Link to comment
Share on other sites

If you've already tried used_by scripts I don't see anything obvious down that route.

The way I'd approach it then is:

1) Make a looping script that checks every 0.5s what category of inv_item the player currently has selected. If it's lockpicks...

2) Check what entity the player currently has highlighted. If its classname key is that of a door and it's locked...

3) Loop through all AIs in the map, checking if they can see the player. Can look at the A to Z Scripting guide for a method to do this.

 

Apart from that, you could derive a new scriptobject from the lockpick scriptobject which has a modified "activate" function that sets a global float variable for when the lockpicks were last used using sys.getTime(), and apply this scriptobject to your lockpicks via the spawnarg. Then you could have a global looping script check if the player very recently used his lockpicks, and if so check whether any AIs can see him.

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

    • snatcher

      TDM Modpack v4.2 released!
      · 0 replies
    • The Black Arrow

      Hey @nbohr1morehow come the zombies in The Dark Mod don't have a "resurrection" mechanic to it, similar to how Thief has it?
      They're quite a weak creature as of right now, it's merely a walking corpse that slashes you, making attacking them to kill them an actual strategy.
      Would be better if they had some cool mechanism to it that truly makes them a danger, such as the resurrection idea itself.
      · 3 replies
    • Ansome

      Query: when was the last time a zombie in a video game was unnerving or scary to you? I'm chipping away at my anniversary submission and I've been trying to gather opinions on the subject. I'm perfectly capable of lighting them well, changing their sfx, and creating effective ambience, but I'm worried that zombies at their core are just too overdone to be an effective payoff to the tension I'm creating.
      · 4 replies
    • nbohr1more

      The Lieutenant 3 is out! Congrats Frost_Salamander! ( raising awareness )
      · 2 replies
    • OrbWeaver

      Has anyone had any luck with textures from Polyhaven? Their OpenEXR normal maps seem too washed out and give incorrect shading in the engine.
      · 5 replies
×
×
  • Create New...