Raised This Month: $51 Target: $400
 12% 

Please help me with GameFrame


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DigiSoft
BANNED
Join Date: Feb 2009
Old 01-04-2010 , 19:34   Please help me with GameFrame
Reply With Quote #1

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.
DigiSoft is offline
BAILOPAN
Join Date: Jan 2004
Old 01-04-2010 , 21:03   Re: Please help me with GameFrame
Reply With Quote #2

It's okay to check the time every frame.
__________________
egg
BAILOPAN is offline
DigiSoft
BANNED
Join Date: Feb 2009
Old 01-05-2010 , 04:23   Re: Please help me with GameFrame
Reply With Quote #3

Quote:
Originally Posted by BAILOPAN View Post
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

Last edited by DigiSoft; 01-05-2010 at 04:29.
DigiSoft is offline
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 01-05-2010 , 04:49   Re: Please help me with GameFrame
Reply With Quote #4

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.

Last edited by CrimsonGT; 01-05-2010 at 04:51.
CrimsonGT is offline
BAILOPAN
Join Date: Jan 2004
Old 01-05-2010 , 05:21   Re: Please help me with GameFrame
Reply With Quote #5

Don't use sleep() in the game thread... it's blocking.
__________________
egg
BAILOPAN is offline
DigiSoft
BANNED
Join Date: Feb 2009
Old 01-05-2010 , 05:29   Re: Please help me with GameFrame
Reply With Quote #6

Oh thank you to both, I'll try this.
DigiSoft is offline
DigiSoft
BANNED
Join Date: Feb 2009
Old 01-05-2010 , 05:49   Re: Please help me with GameFrame
Reply With Quote #7

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.

Last edited by DigiSoft; 01-05-2010 at 06:57.
DigiSoft is offline
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 01-05-2010 , 07:40   Re: Please help me with GameFrame
Reply With Quote #8

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*)
CrimsonGT is offline
DigiSoft
BANNED
Join Date: Feb 2009
Old 01-05-2010 , 08:09   Re: Please help me with GameFrame
Reply With Quote #9

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

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?

Last edited by DigiSoft; 01-05-2010 at 08:55.
DigiSoft is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 01-05-2010 , 10:08   Re: Please help me with GameFrame
Reply With Quote #10

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 )"

Last edited by Keeper; 01-05-2010 at 10:12.
Keeper 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 04:09.


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