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

[L4D-REQ] Remember Spectators


Post New Thread Reply   
 
Thread Tools Display Modes
bman87
Senior Member
Join Date: Dec 2008
Location: Michigan
Old 08-19-2009 , 08:37   Re: [L4D-REQ] Remember Spectators
Reply With Quote #21

I don't know how to use arrays very well, it looks like using an ADT array would be a lot easier.

If we store the STEAMID string in the array and use the function FindStringInArray() to see if it does not return -1, then move the client to spectators.
Then we could use the RemoveFromArray() function on the index that FindStringInArray() returned

Last edited by bman87; 08-19-2009 at 08:43.
bman87 is offline
bman87
Senior Member
Join Date: Dec 2008
Location: Michigan
Old 08-19-2009 , 09:07   Re: [L4D-REQ] Remember Spectators
Reply With Quote #22

Thanks for the help olj!

This compiles, but not tested yet. Can't test it at work.. =/

PHP Code:
#include <sourcemod>

#define VERSION "1.0"

new Handle:g_adtArray;
new 
roundCount 0;
new 
bool:g_isMapChange false;

public 
Plugin:myinfo =
{
    
name "Remember Spectator Team",
    
author "B-man",
    
description "Remembers who was a spectator on map change",
    
version VERSION,
    
url "http://www.tchalo.com"
};

public 
OnPluginStart()
{
    
HookEvent("round_end",Event_RoundEnd);
    
g_adtArray CreateArray(64);
}

public 
OnMapStart()
{
    
roundCount 0;    //Reset round count
    
g_isMapChange false;    //Server is not changing map
}

public 
OnMapEnd()
{
    
g_isMapChange true;    //Map is changing
}

public 
Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    
roundCount++;
    
    
decl String:steamID[64];
    
    if (
roundCount == 2)
    {
        for (new 
1<= MaxClientsi++)
        {
            if (
GetClientTeam(i) == 1)    //finds spectators
            
{
                new 
client GetClientOfUserId(i)
                
GetClientAuthString(clientsteamID64);    //Gets the steamID
                
PushArrayString(g_adtArraysteamID);        //Add the steamID string to the array
            
}
        }
    }
}

public 
OnClientPostAdminCheck(client)
{
    
decl String:steamID[64];
    
GetClientAuthString(clientsteamID64);    //Get steamID
    
new arrayIndex FindStringInArray(g_adtArraysteamID);    //Returns the index where steamID was found -1 if not found
    
    
if (arrayIndex != -1)    //If the index is not -1
    
{
        
ChangeClientTeam(client1);        //change team to spectator
        
RemoveFromArray(g_adtArrayarrayIndex);    //remove that person from the array
    
}
}  

public 
OnClientDisconnect_Post(client)    //If everyone leaves, clear the array.
{
    if (
GetClientCount(false) == && !g_isMapChange)
    {
        
ClearArray(g_adtArray);
    }

Attached Files
File Type: sp Get Plugin or Get Source (l4d_spec_remember.sp - 228 views - 1.4 KB)

Last edited by bman87; 08-19-2009 at 11:10.
bman87 is offline
olj
Veteran Member
Join Date: Jun 2009
Old 08-19-2009 , 11:48   Re: [L4D-REQ] Remember Spectators
Reply With Quote #23

[quote=bman87;905419]Thanks for the help olj!

This compiles, but not tested yet. Can't test it at work.. =/

Well, it seems we all writing l4d plugins instead of actually WORKING. lol.
__________________
olj is offline
olj
Veteran Member
Join Date: Jun 2009
Old 08-19-2009 , 11:52   Re: [L4D-REQ] Remember Spectators
Reply With Quote #24

Quote:
Originally Posted by bman87 View Post
Is using GetClientUserId() is the best fuction?
Notes: Retrieves a client's user id, which is an index incremented for every client that joins the server.

Does that get incremented on a map change since the clients are reconnecting?

GetClientAuthString() or GetClientSerial() might work better, much more unique than the user ID.


I am assuming hooking round_end for adding the spectators to the array instead of OnMapEnd() would be more safe.
Wait for the second round_end to fire for the map and store the spectators.

OnClientPostAdminCheck() is a much better idea than hooking player_team. =)
As for user IDs , they dont change on map change. Thats why it is valid choice. And yes, round end/start is more safe, but i'm noob and dont know how to use "%" operator properly to tell if the round is 2nd. (% can be used to check if number is odd or even). Anyway i see you wrote your code, gj. Dont have time to look at it though or test it.
__________________

