Is it possible to send player tag updates to select players [message #474093] |
Sat, 08 September 2012 06:43 |
BillieJoe67
Messages: 35 Registered: March 2012
Karma: 0
|
Recruit |
|
|
What I'm trying to do is create an improved spectate mode, and I had this idea where players who are scoped have the tag Scoping or whatever. Obviously, the tag should only be sent to players that are in spectate mode, but would it be possible to do a select update? Send_Object_Update doesn't work.
This is the basic code I have so far, but it sends the tag to all players
DynamicVectorClass<int> SpectatingPlayers;
void ExamplePlugin::OnThink()
{
for(SLNode<cPlayer>* PlayerIter = Get_Player_List()->Head(); (PlayerIter != NULL); PlayerIter = PlayerIter->Next())
{
cPlayer* cP = PlayerIter->Data();
if(cP && cP->IsActive)
{
GameObject* PlayerObj = Get_GameObj(cP->PlayerId);
if(PlayerObj)
{
if(PlayerObj->As_SoldierGameObj()->Is_Sniping() == true)
{
cP->customTag.Format(L"Sniping");
cP->Set_Object_Dirty_Bit(NetworkObjectClass::BIT_CREATION, true); //remove this line
for(int i = 0; i < SpectatingPlayers.Length(); i++)
{
//Do the update here
}
}
else
{
cP->customTag.Format(L"");
cP->Set_Object_Dirty_Bit(NetworkObjectClass::BIT_CREATION, true); //remove this line
for(int i = 0; i < SpectatingPlayers.Length(); i++)
{
//Do the update here
}
}
}
}
}
}
[Updated on: Sat, 08 September 2012 06:50] Report message to a moderator
|
|
|
|
Re: Is it possible to send player tag updates to select players [message #474105 is a reply to message #474093] |
Sat, 08 September 2012 09:02 |
iRANian
Messages: 4308 Registered: April 2011
Karma: 0
|
General (4 Stars) |
|
|
Simplify it first so it runs for only one guy in spectate.
Try:
cP->customTag.Format(L"Sniping");
Send_Object_Update(obj, PlayerID);
cP->customTag.Format(L"");
Or:
cP->customTag.Format(L"Sniping");
cP->Set_Object_Dirty_Bits(PlayerID, NetworkObjectClass::BIT_CREATION);
Send_Object_Update(obj, PlayerID);
cP->customTag.Format(L"");
Otherwise you can attach an object or float an object above sniping players for one second and only have these shown for spectating players. I recommend you add a simple check at the start of OnThink() to make the code only run every second or so. Use GetTickCount64().
Long time and well respected Renegade community member, programmer, modder and tester.
Scripts 4.0 private beta tester since May 2011.
My Renegade server plugins releases
[Updated on: Sat, 08 September 2012 09:12] Report message to a moderator
|
|
|
Re: Is it possible to send player tag updates to select players [message #474109 is a reply to message #474093] |
Sat, 08 September 2012 13:49 |
BillieJoe67
Messages: 35 Registered: March 2012
Karma: 0
|
Recruit |
|
|
Thanks Ethenal
Iran, the second code works, thanks so much
For anyone interested, this is the current, working code.
DynamicVectorClass<int> SpectatingPlayers;
bool IsSniping[128];
int LastCheck = 0;
int Seconds_Difference(int time1, int time2)
{
time_t Time1(time1);
time_t Time2(time2);
return (int)difftime(Time1, Time2);
}
ExamplePlugin::ExamplePlugin()
{
RegisterEvent(EVENT_THINK_HOOK,this);
for(int i = 0; i < 127; i++)
{
IsSniping[i] = false;
}
}
ExamplePlugin::~ExamplePlugin()
{
UnregisterEvent(EVENT_THINK_HOOK,this);
}
void ExamplePlugin::OnThink()
{
int Seconds = Seconds_Difference((int)time(NULL), LastCheck);
if(Seconds >= 1)
{
LastCheck = (int)time(NULL);
for(SLNode<cPlayer>* PlayerIter = Get_Player_List()->Head(); (PlayerIter != NULL); PlayerIter = PlayerIter->Next())
{
cPlayer* cP = PlayerIter->Data();
if(cP && cP->IsActive)
{
GameObject* PlayerObj = Get_GameObj(cP->PlayerId);
if(PlayerObj)
{
if(PlayerObj->As_SoldierGameObj()->Is_Sniping() == true)
{
if(!IsSniping[cP->PlayerId])
{
IsSniping[cP->PlayerId] = true;
cP->customTag.Format(L"Scoped");
for (int i = 0;i < SpectatingPlayers.Count();i++)
{
int id = SpectatingPlayers[i];
cP->Set_Object_Dirty_Bit(id, NetworkObjectClass::BIT_CREATION, true);
Send_Object_Update(cP, id);
}
cP->customTag.Format(L"");
}
}
else
{
if(IsSniping[cP->PlayerId])
{
IsSniping[cP->PlayerId] = false;
cP->customTag.Format(L"");
cP->Set_Object_Dirty_Bit(NetworkObjectClass::BIT_CREATION, true);
}
}
}
}
}
}
}
[Updated on: Sat, 08 September 2012 13:55] Report message to a moderator
|
|
|
Re: Is it possible to send player tag updates to select players [message #474111 is a reply to message #474093] |
Sat, 08 September 2012 14:19 |
iRANian
Messages: 4308 Registered: April 2011
Karma: 0
|
General (4 Stars) |
|
|
You should modify this for-loop from:
for (int i = 0;i < SpectatingPlayers.Count();i++)
To:
for (int i = 0, e = SpectatingPlayers.Count();i < e;i++)
The latter is more efficient, the ::Count() function gets called for every iteration of the loop. This is the reason why this is done in the clang compiler source code.
Also you should use GetTickCount64(), it's a more efficient (the engine uses GetTickCount() in a few places, but that one rolls around every 45 days or so, GetTickCount64() rolls around every 5 million years).
Long time and well respected Renegade community member, programmer, modder and tester.
Scripts 4.0 private beta tester since May 2011.
My Renegade server plugins releases
|
|
|
|
|
|
|