SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 02/05/2010, 11:35 PM   #1
beckzy
Beta Tester
 
Join Date: Dec 2006
Posts: 1,287
Reputation: 172
Default communicate from npcmodes?

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

Thanks
__________________
beckzy is online now  
Old 02/05/2010, 11:52 PM   #2
Babul
High-roller
 
Babul's Avatar
 
Join Date: Sep 2009
Location: in a cement block
Posts: 1,781
Reputation: 266
Default Re: communicate from npcmodes?

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.
__________________
FireWorks

new sscanf2 custom specifiers available for Download, read the Release Topic
Babul is offline  
Old 03/05/2010, 06:22 AM   #3
mick88
Big Clucker
 
mick88's Avatar
 
Join Date: Jan 2010
Location: Ireland
Posts: 166
Reputation: 32
Default Re: communicate from npcmodes?

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.
mick88 is offline  
Old 03/05/2010, 09:16 PM   #4
Babul
High-roller
 
Babul's Avatar
 
Join Date: Sep 2009
Location: in a cement block
Posts: 1,781
Reputation: 266
Default Re: communicate from npcmodes?

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
__________________
FireWorks

new sscanf2 custom specifiers available for Download, read the Release Topic
Babul is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how i use npcmodes OmarEco Help Archive 4 09/07/2010 02:40 PM
how to use npcmodes? oObig_manOo Help Archive 0 12/03/2010 04:45 AM
Multiple NPCs using 2 npcmodes? Programie Help Archive 0 07/03/2010 12:19 PM
how can pawno communicate with mysql Drezek Help Archive 2 22/10/2009 10:15 PM
Communicate with NPC? Zezombia Help Archive 1 03/09/2009 03:58 AM


All times are GMT. The time now is 04:46 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.