Last edited by olj; 08-19-2009 at 11:58.
olj is offline
bman87
Senior Member
Join Date: Dec 2008
Location: Michigan
Old 08-19-2009 , 12:52   Re: [L4D-REQ] Remember Spectators
Reply With Quote #25

I just tested the plugin I posted and it did not work =(
bman87 is offline
bman87
Senior Member
Join Date: Dec 2008
Location: Michigan
Old 08-19-2009 , 14:25   Re: [L4D-REQ] Remember Spectators
Reply With Quote #26

This one may work. I think I found a bug. I will have to test later.

I added debugging info print outs, dont use on a pub server unless you comment out the PrintToChatAll() lines.

PHP Code:
#include <sourcemod>

#define VERSION "1.0"

new Handle:g_adtArray;
new 
roundCount 0;
new 
bool:g_isMapChange false;

public 
Plugin:myinfo =
{
    
name "Remember Spectator Team",
    
author "B-man",
    
description "Remembers who was a spectator on map change",
    
version VERSION,
    
url "http://www.tchalo.com"
};

public 
OnPluginStart()
{
    
HookEvent("round_end",Event_RoundEnd);
    
g_adtArray CreateArray(ByteCountToCells(32));
}

public 
OnMapStart()
{
    
roundCount 0;    //Reset round count
    
g_isMapChange false;    //Server is not changing map
}

public 
OnMapEnd()
{
    
g_isMapChange true;    //Map is changing
}

public 
Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    
roundCount++;
    
PrintToChatAll("Round Count: %i"roundCount);
    
    if (
roundCount == 2)
    {
        
PrintToChatAll("Attempting to save spectators");
        for (new 
1<= MaxClientsi++)
        {
            if (
GetClientTeam(i) == 1)    //finds spectators
            
{
                
decl String:steamID[32];
                
PrintToChatAll("Found a spectator!");
                new 
client GetClientUserId(i)
                
GetClientAuthString(clientsteamIDsizeof(steamID));    //Gets the steamID
                
PushArrayString(g_adtArraysteamID);        //Add the steamID string to the array
                
PrintToChatAll("SteamID: %s"steamID);
            }
        }
    }
}

public 
OnClientPostAdminCheck(client)
{
    
decl String:steamID[32];
    
GetClientAuthString(clientsteamIDsizeof(steamID));    //Get steamID
    
new arrayIndex FindStringInArray(g_adtArraysteamID);    //Returns the index where steamID was found -1 if not found
    
PrintToChatAll("SteamID Checking: %s"steamID);
    
PrintToChatAll("Array Index: %i"arrayIndex);
    
    if (
arrayIndex != -1)    //If the index is not -1
    
{
        
PrintToChatAll("Attempting to change client team to spectator");
        
ChangeClientTeam(client1);        //change team to spectator
        
RemoveFromArray(g_adtArrayarrayIndex);    //remove that person from the array
    
}
}  

public 
OnClientDisconnect_Post(client)    //If everyone leaves, clear the array.
{
    if (
GetClientCount(false) == && !g_isMapChange)
    {
        
PrintToChatAll("Clearing Array");
        
ClearArray(g_adtArray);
    }

bman87 is offline
olj
Veteran Member
Join Date: Jun 2009
Old 08-19-2009 , 15:10   Re: [L4D-REQ] Remember Spectators
Reply With Quote #27

GetClientAuthString(client, steamID, sizeof(steamID)); //Gets the steamID


This function require s client index - not user ID. Replace "client" with "i" there. (Talking about round_end event callback only. PostAdmincCheck function seems to be fine)
__________________

Last edited by olj; 08-19-2009 at 15:18.
olj is offline
bman87
Senior Member
Join Date: Dec 2008
Location: Michigan
Old 08-19-2009 , 15:20   Re: [L4D-REQ] Remember Spectators
Reply With Quote #28

Thanks for the tip! I will try this later today

Last edited by bman87; 08-19-2009 at 15:28.
bman87 is offline
bman87
Senior Member
Join Date: Dec 2008
Location: Michigan
Old 08-19-2009 , 17:43   Re: [L4D-REQ] Remember Spectators
Reply With Quote #29

It works! I posted the plugin in the New Plugins forum.
bman87 is offline
olj
Veteran Member
Join Date: Jun 2009
Old 08-19-2009 , 19:15   Re: [L4D-REQ] Remember Spectators
Reply With Quote #30

Nice. Born from a dream plugin
__________________
olj 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 17:30.


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