AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   register_forward(FM_SetKeyValue, ...) ? (https://forums.alliedmods.net/showthread.php?t=27029)

bahr 04-13-2006 13:08

register_forward(FM_SetKeyValue, ...) ?
 
I cant make the register_forward(FM_SetKeyValue,..) to work; it seems to not catch the SetKeyValue() function. Am I missing something?

I have this:

Code:
public plugin_precache() {     register_forward(FM_SetKeyValue, "Hook_SetKeyValue") ... } public Hook_SetKeyValue(infobuffer[], key[], value[]) {     new fmt[256]     formatex(fmt, 255, "infobuffer ='%s', key = '%s', value = '%s'", infobuffer, key, value)     log_amx(fmt)     return FMRES_IGNORED }

I got no logging at all..

Thx

PM 04-13-2006 13:35

First off, that formatting thing you do is bad. bad!

log_amx does formatting for you. so do:

Code:
public Hook_SetKeyValue(infobuffer[], key[], value[]) {     log_amx("infobuffer ='%s', key = '%s', value = '%s'", infobuffer, key, value)     return FMRES_IGNORED }

Otherwise, your code is much less efficient (zeroing the fmt buffer on the stack, formatting into that buffer, then letting log_amx go through the entire output again) and fragile (imagine that infobuffer contained "%s", then the output from formatex in fmt would also contain "%s", so log_amx would look for a subsequent string parameter - it wouldn't find it and you'd get a runtime error).

Okay, to your actual issue..
The HLSdk doesn't use this function at all; I don't know what it does; probably the gamedll could tell the engine to set a keyvalue on an entity.. whatever :)

Most likely you want pfnKeyValue from DLL_FUNCTIONS or maybe pfnInfoKeyValue from enginefuncs_s.

v3x 04-13-2006 14:22

pm is teh smart :o

bahr 04-13-2006 18:43

Is that mean I cant catch that function at all?
I need to catch it for a way to communicate from one plugin to another.
1st plugin: modify entities; moving, rotating, etc
2nd plugin: create special entities but need to know when 1st plugin modify the keys of entities created by the 2nd.
How can I achieve this?

Twilight Suzuka 04-14-2006 08:08

DispatchKeyValue doesn't actually alter the keyvalue, it just makes the engine think the value is different. Sooo...maybe the engine forward?

PM 04-14-2006 08:14

Things that plugins do don't go through the hook layer anymore - so you can't intercept them (maybe with some hacks you could); otherwise it would be too easy to get infinite recursion problems and such.

The first plugin would have to notify the second one. We don't have an observer pattern implementation IIRC so callfunc would be most likely your best bet. Of course, assuming that you are able to modify the first plugin.

I hope I haven't misunderstood you :)

edit: bail said: plugins can do CreateMultiForward()

I imagine that that'd be better than callfunc.

bahr 04-14-2006 09:22

Thanks :)

I think I'll try callfunc then ;)


All times are GMT -4. The time now is 05:06.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.