For custom light per players: no reason to complicate too much. Sending a custom message should be enough:
PHP Code:
emessage_begin(MSG_ONE, SVC_LIGHTSTYLE, _, id)
{
ewrite_byte(0)
ewrite_string("flags")
emessage_end()
}
Lights values are the same as when you use
set_lights. Now, you should make sure that game doesn not override your custom setup, for this you need to hook
PF_lightstyle_I
PF_lightstyle_I is exported to dll, so hooking it is very easy. Use orpheu/okapi.
PHP Code:
#include <amxmodx>
#include <orpheu>
#include <orpheu_stocks>
#include <fakemeta>
new OrpheuFunction:HandleSetLightStyle
public plugin_precache()
{
HandleSetLightStyle = OrpheuGetEngineFunction("pfnLightStyle", "SetLightStyle")
OrpheuRegisterHook(HandleSetLightStyle, "OnSetLightStyle", OrpheuHookPre)
}
//Style is an light type I guess. Should use 0 for players
//Value is light value
public OrpheuHookReturn:OnSetLightStyle(Style, const Value[])
{
//Now send your message here again.
return OrpheuSupercede
}
Signature:
Code:
{
"name" : "SetLightStyle",
"library" : "engine",
"arguments" :
[
{
"type" : "int"
},
{
"type" : "char *"
}
],
"return" :
{
"type" : "int"
}
}
Name this file
SetLightStyle and put it inside
orpheu/functions folder.
Take a look here. I used this to test the method.
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <orpheu>
#include <orpheu_stocks>
new MaxPlayers
public plugin_precache()
{
new OrpheuFunction:HandleSetLightStyle = OrpheuGetEngineFunction("pfnLightStyle", "SetLightStyle")
OrpheuRegisterHook(HandleSetLightStyle, "OnSetLightStyle", OrpheuHookPre)
register_event("InitHUD", "OnPlayerJoin_Event", "b")
MaxPlayers = get_maxplayers()
//Fix coloring bug
server_cmd("sv_skycolor_r 0")
server_cmd("sv_skycolor_g 0")
server_cmd("sv_skycolor_b 0")
}
public OnPlayerJoin_Event(id)
{
if(is_user_connected(id))
{
//Player joined, send message
SendNewLightMessage(id)
}
}
public OrpheuHookReturn:OnSetLightStyle(Style, const Value[])
{
//Send a new message and supercede original call
SendNewLightMessage(0)
return OrpheuSupercede
}
SendNewLightMessage(id)
{
if(id)
{
SendMessage(id)
}
else
{
//According to wiki this message is send some times during connecting
//Due to lack of time I'll just trust this
for(new i = 1; i <= MaxPlayers; i++)
{
if(is_user_connecting(i))
{
SendMessage(i)
}
}
}
}
SendMessage(id)
{
//Send a new message
emessage_begin(MSG_ONE, SVC_LIGHTSTYLE, _, id)
{
ewrite_byte(0)
ewrite_string("a")
emessage_end()
}
}
Did not tested in deep, but should work fine.
ewrite_string("a") here you put the light string(I used "a" just for test). This is a basic example, you should add checks to see if current light value is different from the one you want to setup. As said, credits to wiki and Arkshine.
__________________