dataviruset / sm-hosties

The ultimate jailbreak plugin for SourceMod
https://forums.alliedmods.net/forumdisplay.php?f=155
GNU General Public License v3.0
29 stars 27 forks source link

Issue with API #84

Open Hexer10 opened 7 years ago

Hexer10 commented 7 years ago

I'm trying to use the sm_hosties API, but I cannot get it work, seems like i've done all but the LR never starts. The code:

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <cstrike>
#include <hexstocks>
#include <emitsoundany>
#include <hosties>
#include <lastrequest>

#pragma newdecls required
#pragma semicolon 1

#define PLUGIN_AUTHOR "Hexah"
#define PLUGIN_VERSION "1.00"

//Handle
Menu WeapMenu = null;
Menu HPMenu = null;
Handle hTimer = null;

int LR_GunFight = 0;
int LRType = 0;
int LR_Guard = 0;
int LR_Terror = 0;
int iLRHealth = 0;
int iDelay = 4;

char sLRWeap[32];
char Sound[64][5];

public Plugin myinfo = 
{
    name = "GunFight LR", 
    author = PLUGIN_AUTHOR, 
    description = "", 
    version = PLUGIN_VERSION, 
    url = "csitajb.it"
};

//Startup
public void OnPluginStart()
{
    //Create menu for weapons
    WeapMenu = new Menu(hLRWeapon);
    WeapMenu.SetTitle("Choose your weapon!");
    WeapMenu.AddItem("awp", "AWP");
    WeapMenu.AddItem("m4a1", "M4A4");
    WeapMenu.AddItem("deagle", "Deagle");
    WeapMenu.AddItem("ak47", "AK47");
    SetMenuExitButton(WeapMenu, true);

    //Create menu for HPs
    HPMenu = new Menu(hLRHP);
    HPMenu.SetTitle("Choose the HP");
    HPMenu.AddItem("100", "100");
    HPMenu.AddItem("200", "200");
    HPMenu.AddItem("350", "350");
    HPMenu.AddItem("500", "500");
    SetMenuExitButton(HPMenu, true);
}

public void OnPluginEnd()
{
    //Remove LR on unload
    RemoveLastRequestFromList(OnLRStart, OnLREnd, "GunFight");
}

public void OnConfigsExecuted()
{
    //Add LR
    static bool bAddedLR = false;
    if (!bAddedLR)
    {
        LR_GunFight = AddLastRequestToList(OnLRStart, OnLREnd, "GunFight", false);
        bAddedLR = true;
    }
}

public void OnMapStart()
{
    //Precache all sounds
    PrecacheSoundAny("sound/sm_hosties/noscopestart1.mp3");
    for (int i = 1; i <= 5; i++)
    {
        Format(Sound[i - 1], sizeof(Sound[]), "sound/timeleft/en/unreal/%isec.mp3", i);
        PrecacheSoundAny(Sound[i - 1]);
    }

}

//Events
public int OnLRStart(Handle LR_Array, int ArrayIndex)
{
    LRType = GetArrayCell(LR_Array, ArrayIndex, view_as<int>(Block_LRType)); // get this lr from selection
    if (LRType == LR_GunFight)
    {
        LR_Guard = GetArrayCell(LR_Array, ArrayIndex, view_as<int>(Block_Guard)); //Get Guard index
        LR_Terror = GetArrayCell(LR_Array, ArrayIndex, view_as<int>(Block_Prisoner)); //Get Prisoner index

        CheckDataPack(LR_Array, ArrayIndex); //Check data pack?

        DisplayMenu(WeapMenu, LR_Terror, MENU_TIME_FOREVER); //Display the menu.

        PrintToChat(LR_Guard, "\x04[SM] \x01The player %N selected to you as a partner in his lastrequest.", LR_Terror);
    }
}

public void PreInitializeLR()
{
    for (int i = 1; i <= MaxClients; i++)
        EmitSoundToAllAny(Sound[4]); //Play first sound
    StripAllPlayerWeapons(LR_Guard); //Remove Guard Weapons
    StripAllPlayerWeapons(LR_Terror); //Remove Prisoner Weapons
    PrintToHud(LR_Guard, "5", 0.9, -1.0, -1.0, 255, 255, 100, 100); 
    PrintToHud(LR_Terror, "5", 0.9, -1.0, -1.0, 255, 255, 100, 100);
    PrintToChatAll("[SM] LR sta per iniziare!");
    GivePlayerItem(LR_Guard, "weapon_knife"); //Give Knife
    GivePlayerItem(LR_Terror, "weapon_knife"); //Give knife
    hTimer = CreateTimer(1.0, Timer_CountDown, _, TIMER_REPEAT); //Preparation timer
}

public Action Timer_CountDown(Handle timer)
{
    if (iDelay == 0)
    {
        //Real start LR
        EmitSoundToAllAny("sound/sm_hosties/noscopestart1.mp3");
        GivePlayerItem(LR_Guard, sLRWeap);
        GivePlayerItem(LR_Terror, sLRWeap);
        SetEntityHealth(LR_Guard, iLRHealth);
        SetEntityHealth(LR_Terror, iLRHealth);
        iDelay = 4;
        InitializeLR(LR_Terror);
        return Plugin_Stop;
    }
    char sDelay[8];
    IntToString(iDelay, sDelay, sizeof(sDelay));
    iDelay--;
    PrintToHud(LR_Guard, sDelay, 0.9, -1.0, -1.0, 255, 255, 100, 100);
    PrintToHud(LR_Terror, sDelay, 0.9, -1.0, -1.0, 255, 255, 100, 100);
    EmitSoundToAllAny(Sound[iDelay]);
    return Plugin_Continue;
}

//Reset variables on LR end
public int OnLREnd(int type, int prisioner, int guard)
{
    if (hTimer != null)
    {
        delete hTimer;
    }
    LR_GunFight = 0;
    LRType = 0;
    LR_Guard = 0;
    LR_Terror = 0;
    iLRHealth = 0;
    iDelay = 4;
    strcopy(sLRWeap, sizeof(sLRWeap), "");
}

void CheckDataPack(Handle LR_Array, int ArrayIndex)
{
    int LR_Pack_Value = GetArrayCell(LR_Array, ArrayIndex, view_as<int>(Block_Global1));
    switch (LR_Pack_Value)
    {
        case  - 1:
        {
            PrintToServer("no info included");
        }
    }

    SetArrayCell(LR_Array, ArrayIndex, 3, view_as<int>(Block_Global1));
}

//Menu
public int hLRWeapon(Menu menu, MenuAction action, int param1, int param2)
{
    if (action == MenuAction_Select)
    {
        menu.GetItem(param2, sLRWeap, sizeof(sLRWeap));
        Format(sLRWeap, sizeof(sLRWeap), "weapon_%s", sLRWeap);
        DisplayMenu(HPMenu, param1, MENU_TIME_FOREVER);
    }
}

public int hLRHP(Menu menu, MenuAction action, int param1, int param2)
{
    if (action == MenuAction_Select)
    {
        char info[16];
        menu.GetItem(param2, info, sizeof(info));
        iLRHealth = StringToInt(info);
        PreInitializeLR();
    }
}

PS: I've done a post on AM too (but I had no replies), check that for more infos: https://forums.alliedmods.net/showthread.php?t=299739

If you need any of the includes to help me I will give them.

data-bomb commented 7 years ago

So keep in mind that multiple LRs could be cycling through at the same time depending on the maximum LR convar. Try creating the menus each time you have the LR instead of globally in OnPluginStart. Also, do not use global variables to pass LR information.