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

How could I make this work!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Loading
Junior Member
Join Date: Jul 2008
Old 07-03-2008 , 13:59   How could I make this work!
Reply With Quote #1

ok so what I want to do is make a script that will play a song in TF2 if a round lasts longer then 90 mins and is then won this is what I has so far:

Code:
#include <sourcemod>
#include <sdktools>

#pragma semicolon 1

#define PLUGIN_VERSION "1"

public Plugin:myinfo = 
{
    name = "Champs +90 min win",
    author = "IDK",
    description = "Plays a song if the round last longer then 90 mins and is then won",
    version = PLUGIN_VERSION,
    url = "lol no"
};

new Handle:Champs = INVALID_HANDLE;
new bool:doChamps = true;

new Handle:Champsfile = INVALID_HANDLE;
new String:soundfile[PLATFORM_MAX_PATH] = "champs.mp3";

new roundStart = -1;

public OnPluginStart()
{
    champs = CreateConVar("sm_champs", "1", "Enables cmaps Finish", FCVAR_PLUGIN);
    HookConVarChange(champs, HookDochamps);
    
    champsfile = CreateConVar("sm_champsfile", "champs.mp3", "FIle to play upon a champs Finish", FCVAR_PLUGIN);
    HookConVarChange(champsfile, HookchampsFile);
    Precachechamps();
    
    if(!HookEventEx("teamplay_round_start", HookRoundStart, EventHookMode_PostNoCopy)
        || !HookEventEx("teamplay_round_win", HookRoundEnd, EventHookMode_PostNoCopy))
    {
        ThrowError("Could not hook teamplay_round_start or teamplay_round_win events. Looks like you are not the champs");
        return;
    }
}

public HookDochamps(Handle:convar, const String:oldValue[], const String:newValue[])
{
    dochamps = GetConVarBool(convar);
}

public HookchampsFile(Handle:convar, const String:oldValue[], const String:newValue[])
{
    strcopy(soundfile, sizeof(soundfile), newValue);
    
    Precachechamps();
}

Precachechamps()
{
    decl String:path[PLATFORM_MAX_PATH];
    Format(path, sizeof(path), "sound/%s", soundfile);
    
    if(!PrecacheSound(soundfile))
    {
        SetFailState("Failed to precache champs sound.");
        return;
    }
    
    AddFileToDownloadsTable(path);
}

public HookRoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
    roundStart = GetTime();
}

public HookRoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(!dochamps || roundStart < 0 || (GetTime() - roundStart) < (90 * 60))
        return;
    
    EmitSoundToAll(soundfile, SOUND_FROM_PLAYER, SNDCHAN_AUTO, SNDLEVEL_MINIBIKE);
    PrintToChatAll("We are the Champions!");///////////////
}
will this work and if not how can I make it work Thanks for any help.
Loading is offline
Loading
Junior Member
Join Date: Jul 2008
Old 07-03-2008 , 22:06   Re: How could I make this work!
Reply With Quote #2

Anyone? I don't mean to rush but wondering if anyone has any ideas.
Loading is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 07-03-2008 , 22:11   Re: How could I make this work!
Reply With Quote #3

Why don't you just create a timer for 90 minutes at the round start, and if the round ends, kill the timer. If the timer is triggered, have it play the sound you want. Also, make sure to give the timer the mapchange flag so it won't carry over.
bl4nk is offline
Loading
Junior Member
Join Date: Jul 2008
Old 07-03-2008 , 22:15   Re: How could I make this work!
Reply With Quote #4

I'm still rather new to source pawn so honestly I have no idea how to do that all i would need is an example of how to do that if you don't mind.
Loading is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 07-03-2008 , 22:36   Re: How could I make this work!
Reply With Quote #5

I misunderstood what you were asking for, but I'm writing something up for you that should do what you want.

[edit]

This should do what you want:
PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>

// Global Definitions
#define PLUGIN_VERSION "1.0.0"

new bool:isHooked false;
new 
bool:playSound false;

new 
Handle:cvarEnable;
new 
Handle:cvarSound;
new 
Handle:soundTimer INVALID_HANDLE;

