Помогите переделать JetPack

Тема в разделе "Counter-Strike: Source", создана пользователем Вова Галик 552892780, 23 окт 2015.

  1. Вова Галик 552892780

    Вова Галик 552892780

    Сообщения:
    173
    Симпатии:
    37
    Помогите сделать в первом плагине так как во втором когда биндишь кнопку bind mouse3 +sm_jetpack и после зажатия её то ты взлетаешь когда отпускаешь то джетпак отключается

    №1
    Код:
    #include <sourcemod>
    #include <sdktools>
    #include <morecolors>
    new fuel[MAXPLAYERS+1]
    new fuelreset[MAXPLAYERS+1]
    new Handle:player[MAXPLAYERS+1]
    //new Handle:g_password;
    new Handle:g_fuel;
    new Handle:g_fuelreset;
    
    //new Float:Location[3];
    //This plugin must not be sold!
    
    public Plugin:myinfo =
    {
    name = "Adv Jetpack",
    author = "ShadowDragon",
    description = "a private plugin request for R@ Blackglade",
    version = "1.0",
    url = ""
    
    }
    
    public OnPluginStart()
    {
    AutoExecConfig();
    RegConsoleCmd("sm_jet", Command_jet);
    //g_password = CreateConVar("sm_jetpassword", "1", "Password to run the plugin", 0, true, 0.0);
    g_fuel = CreateConVar("sm_jetfuel", "10", "The amount of time the jet pack will last", 0, true, 0.0);
    g_fuelreset = CreateConVar("sm_jetfuelreset", "30", "The amount of time it takes to refule", 0, true, 0.0);
    
    }
    
    public OnMapStart()
    {
    PrecacheSound("jetpack/jetpack.wav");
    PrecacheSound("jetpack/redalert.wav");
    PrecacheSound("jetpack/cloak.wav");
    }
    public OnClientPutInServer(client)
    {
    
    }
    
    public Action:Command_jet(client, args)
    {
    if (client && IsClientInGame(client))
    {
    //new value;
    //value = GetConVarInt(g_password)
    new peet;
    peet = GetConVarInt(g_fuel)
    
    //if(value == 1013410)
    //{
    if(fuel[client] < 2)
    {
    
    if(fuel[client] < peet)
    {
    SetEntityMoveType(client, MOVETYPE_FLY);
    
    CPrintToChat(client, "{darkblue}[JetPack] {cyan}Your Jet Pack Has Been Activated")
    
    }
    }
    if(fuel[client] > peet)
    {
    
    CPrintToChat(client, "{darkblue}[JetPack] {cyan}Refueling in progress!")
    
    }
    
    if(fuel[client] < 2)
    {
    if (!IsFakeClient(client))
    {
    // 60 * 4
    player[client] = CreateTimer(1.0, Timer_Show, client, TIMER_REPEAT);
    
    }
    
    EmitSoundToClient(client, "jetpack/jetpack.wav", client, 1);
    
    }
    
    //}
    else
    {
    CPrintToChat(client, "{darkblue}[JetPack] {cyan}Plugin will not start till the password is correct!")
    }
    
    }
    }
    
    /*stock spark(client)
    {
    new Handle:event;
    Location[0] = GetEventFloat(event,"x");
    Location[1] = GetEventFloat(event,"y");
    Location[2] = GetEventFloat(event,"z");
    TE_SetupSmoke(Location,Location,255,1);
    TE_SendToClient(client);
    }*/
    
    /*public Action:fuel_f(Handle:timer, any:client)
    {
    
    new peet;
    peet = GetConVarInt(g_fuel)
    if(fuel[client] == peet)
    {
    fuel[client] = 0;
    SetEntityMoveType(client, MOVETYPE_WALK);
    }
    fuel[client]++;
    }*/
    
    public Action:Timer_Show(Handle:timer, any:client)
    {
    
    if (IsClientInGame(client) && !IsFakeClient(client))
    {
    new peet;
    peet = GetConVarInt(g_fuel)
    new refuel;
    refuel = GetConVarInt(g_fuelreset)
    if(fuel[client] == peet)
    {
    EmitSoundToClient(client, "jetpack/redalert.wav", client, 2);
    StopSound(client, 1, "jetpack/jetpack.wav");
    CPrintToChat(client, "{darkblue}[JetPack] {cyan}Your Jet Pack Has Run Out Of Fuel!")
    SetEntityMoveType(client, MOVETYPE_WALK);
    }
    if(fuel[client] == refuel)
    {
    fuel[client] = 0;
    fuelreset[client] = 0;
    StopSound(client, 2, "jetpack/jetpack.wav");
    EmitSoundToClient(client, "jetpack/cloak.wav", client, 2);
    KillTimer(player[client]);
    CPrintToChat(client, "{darkblue}[JetPack] {cyan}Your Jet Pack Is Now Ready To Use!")
    
    }
    
    //spark(client);
    fuel[client]++;
    fuelreset[client]++;
    
    return Plugin_Continue;
    }
    
    return Plugin_Stop;
    }

    №2
    Код:
    #pragma semicolon 1
    
    #include <sourcemod>
    #include <sdktools>
    
    #define PLUGIN_VERSION "1.1.0"
    
    #define MOVETYPE_WALK            2
    #define MOVETYPE_FLYGRAVITY        5
    #define MOVECOLLIDE_DEFAULT        0
    #define MOVECOLLIDE_FLY_BOUNCE    1
    
    #define LIFE_ALIVE    0
    
    #define JETPACK_LIMIT 5
    
    // ConVars
    new Handle:sm_jetpack            = INVALID_HANDLE;
    new Handle:sm_jetpack_sound        = INVALID_HANDLE;
    new Handle:sm_jetpack_speed        = INVALID_HANDLE;
    new Handle:sm_jetpack_volume    = INVALID_HANDLE;
    
    // SendProp Offsets
    new g_iLifeState    = -1;
    new g_iMoveCollide    = -1;
    new g_iMoveType        = -1;
    new g_iVelocity        = -1;
    
    // Soundfile
    new String:g_sSound[255]    = "vehicles/airboat/fan_blade_fullthrottle_loop1.wav";
    
    // Is Jetpack Enabled
    new bool:g_bJetpacks[MAXPLAYERS + 1]    = {false,...};
    new bool:g_bAllowedToUseJetpack[MAXPLAYERS+1] = {false,...};
    
    new Float:g_flJetpackLength[MAXPLAYERS+1] = {0.0,...};
    
    // Timer For GameFrame
    new Float:g_fTimer    = 0.0;
    
    // MaxClients
    new g_iMaxClients    = 0;
    
    public Plugin:myinfo =
    {
        name = "Jetpack",
        author = "Knagg0",
        description = "",
        version = PLUGIN_VERSION,
        url = "http://www.mfzb.de"
    };
    
    public OnPluginStart()
    {
        AutoExecConfig();
        
        // Create ConVars
        CreateConVar("sm_jetpack_version", PLUGIN_VERSION, "", FCVAR_PLUGIN | FCVAR_REPLICATED | FCVAR_NOTIFY);
        sm_jetpack = CreateConVar("sm_jetpack", "1", "", FCVAR_PLUGIN | FCVAR_REPLICATED | FCVAR_NOTIFY);
        sm_jetpack_sound = CreateConVar("sm_jetpack_sound", g_sSound, "", FCVAR_PLUGIN);
        sm_jetpack_speed = CreateConVar("sm_jetpack_speed", "100", "", FCVAR_PLUGIN);
        sm_jetpack_volume = CreateConVar("sm_jetpack_volume", "0.5", "", FCVAR_PLUGIN);
        
        HookEvent( "player_spawn", EventPlayerSpawn_Post, EventHookMode_Post );
    
        // Create ConCommands
        RegConsoleCmd("+sm_jetpack", JetpackP, "", FCVAR_GAMEDLL);
        RegConsoleCmd("-sm_jetpack", JetpackM, "", FCVAR_GAMEDLL);
        
        // Find SendProp Offsets
        if((g_iLifeState = FindSendPropOffs("CBasePlayer", "m_lifeState")) == -1)
            LogError("Could not find offset for CBasePlayer::m_lifeState");
            
        if((g_iMoveCollide = FindSendPropOffs("CBaseEntity", "movecollide")) == -1)
            LogError("Could not find offset for CBaseEntity::movecollide");
            
        if((g_iMoveType = FindSendPropOffs("CBaseEntity", "movetype")) == -1)
            LogError("Could not find offset for CBaseEntity::movetype");
            
        if((g_iVelocity = FindSendPropOffs("CBasePlayer", "m_vecVelocity[0]")) == -1)
            LogError("Could not find offset for CBasePlayer::m_vecVelocity[0]");
    }
    
    public Action:EventPlayerSpawn_Post(Handle:event,const String:name[],bool:dontBroadcast)
    {
        new client_id = GetEventInt(event, "userid");
        new client = GetClientOfUserId(client_id);
        g_bAllowedToUseJetpack[client] = true;
    }
    
    public OnMapStart()
    {
        g_fTimer = 0.0;
        g_iMaxClients = GetMaxClients();
    }
    
    public OnConfigsExecuted()
    {
        GetConVarString(sm_jetpack_sound, g_sSound, sizeof(g_sSound));
        PrecacheSound(g_sSound, true);
    }
    
    public OnGameFrame()
    {
        if(GetConVarBool(sm_jetpack) && g_fTimer < GetGameTime() - 0.075)
        {
            g_fTimer = GetGameTime();
            
            for(new i = 1; i <= g_iMaxClients; i++)
            {
                if(g_bJetpacks[i])
                {
                    if(!IsAlive(i)) StopJetpack(i);
                    else 
                    {
                        if( !g_flJetpackLength[i] )
                            g_flJetpackLength[i] = GetGameTime() + JETPACK_LIMIT.0;
                        if(g_flJetpackLength[i] && g_flJetpackLength[i]>GetGameTime())
                            AddVelocity(i, GetConVarFloat(sm_jetpack_speed));
                        else
                            StopJetpack(i);
                    }
                }
            }
        }
    }
    
    public OnClientDisconnect(client)
    {
        StopJetpack(client);
    }
    
    public Action:JetpackP(client, args)
    {
        if(GetConVarBool(sm_jetpack) && !g_bJetpacks[client] && IsAlive(client) && g_bAllowedToUseJetpack[client] )
        {
            new Float:vecPos[3];
            GetClientAbsOrigin(client, vecPos);
            EmitSoundToAll(g_sSound, client, SNDCHAN_AUTO, SNDLEVEL_NORMAL, SND_NOFLAGS, GetConVarFloat(sm_jetpack_volume), SNDPITCH_NORMAL, -1, vecPos, NULL_VECTOR, true, 0.0);
            SetMoveType(client, MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE);
            g_bJetpacks[client] = true;
        }
        
        return Plugin_Continue;
    }
    
    public Action:JetpackM(client, args)
    {
        StopJetpack(client);
        return Plugin_Continue;
    }
    
    StopJetpack(client)
    {
        if(g_bJetpacks[client])
        {
            if(IsAlive(client)) SetMoveType(client, MOVETYPE_WALK, MOVECOLLIDE_DEFAULT);
            StopSound(client, SNDCHAN_AUTO, g_sSound);
            g_bJetpacks[client] = false;
        }
        g_flJetpackLength[client] = 0.0;
        g_bAllowedToUseJetpack[client] = false;
    }
    
    SetMoveType(client, movetype, movecollide)
    {
        if(g_iMoveType == -1) return;
        SetEntData(client, g_iMoveType, movetype);
        if(g_iMoveCollide == -1) return;
        SetEntData(client, g_iMoveCollide, movecollide);
    }
    
    AddVelocity(client, Float:speed)
    {
        if(g_iVelocity == -1) return;
        
        new Float:vecVelocity[3];
        GetEntDataVector(client, g_iVelocity, vecVelocity);
        
        vecVelocity[2] += speed;
    
        TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, vecVelocity);
    }
    
    bool:IsAlive(client)
    {
        if(g_iLifeState != -1 && GetEntData(client, g_iLifeState, 1) == LIFE_ALIVE)
            return true;
    
        return false;
    }