Is this possible?

Fou-lu

New member
Messages
145
Points
0
Github
Pedro
I would like to detect when a player leaves a map through the return when he dies.

 
DieEvent no good 'cause the player can be revived and not exit the map, in my case I want to detect the moment he presses the button to go back to the last save.

 
Last edited by a moderator:
some random idea.

OnPCDieEvent: .@map$ = strcharinfo(3); if ( .@map$ == "prontera" ) { while ( strcharinfo(3) == .@map$ ) sleep2 1000; announce strcharinfo(0)+" has died and back to Save Points.",bc_all; } end;

can be done with various way .... like using this way too

Code:
OnCheck:	if ( strcharinfo(3) != "prontera" ) {		announce strcharinfo(0)+" has died and back to Save Points.",bc_all;	}OnPCLoadMapEvent:	deltimer strnpcinfo(0)+"::OnCheck";	if ( strcharinfo(3) == "prontera" )		addtimer 5000,strnpcinfo(0)+"::OnCheck";	end;
 
@@Emistry

The first won't work.

Leaving the map would reset the script and the part after the loop would never get executed.

The second should work, but it is pretty unrealistic since i guess he wants this function global. For OnPCLoadMapEvent you need to add it via Mapflag to all maps which would produce a high server load and some other changes would be required to make it possible at all.

 
I had a different idea inspired by the first example.
 
The Hp is to check if the player is still dead and attachrid is for the script to continue running even with the player moving map and OnPCLogoutEvent is to log out case.
 
With this together and the mapflag of noreturn and nowarp think there's no way the player leave the map without being checked by the script.
 
Code:
OnPCDieEvent:	.@map$ = strcharinfo(3);	.@char = getcharid(0);	if ( .@map$ == "prontera" ) {        while ( strcharinfo(3) == .@map$ && !Hp) {			sleep 1000;			if (isloggedin(.@char)) attachrid(.@char);			else break;		}		if (isloggedin(.@char) && strcharinfo(3) != .@map$)			announce strcharinfo(0)+" has died and back to Save Points.",bc_all;	}	end;OnPCLogoutEvent:	if ( .@map$ == "prontera" ) {		if (!Hp) announce strcharinfo(0)+" has died and Logout.",bc_all;		else announce strcharinfo(0)+" has Logout.",bc_all;	}	end;
 
Last edited by a moderator:
@@Pedroooo

The problem isn't the that you loose the rid, the problem is that the script gets completly unloaded and loaded again.

 
@@Emistry

The first won't work.

Leaving the map would reset the script and the part after the loop would never get executed.

The second should work, but it is pretty unrealistic since i guess he wants this function global. For OnPCLoadMapEvent you need to add it via Mapflag to all maps which would produce a high server load and some other changes would be required to make it possible at all.
it work fine in my Hercules test server. 

 
if you just want to execute an npc when player press that respawn button (Return to last save point)

then you have to do source modification

plugin

#include "common/hercules.h"#include <stdio.h>#include <string.h>#include <stdlib.h>#include "map/pc.h"#include "map/npc.h"#include "common/HPMDataCheck.h"HPExport struct hplugin_info pinfo = { "OnPCRespawnEvent", // Plugin name SERVER_TYPE_MAP,// Which server types this plugin works with? "0.1", // Plugin version HPM_VERSION, // HPM Version (don't change, macro is automatically updated)};void pc_respawn_post( struct map_session_data* sd, clr_type clrtype ) { struct npc_data *nd = npc->name2id("OnPCRespawnEvent"); if ( !nd ) { ShowError( "OnPCRespawnEvent not found !" ); return; } script->run( nd->u.scr.script, 0, sd->bl.id, nd->bl.id ); return;}HPExport void plugin_init (void) { addHookPost( "pc->respawn", pc_respawn_post );}and write a script as it were executed like MOTD ...
Code:
-	script	OnPCRespawnEvent	FAKE_NPC,{	unittalk getcharid(3), "I'm ALIVE !!!";	end;OnPCDieEvent:	unittalk getcharid(3), "I'm dead ...";	end;}
..

however if you are actually writing an event script, such as instance script

remember there are other checks to make sure the event run smoothly

eg: warpping, log out ... etc etc

 
Last edited by a moderator:
Back
Top