PDA

View Full Version : [Help] NMRiH: Hook achievement_earned event not working.


yokomo
11-14-2014, 13:23
Hi, in NMRiH (No More Room In Hell) there are no chat info when player has unlocked their achievement, so i wanna recreate that chat info. But when i test in server it doesn't print anything after i unlocked any achievement.

#include <sourcemod>

public Plugin:myinfo =
{
name = "NMRiH Achievement Info",
author = "wbyokomo",
description = "NULL",
version = "0.0.1",
url = "NULL"
}

new String:szAchievement[MAXPLAYERS+1][64]
#define IsPlayer(%0) (1<=%0<=MaxClients)

public OnPluginStart()
{
HookEvent("achievement_event", OnAchievementEventPre, EventHookMode_Pre)
HookEvent("achievement_earned", OnAchievementEarnedPre, EventHookMode_Pre)
}

public Action:OnAchievementEventPre(Handle:event, const String:name[], bool:dontBroadcast)
{
new id = GetClientOfUserId(GetEventInt(event, "userid"))
if(IsPlayer(id) && IsClientInGame(id)) GetEventString(event, "achievement_name", szAchievement[id], sizeof(szAchievement[]));
}

public Action:OnAchievementEarnedPre(Handle:event, const String:name[], bool:dontBroadcast)
{
new id = GetClientOfUserId(GetEventInt(event, "player"))
if(IsPlayer(id) && IsClientInGame(id)) PrintToChatAll("%N has earned the achievement %s", id, szAchievement[id]);
}


What is wrong with my code? or i hooked the wrong event?

Thanks.

Powerlord
11-14-2014, 14:50
Not all events are server-side events. Source sometimes uses events to communicate between different parts of the client as well.

yokomo
11-14-2014, 15:14
Not all events are server-side events. Source sometimes uses events to communicate between different parts of the client as well.

Then what is the suitable method to hook when someone earned achievement? I'm newbie to Sourcemod.