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

Need a bit help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
stonedegg
Senior Member
Join Date: Nov 2011
Location: de_dust2
Old 01-07-2013 , 07:18   Need a bit help
Reply With Quote #1

Hello, I'm trying to fire an event when a sourcemod rockthevote was successfull which I want to read out in Eventscripts.
So this is what I got so far, but it seems not to fire the event:

Code:
/**
 * vim: set ts=4 :
 * =============================================================================
 * SourceMod Rock The Vote Plugin
 * Creates a map vote when the required number of players have requested one.
 *
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
 * =============================================================================
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, version 3.0, as published by the
 * Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * As a special exception, AlliedModders LLC gives you permission to link the
 * code of this program (as well as its derivative works) to "Half-Life 2," the
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
 * by the Valve Corporation.  You must obey the GNU General Public License in
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
 * this exception to all derivative works.  AlliedModders LLC defines further
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
 * or <http://www.sourcemod.net/license.php>.
 *
 * Version: $Id$
 */

#include <sourcemod>
#include <mapchooser>
#include <nextmap>

#pragma semicolon 1

public Plugin:myinfo =
{
    name = "Rock The Vote",
    author = "AlliedModders LLC",
    description = "Provides RTV Map Voting",
    version = SOURCEMOD_VERSION,
    url = "http://www.sourcemod.net/"
};

new Handle:g_Cvar_Needed = INVALID_HANDLE;
new Handle:g_Cvar_MinPlayers = INVALID_HANDLE;
new Handle:g_Cvar_InitialDelay = INVALID_HANDLE;
new Handle:g_Cvar_Interval = INVALID_HANDLE;
new Handle:g_Cvar_ChangeTime = INVALID_HANDLE;
new Handle:g_Cvar_RTVPostVoteAction = INVALID_HANDLE;

new bool:g_CanRTV = false;        // True if RTV loaded maps and is active.
new bool:g_RTVAllowed = false;    // True if RTV is available to players. Used to delay rtv votes.
new g_Voters = 0;                // Total voters connected. Doesn't include fake clients.
new g_Votes = 0;                // Total number of "say rtv" votes
new g_VotesNeeded = 0;            // Necessary votes before map vote begins. (voters * percent_needed)
new bool:g_Voted[MAXPLAYERS+1] = {false, ...};

new bool:g_InChange = false;

public OnPluginStart()
{
    LoadTranslations("common.phrases");
    LoadTranslations("rockthevote.phrases");
    
    g_Cvar_Needed = CreateConVar("sm_rtv_needed", "0.60", "Percentage of  players needed to rockthevote (Def 60%)", 0, true, 0.05, true, 1.0);
    g_Cvar_MinPlayers = CreateConVar("sm_rtv_minplayers", "0", "Number  of players required before RTV will be enabled.", 0, true, 0.0, true,  float(MAXPLAYERS));
    g_Cvar_InitialDelay = CreateConVar("sm_rtv_initialdelay", "30.0",  "Time (in seconds) before first RTV can be held", 0, true, 0.00);
    g_Cvar_Interval = CreateConVar("sm_rtv_interval", "240.0", "Time (in  seconds) after a failed RTV before another can be held", 0, true,  0.00);
    g_Cvar_ChangeTime = CreateConVar("sm_rtv_changetime", "0", "When to  change the map after a succesful RTV: 0 - Instant, 1 - RoundEnd, 2 -  MapEnd", _, true, 0.0, true, 2.0);
    g_Cvar_RTVPostVoteAction = CreateConVar("sm_rtv_postvoteaction",  "0", "What to do with RTV's after a mapvote has completed. 0 - Allow,  success = instant change, 1 - Deny", _, true, 0.0, true, 1.0);
    
    RegConsoleCmd("say", Command_Say);
    RegConsoleCmd("say_team", Command_Say);
    
    RegConsoleCmd("sm_rtv", Command_RTV);
    
    AutoExecConfig(true, "rtv");

    ServerCommand( "es_loadevents declare resource/rockthevote.res" );
}

