AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   MVMVictory HookUserMessage (https://forums.alliedmods.net/showthread.php?t=325291)

Gurrth 06-15-2020 19:09

MVMVictory HookUserMessage
 
Hi all, I'd like to use the User Message MVMVictory, and hook it with HookUserMessage.

Basically, I'd like sm_resetpopfile to be sent once it's been hooked with MVMVictory after a mann vs machine match was completed.

I've tried it with this code, I don't exactly know what type of public action to use for it.

Code:

#include <sourcemod>
#include <sdktools>
#include <tf2>
#include <sdkhooks>
#include <events>

public Plugin:myinfo =
{
        name = "[TF2]Reset Popfile",
        author = "Gurrth",
        description = "Resets current Popfile after a MVM Mission Completes, no map change",
        version = "1.0",
        url = ""
}

public OnPluginStart()
{
       
       

       
        PrintToServer("[SM] Rest Pop Files is Loaded!");
       
       
        RegConsoleCmd("sm_resetpopfile", command_resetpopfile, "resets popfile");
       
       
        HookUserMessage(GetUserMessageId("MVMVictory" ), mvm_complete, true);
       
}




// What sm_resetpopfile does
public Action:command_resetpopfile(client, args)
{
       
        char responseBuffer[4096];
        int ObjectiveEntity = FindEntityByClassname(-1, "tf_objective_resource");
       
       
        // Get Popfile Name
        GetEntPropString(ObjectiveEntity, Prop_Send, "m_iszMvMPopfileName", responseBuffer, sizeof(responseBuffer));
       
        // Tell server to change popfile
        ServerCommand("tf_mvm_popfile %s", ObjectiveEntity);
       
}


PC Gamer 06-16-2020 20:01

Re: MVMVictory HookUserMessage
 
I haven't used HookUserMessage before. But... after reading these:

https://sm.alliedmods.net/new-api/us...ookUserMessage
https://wiki.alliedmods.net/User_mes..._User_Messages

I would probably do something like this:

PHP Code:

#include <sourcemod>
#include <sdktools>

public Plugin:myinfo 
{
    
name "[TF2]Reset Popfile",
    
author "Gurrth",
    
description "Resets current Popfile after a MVM Mission Completes, no map change",
    
version "1.0",
    
url ""
}

public 
OnPluginStart()
{
    
RegConsoleCmd("sm_resetpopfile"command_resetpopfile"resets popfile");
    
    
HookUserMessage(GetUserMessageId("MVMVictory" ), mvm_completetrue); 
}

public 
Action:mvm_complete(UserMsg:msg_idHandle:bf, const players[], playersNumbool:reliablebool:init
{
    
char responseBuffer[4096];
    
int ObjectiveEntity FindEntityByClassname(-1"tf_objective_resource");

    
// Get Popfile Name
    
GetEntPropString(ObjectiveEntityProp_Send"m_iszMvMPopfileName"responseBuffersizeof(responseBuffer));
    
    
// Tell server to change popfile 
    
ServerCommand("tf_mvm_popfile %s"ObjectiveEntity);
}

public 
Action:command_resetpopfile(clientargs)
{
    
char responseBuffer[4096];
    
int ObjectiveEntity FindEntityByClassname(-1"tf_objective_resource");
    
    
// Get Popfile Name
    
GetEntPropString(ObjectiveEntityProp_Send"m_iszMvMPopfileName"responseBuffersizeof(responseBuffer));
    
    
// Tell server to change popfile 
    
ServerCommand("tf_mvm_popfile %s"ObjectiveEntity);


Note: Not tested since I gave up on running MvM long ago after it kept kicking all players every mapchange. I never did receive a solution to that problem. Anyway, I hope this works for you.


All times are GMT -4. The time now is 23:56.

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