// Functions
public Plugin:myinfo =
{
    
name "Champs +90 min win",
    
author "IDK",
    
description "Plays a song if the round last longer then 90 mins and is then won",
    
version PLUGIN_VERSION,
    
url "lol no"
};

public 
OnPluginStart()
{
    
cvarEnable CreateConVar("sm_champs""1""Enables cmaps Finish"FCVAR_PLUGINtrue0.0true1.0);
    
cvarSound CreateConVar("sm_shampsfile""champs.mp3""File to play upon a camps Finish"FCVAR_PLUGIN);

    
CreateTimer(3.0OnPluginStart_Delayed);
}

public 
Action:OnPluginStart_Delayed(Handle:timer)
{
    if (
GetConVarInt(cvarEnable))
    {
        
isHooked true;
        
HookEvent("teamplay_round_start"event_RoundStart);
        
HookEvent("teamplay_round_end"event_RoundEnd);
    }

    
PrecacheChamps();
    
HookConVarChange(cvarEnableCvarChange);
}

public 
CvarChange(Handle:convar, const String:oldValue[], const String:newValue[])
{
    if (!
GetConVarInt(cvarEnable))
    {
        if (
isHooked)
        {
            
isHooked false;
            
UnhookEvent("teamplay_round_start"event_RoundStart);
            
UnhookEvent("teamplay_round_end"event_RoundEnd);
        }
    }
    else if (!
isHooked)
    {
        
isHooked true;
        
HookEvent("teamplay_round_start"event_RoundStart);
        
HookEvent("teamplay_round_end"event_RoundEnd);
    }
}

public 
event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
    
playSound false;
    
soundTimer CreateTimer(5400.0timer_Sound_TIMER_FLAG_NO_MAPCHANGE);
}

public 
Action:timer_Sound(Handle:timer)
    
playSound true;

public 
event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    
KillSoundTimer();

    if (
playSound)
    {
        
decl String:soundFile[32];
        
GetConVarString(cvarSoundsoundFilesizeof(soundFile));

        
EmitSoundToAll(soundFile__SNDLEVEL_MINIBIKE);
        
PrintToChatAll("We are the Champions!");
    }
}

stock PrecacheChamps()
{
    
decl String:soundFile[32], String:path[PLATFORM_MAX_PATH];
    
GetConVarString(cvarSoundsoundFilesizeof(soundFile));
    
Format(pathsizeof(path), "sound/%s"soundFile);

    if (!
PrecacheSound(soundFile))
        
SetFailState("Failed to precache sound file: %s"soundFile);

    
AddFileToDownloadsTable(path);
}

stock KillSoundTimer()
{
    if (
soundTimer != INVALID_HANDLE)
        
KillTimer(soundTimer);


Last edited by bl4nk; 07-03-2008 at 22:48.
bl4nk is offline
Loading
Junior Member
Join Date: Jul 2008
Old 07-03-2008 , 23:23   Re: How could I make this work!
Reply With Quote #6

wow thank you. So this will just play a .mp3 in the sound folder named champs.mp3 if the round last's longer then 90 mins and is then won?
Loading is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 07-03-2008 , 23:24   Re: How could I make this work!
Reply With Quote #7

Yup. That is, if the events are right.
bl4nk is offline
Loading
Junior Member
Join Date: Jul 2008
Old 07-03-2008 , 23:32   Re: How could I make this work!
Reply With Quote #8

wonder if you can answer one more question probably a stupid one but how can I compile this I keep having to ask a Friend to do it and I want to learn how
Loading is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 07-04-2008 , 00:33   Re: How could I make this work!
Reply With Quote #9

You can either use the online compiler here or you can download a SourceMod package and use the provided exe's in the scripting folder.

http://wiki.alliedmods.net/Compiling_SourceMod_Plugins
bl4nk is offline
Loading
Junior Member
Join Date: Jul 2008
Old 07-04-2008 , 00:51   Re: How could I make this work!
Reply With Quote #10

I'll Test it I got it to compile

Last edited by Loading; 07-04-2008 at 03:34.
Loading 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 09:50.


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