public OnMapStart()
{
    g_Voters = 0;
    g_Votes = 0;
    g_VotesNeeded = 0;
    g_InChange = false;
    
    /* Handle late load */
    for (new i=1; i<=MaxClients; i++)
    {
        if (IsClientConnected(i))
        {
            OnClientConnected(i);    
        }    
    }
    ServerCommand( "es_loadevents resource/rockthevote.res" );
}

public OnMapEnd()
{
    g_CanRTV = false;    
    g_RTVAllowed = false;
}

public OnConfigsExecuted()
{    
    g_CanRTV = true;
    g_RTVAllowed = false;
    CreateTimer(GetConVarFloat(g_Cvar_InitialDelay), Timer_DelayRTV, _, TIMER_FLAG_NO_MAPCHANGE);
}

public OnClientConnected(client)
{
    if(IsFakeClient(client))
        return;
    
    g_Voted[client] = false;

    g_Voters++;
    g_VotesNeeded = RoundToFloor(float(g_Voters) * GetConVarFloat(g_Cvar_Needed));
    
    return;
}

public OnClientDisconnect(client)
{
    if(IsFakeClient(client))
        return;
    
    if(g_Voted[client])
    {
        g_Votes--;
    }
    
    g_Voters--;
    
    g_VotesNeeded = RoundToFloor(float(g_Voters) * GetConVarFloat(g_Cvar_Needed));
    
    if (!g_CanRTV)
    {
        return;    
    }
    
    if (g_Votes && 
        g_Voters && 
        g_Votes >= g_VotesNeeded && 
        g_RTVAllowed ) 
    {
        if (GetConVarInt(g_Cvar_RTVPostVoteAction) == 1 && HasEndOfMapVoteFinished())
        {
            return;
        }
        
        StartRTV();
    }    
}

public Action:Command_RTV(client, args)
{
    if (!g_CanRTV || !client)
    {
        return Plugin_Handled;
    }
    
    AttemptRTV(client);
    
    return Plugin_Handled;
}

public Action:Command_Say(client, args)
{
    if (!g_CanRTV || !client)
    {
        return Plugin_Continue;
    }
    
    decl String:text[192];
    if (!GetCmdArgString(text, sizeof(text)))
    {
        return Plugin_Continue;
    }
    
    new startidx = 0;
    if(text[strlen(text)-1] == '"')
    {
        text[strlen(text)-1] = '\0';
        startidx = 1;
    }
    
    new ReplySource:old = SetCmdReplySource(SM_REPLY_TO_CHAT);
    
    if (strcmp(text[startidx], "rtv", false) == 0 || strcmp(text[startidx], "rockthevote", false) == 0)
    {
        AttemptRTV(client);
    }
    
    SetCmdReplySource(old);
    
    return Plugin_Continue;    
}

AttemptRTV(client)
{
    if (!g_RTVAllowed  || (GetConVarInt(g_Cvar_RTVPostVoteAction) == 1 && HasEndOfMapVoteFinished()))
    {
        ReplyToCommand(client, "[SM] %t", "RTV Not Allowed");
        return;
    }
        
    if (!CanMapChooserStartVote())
    {
        ReplyToCommand(client, "[SM] %t", "RTV Started");
        return;
    }
    
    if (GetClientCount(true) < GetConVarInt(g_Cvar_MinPlayers))
    {
        ReplyToCommand(client, "[SM] %t", "Minimal Players Not Met");
        return;            
    }
    
    if (g_Voted[client])
    {
        ReplyToCommand(client, "[SM] %t", "Already Voted", g_Votes, g_VotesNeeded);
        return;
    }    
    
    new String:name[64];
    GetClientName(client, name, sizeof(name));
    
    g_Votes++;
    g_Voted[client] = true;
    
    PrintToChatAll("[SM] %t", "RTV Requested", name, g_Votes, g_VotesNeeded);
    
    if (g_Votes >= g_VotesNeeded)
    {
        StartRTV();
    }    
}

public Action:Timer_DelayRTV(Handle:timer)
{
    g_RTVAllowed = true;
}

