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

    • 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...