communicate from npcmodes?
#1

Hey, is it possible to call functions in gamemode/filterscripts from a npc mode?

Thanks
Reply
#2

yes. the npc script can handle that by sending a command. i use it for announcing special events, happenings, w/e u call it. that function gets called by a lot of npcs - imo its a very comfortable way once you figured it out, however, i would appreciate a better, more precise way for doing that. :/
NPC script:
Code:
#define RECORDING "LicenseA"
#define RECORDING_TYPE 1
#include <a_npc>
new CyclesMin=20;
new CyclesMax=40;
new CyclesATM=35;
new gTimerLicense;
public OnRecordingPlaybackEnd()
	StartRecordingPlayback(RECORDING_TYPE, RECORDING);
#if RECORDING_TYPE == 1
  public OnNPCEnterVehicle(vehicleid, seatid) StartRecordingPlayback(RECORDING_TYPE, RECORDING);
  public OnNPCExitVehicle() StopRecordingPlayback();
#else
  public OnNPCSpawn() StartRecordingPlayback(RECORDING_TYPE, RECORDING);
#endif
main()
{
  printf("License");
}
public OnNPCModeInit()
{
	gTimerLicense=SetTimer("TimerLicense",2000,1);
}
public OnNPCModeExit()
{
	KillTimer(gTimerLicense);
}
forward TimerLicense();
public TimerLicense()
{
	CyclesATM++;
	if(CyclesATM>CyclesMin)
	{
		if(CyclesATM>CyclesMax || random(10)<2)
		{
			new Amount=10000;//need to calculate a random amount, so the money wont stack up
			new NPCcmd[32];
			format(NPCcmd,sizeof(NPCcmd),"/dt %d",Amount);
// thats the "drop treasure" command, it will create a simple money pickup...
			SendCommand(NPCcmd);
			new msg[128];
			format(msg,128,"/Aq make your license! get less wanted levels for stealing a vehicle!",Amount);
			SendCommand(msg);
			format(msg,128,"i got $#mon here, i will drop some!",Amount);
//#mon is a quickstring, it will insert your actual money, its processed in the GM...
			SendChat(msg);
			CyclesATM=0;
		}
	}
}
2 snippets inside a filterscript: ...it wont harm if theyre not present, coz the npc will recieve "command not found." ^^
Code:
dcmd_Aq(playerid,params[])
{
	new Text[128];
	if (sscanf(params,"s",Text))
	{
		SendClientMessage(playerid,MSGCOMM_COLOR, "Usage: \"/Aq <Text>\"");
		return 1;
	}
	AddNews(playerid,Text);
	return 1;
}

forward AddNews(playerid,Text[]);
public AddNews(playerid,Text[])
{
//	SendClientMessage(playerid,0xffffffff,Text);
	format(TDTSMessageText,sizeof(TDTSMessageText),"%s%s_",TDTSMessageText,Text);
//looks weird, i know :)
	ShowTDTS();
	return 1;
}
Code:
 . regards
..: babul
edit: you could use the OnPlayerKeyStateChange too, f.ex to trigger functions like arresting, accepting a deal etc. using the KEY_SUBMISSION, KEY_CROUCH etc.
Reply
#3

How about CallRemoteFunction()? It works with filterscripts, might as well work with NPCs, but I never tried that myself. I think NPCs are run by different exe and for the same reason you can't see printf() from NPC code in the log... I think it's worth to try.
Reply
#4

sadly, i failed at trying this (to include callremotefunction inside the npc script)...
anyways, its fun to see a npc reacting on chat-messages with OnClientMessage() "detection". it can be RemoteControlled this way by sending it PMs, works with scripted PMs even
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)