StartRTV()
{
    if (g_InChange)
    {
        return;    
    }
    
    if (EndOfMapVoteEnabled() && HasEndOfMapVoteFinished())
    {
        /* Change right now then */
        new String:map[65];
        if (GetNextMap(map, sizeof(map)))
        {
            PrintToChatAll("[SM] %t", "Changing Maps", map);
            CreateTimer(5.0, Timer_ChangeMap, _, TIMER_FLAG_NO_MAPCHANGE);
            fireEvent2ES(map);
            g_InChange = true;
            
            ResetRTV();
            
            g_RTVAllowed = false;
        }
        return;    
    }
    
    if (CanMapChooserStartVote())
    {
        new MapChange:when = MapChange:GetConVarInt(g_Cvar_ChangeTime);
        InitiateMapChooserVote(when);
        
        ResetRTV();
        
        g_RTVAllowed = false;
        CreateTimer(GetConVarFloat(g_Cvar_Interval), Timer_DelayRTV, _, TIMER_FLAG_NO_MAPCHANGE);
    }
}

ResetRTV()
{
    g_Votes = 0;
            
    for (new i=1; i<=MAXPLAYERS; i++)
    {
        g_Voted[i] = false;
    }
}

public Action:Timer_ChangeMap(Handle:hTimer)
{
    g_InChange = false;
    
    LogMessage("RTV changing map manually");
    
    new String:map[65];
    if (GetNextMap(map, sizeof(map)))
    {    
        ForceChangeLevel(map, "RTV after mapvote");
    }
    
    return Plugin_Stop;
}

fireEvent2ES(String:map[65])
{

    new Handle:event = CreateEvent("rockthevote");
    if (event == INVALID_HANDLE)
    {
        PrintToServer("RockTheVote : --INVALID_HANDLE-- ");
        return;
    }
    SetEventString(event, "nextmap", map);
    FireEvent(event);
}
This is how my .res file in ..cstrike/resource/ looks like:


Code:
"rockthevote"
{
    "rockthevote"
    {
        "string"    "nextmap"
    }
}
I took the code from this plugin: http://addons.eventscripts.com/addon...sm2es_keyPress which works perfectly in Eventscripts.
I hope somebody can help me, thanks in advance.
stonedegg is offline
Starbish
AlliedModders Donor
Join Date: Oct 2011
Location: South Korea
Old 01-07-2013 , 09:18   Re: Need a bit help
Reply With Quote #2

As i know, it's just a firing events which was defined like player_death and player_hurt.

you can't make new Events at least in SM.

but you can make a forward function but it can't be called in EventScripts.

so... you can make it with Socket if EventScript supports Socket Functions.

or SQL? but not recommended..
__________________
Starbish is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 01-07-2013 , 10:03   Re: Need a bit help
Reply With Quote #3

You could fire a ServerCommand and hook it in ES. Any reason why you don't just do it all in SM?
__________________
Dr. McKay is offline
stonedegg
Senior Member
Join Date: Nov 2011
Location: de_dust2
Old 01-07-2013 , 10:34   Re: Need a bit help
Reply With Quote #4

I like scripting in Eventscripts and I use plugins on both sides.
Could you create a servercommand for me and fire it when rtv was successful?
Starbish, did you see the link I posted in the end? This is a Sourcemod plugin that helps me detecting key presses in Eventscripts. I tried to use the same code to fire a new event, but it doesn't work.
Couldn't you reproduce the code from sm2es_keypress?
Another possibility could be creating a server variable which can be set to 1 or 0. On plugin load and map start it would be 0 and if rtv was successful, put it to 1.

Last edited by stonedegg; 01-07-2013 at 10:54.
stonedegg is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 01-07-2013 , 13:35   Re: Need a bit help
Reply With Quote #5

Just change the FireEvent2ES line to ServerCommand("es_rtv_nextmap") or something.
__________________
Dr. McKay is offline
stonedegg
Senior Member
Join Date: Nov 2011
Location: de_dust2
Old 01-07-2013 , 20:51   Re: Need a bit help
Reply With Quote #6

