Raised This Month: $32 Target: $400
 8% 

Question about lights


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
safetymoose
Senior Member
Join Date: Feb 2015
Old 04-21-2015 , 15:59   Question about lights
Reply With Quote #1

Hello again,

Can anyone tell me the difference between engine's set_lights() and fakemeta's EngFunc_LightStyle ?

And can they be changed on each player separately, or does it apply to the entire map?
safetymoose is offline
hzqst
Senior Member
Join Date: Jul 2008
Old 04-21-2015 , 21:14   Re: Question about lights
Reply With Quote #2

they are the same.

PHP Code:
void PF_lightstyle_I(int stylechar *val)
{
    
client_t *client;
    
int j;

    
sv.lightstyles[style] = val;

    if (
sv.state != ss_active)
        return;

    for (
0svs.maxclientslimitj++)
    {
        
client = &svs.clients[j];

        if (!
client->active && !client->spawned)
            continue;

        if (!
client->fakeclient)
        {
            
MSG_WriteChar(&client->netchan.messagesvc_lightstyle);
            
MSG_WriteChar(&client->netchan.messagestyle);
            
MSG_WriteString(&client->netchan.messageval);
        }
    }

send a style id and a lightstyle string to all active clients, if you want to send to each clients separately, you need a hook on engine, something like:
PHP Code:
    MSG_WriteChar(&svs.clients[id].netchan.messagesvc_lightstyle);
    
MSG_WriteChar(&svs.clients[id].netchan.messagestyle);
    
MSG_WriteString(&svs.clients[id].netchan.messageval); 
and it's difficult to locate the address of "&svs.clients[id].netchan.message" on each version of engine, maybe you need an IDA.
hzqst is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-22-2015 , 10:36   Re: Question about lights
Reply With Quote #3

For custom light per players: no reason to complicate too much. Sending a custom message should be enough:
PHP Code:
emessage_begin(MSG_ONESVC_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 1<= MaxPlayersi++)
        {
            if(
is_user_connecting(i))
            {
                
SendMessage(i)
            }
        }
    }
}

SendMessage(id)
{
    
//Send a new message
    
emessage_begin(MSG_ONESVC_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.
__________________

Last edited by HamletEagle; 04-22-2015 at 15:06.
HamletEagle is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 04-22-2015 , 15:37   Re: Question about lights
Reply With Quote #4

Quote:
Originally Posted by HamletEagle View Post
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
set_lights() manages this automatically for you, which is why it is not equivalent to just calling the engfunc or sending a client message. You don't need to replicate it using Orpheu.
__________________
In Flames we trust!

Last edited by Nextra; 04-22-2015 at 15:48.
Nextra is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-23-2015 , 09:00   Re: Question about lights
Reply With Quote #5

Quote:
Originally Posted by Nextra View Post
set_lights() manages this automatically for you, which is why it is not equivalent to just calling the engfunc or sending a client message. You don't need to replicate it using Orpheu.
Well, the idee is to show a possible way of how to set custom lights per player. set_lights does this for all players, since in PF_lightstyle_I the engine send message to all players. Now he can edit above code, and in SendMessage put a different light for every player or whatever he wants to do.
__________________

Last edited by HamletEagle; 04-23-2015 at 11:22.
HamletEagle is offline
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 04-23-2015 , 11:22   Re: Question about lights
Reply With Quote #6

This ?
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate - Here
Shooting King is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 22:57.


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