AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Coding MM:S Plugins & SM Extensions (https://forums.alliedmods.net/forumdisplay.php?f=75)
-   -   Please help me with GameFrame (https://forums.alliedmods.net/showthread.php?t=114446)

DigiSoft 01-04-2010 19:34

Please help me with GameFrame
 
Ok so I want to make plugin that checks something on every 5 minutes.
Where can I put this loop? I think it should be in GameFrame but this will loop on every frame.

Please help me.

BAILOPAN 01-04-2010 21:03

Re: Please help me with GameFrame
 
It's okay to check the time every frame.

DigiSoft 01-05-2010 04:23

Re: Please help me with GameFrame
 
Quote:

Originally Posted by BAILOPAN (Post 1043466)
It's okay to check the time every frame.

But how, I really don't understand this part. Can you show me very sample code for the loop? Should I use sleep?

And one more question. What function can I use in GameFrame to send messages every 5 minutes on the chat area?

Thank you BAILOPAN

CrimsonGT 01-05-2010 04:49

Re: Please help me with GameFrame
 
Code:

#include "time.h"

//something like this to get the original time
time_t originalTime;
originalTime = time(NULL);

//something like this to get the current time (use in GameFrame())
time_t curTime;
curTime = time(NULL);

if(difftime(originalTime, curTime) > 300.0)
{
//5 minutes has passed
}

To print to the chat area you will have to use UserMessages, theres no function or command you can simply call. Look at the Sourcemod sourcecode for the PrintToChat() function code, and trace it back a little bit to see how to use the usermessage.

BAILOPAN 01-05-2010 05:21

Re: Please help me with GameFrame
 
Don't use sleep() in the game thread... it's blocking.

DigiSoft 01-05-2010 05:29

Re: Please help me with GameFrame
 
Oh thank you to both, I'll try this.

DigiSoft 01-05-2010 05:49

Re: Please help me with GameFrame
 
In the example plugin I see they use CreateMessage for sending messages. Is this bad method?

In sourcemod they use UserMessageBegin and MessageEnd

What is best method to send simple text to the chat area?

If I use
Quote:

#include "time.h"

//something like this to get the original time
time_t originalTime;
originalTime = time(NULL);

//something like this to get the current time (use in GameFrame())
time_t curTime;
curTime = time(NULL);

if(difftime(originalTime, curTime) > 300.0)
{
//5 minutes has passed
}
Wont this code slow down the FPS or something? Because every frame it requests for time and other processes? Thanks

EDIT1: OK I think the loop is working ok but I don't know how to send simple text to the chat area.
I've tried
Quote:

KeyValues *kv = new KeyValues( "msg" );
kv->SetString( "title", "Hello" );
kv->SetString( "msg", "Hello there" );
kv->SetColor( "color", Color( 255, 0, 0, 255 ));
kv->SetInt( "level", 5);
kv->SetInt( "time", 10);
helpers->CreateMessage( pEntity, DIALOG_MSG, kv, this );
kv->deleteThis();
But GameFrame doesn't have pEntity. If I declare pEntity then it doesn't work.

CrimsonGT 01-05-2010 07:40

Re: Please help me with GameFrame
 
It all depends on who you are trying to send a message to. If its to a specific person your going to have to get their index/edict/entity one way or another, then you can use the engine functions to convert it to whatever you need. (Im assuming pEntity is an edict_t*)

DigiSoft 01-05-2010 08:09

Re: Please help me with GameFrame
 
I want to send global chat message.

Now I am truing this code.

Quote:

void CEmptyServerPlugin::SayTextMsg(int PlayerIndexN, char const *Message)
{
MRecipientFilter filter;
if(PlayerIndexN == 0)
{
filter.AddAllPlayers(MaxClients); // we grab the maxclients at the ServerActivate Void
}
else
{
filter.AddRecipient(PlayerIndexN);//adds the player
}

bf_write *pWrite=engine->UserMessageBegin(&filter, 3);//3 for Say_Text

if( !pWrite )
{
//TODO: Action to perform when something goes wrong
}
else
{
pWrite->WriteByte(PlayerIndexN);// Players index, to send a global message from the server make it 0
pWrite->WriteString(Message);//the message itself
pWrite->WriteByte(0);//0 to phrase for colour 1 to ignore it
engine->MessageEnd();//finish off
}
}
But now it sayes
use of undefined type 'bf_write'

Why is it undeclared? Should I include something

I am sorry but I am new to the source engine :D

EDIT1: OK I included bitbuf.h and that is ok but I have another error.
'MRecipientFilter' : undeclared identifier

What should I include now?

Thanks.









EDIT2: Ok so I've write down MRecipientFilter.cpp and MRecipientFilter.h and now it compiles ok. The messaging system is working but the loop is not.

Please help me with the loop. Why it doesn't loops?
This is my code for the loop

Quote:

void CEmptyServerPlugin::GameFrame( bool simulating )
{
time_t curTime;
curTime = time(NULL);
if(difftime(originalTime, curTime) > 5.0)
{
SayTextMsg(0, "IT WORKS");
originalTime = time(NULL);
}
}
originalTime is initialized at LevelInit with
originalTime = time(NULL);

What am I doing wrong?

Keeper 01-05-2010 10:08

Re: Please help me with GameFrame
 
I believe your problem is in the
Code:

difftime(originalTime, curTime) > 5.0
I think it should be
Code:

difftime(curTime, originalTime ) > 5.0
The function is defined as "difftime (endtime, starttime )"


All times are GMT -4. The time now is 07:33.

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