Okay I got a weird bug that I don't understand.
I created in ES a ServerCommand named sm_es_rtv.
Now, when I put
ServerCommand("sm_es_rtv");
into the part where a player says "rtv", the command gets fired and I receive a message in Eventscripts.
But if I put it into the part where the map changes, nothing happens Also when I replace this fireEvent2ES with the server command, nothing happens.

Why is it not working everytime? Any Ideas?
stonedegg is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 01-08-2013 , 13:29   Re: Need a bit help
Reply With Quote #7

As for your original issue, you didn't correctly copy the calls to es_loadevents.
__________________
asherkin is offline
stonedegg
Senior Member
Join Date: Nov 2011
Location: de_dust2
Old 01-08-2013 , 16:32   Re: Need a bit help
Reply With Quote #8

And what is wrong?

Maybe anyone could tell me why the command is working when I say rtv:

Code:
AttemptRTV(client)
{
    if (!g_RTVAllowed  || (GetConVarInt(g_Cvar_RTVPostVoteAction) == 1 && HasEndOfMapVoteFinished()))
    {
        ReplyToCommand(client, "[SM] %t", "RTV Not Allowed");
        ServerCommand("sm_es_rtv");
        return;
    }
        
    if (!CanMapChooserStartVote())
    {
        ReplyToCommand(client, "[SM] %t", "RTV Started");
        ServerCommand("sm_es_rtv");
        return;
    }


But not when a rtv was successful:

Code:
StartRTV()
{
    if (g_InChange)
    {
        return;    
    }
    
    if (EndOfMapVoteEnabled() && HasEndOfMapVoteFinished())
    {
        /* Change right now then */
        new String:map[65];
        if (GetNextMap(map, sizeof(map)))
        {
            PrintToChatAll("[SM] %t", "Changing Maps", map);
            CreateTimer(5.0, Timer_ChangeMap, _, TIMER_FLAG_NO_MAPCHANGE);
            g_InChange = true;
            ServerCommand("sm_es_rtv");
            
            ResetRTV();
            
            g_RTVAllowed = false;

Last edited by stonedegg; 01-09-2013 at 09:54.
stonedegg is offline
stonedegg
Senior Member
Join Date: Nov 2011
Location: de_dust2
Old 01-15-2013 , 08:23   Re: Need a bit help
Reply With Quote #9

Can anyone help me please?
stonedegg is offline
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 01-15-2013 , 16:08   Re: Need a bit help
Reply With Quote #10

Quote:
Originally Posted by stonedegg View Post
And what is wrong?

Maybe anyone could tell me why the command is working when I say rtv:

Code:
AttemptRTV(client)
{
    if (!g_RTVAllowed  || (GetConVarInt(g_Cvar_RTVPostVoteAction) == 1 && HasEndOfMapVoteFinished()))
    {
        ReplyToCommand(client, "[SM] %t", "RTV Not Allowed");
        ServerCommand("sm_es_rtv");
        return;
    }
        
    if (!CanMapChooserStartVote())
    {
        ReplyToCommand(client, "[SM] %t", "RTV Started");
        ServerCommand("sm_es_rtv");
        return;
    }
But not when a rtv was successful:

Code:
StartRTV()
{
    if (g_InChange)
    {
        return;    
    }
    
    if (EndOfMapVoteEnabled() && HasEndOfMapVoteFinished())
    {
        /* Change right now then */
        new String:map[65];
        if (GetNextMap(map, sizeof(map)))
        {
            PrintToChatAll("[SM] %t", "Changing Maps", map);
            CreateTimer(5.0, Timer_ChangeMap, _, TIMER_FLAG_NO_MAPCHANGE);
            g_InChange = true;
            ServerCommand("sm_es_rtv");
            
            ResetRTV();
            
            g_RTVAllowed = false;
that last part will only run if the map is already decided, so it will change the map without making a vote. if you want the server command to happen after the end of the vote, you need to change the plugin mapchooser.sp, which is the one who makes the votes. run the command ServerCommand after this too:
Code:
public Handler_MapVoteFinished(Handle:menu,
                           num_votes, 
                           num_clients,
                           const client_info[][2], 
                           num_items,
                           const item_info[][2])
{
Bimbo1 is offline
Reply


Thread Tools
Display Modes

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:39.


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