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

    • Petike the Taffer

      I've finally managed to log in to The Dark Mod Wiki. I'm back in the saddle and before the holidays start in full, I'll be adding a few new FM articles and doing other updates. Written in Stone is already done.
      · 4 replies
    • nbohr1more

      TDM 15th Anniversary Contest is now active! Please declare your participation: https://forums.thedarkmod.com/index.php?/topic/22413-the-dark-mod-15th-anniversary-contest-entry-thread/
       
      · 0 replies
    • JackFarmer

      @TheUnbeholden
      You cannot receive PMs. Could you please be so kind and check your mailbox if it is full (or maybe you switched off the function)?
      · 1 reply
    • OrbWeaver

      I like the new frob highlight but it would nice if it was less "flickery" while moving over objects (especially barred metal doors).
      · 4 replies
    • nbohr1more

      Please vote in the 15th Anniversary Contest Theme Poll
       
      · 0 replies
×
×
  • Create New...