Quantcast
Channel: Forum VeryGames
Viewing all articles
Browse latest Browse all 5196

[HELP] Evil Deagle

$
0
0
Bonjour,

J'ai un plugin Evil Deagle (Deagle magique) et je suis obligé de le réactiver a chaque changement de carte ou reboot du serveur, je voudrais savoir si il serais possible de mettre le plugin en "Enable" directement apres un changement de map ou reboot du serveur sans avoir a faire de manipulation In Game par moi.
Voilà le code :

Code PHP:

/*

    Evil Deagle.

*/

#include <sourcemod>
#include <sdktools>
#undef REQUIRE_PLUGIN
#include <adminmenu>

#define NAME "Evil Deagle"
#define VERSION "1.3"

/* the admin flag required for the menu and all commands */
#define ADMFLAG ADMFLAG_RCON

new Handle:g_hAdminMenu;
new 
bool:g_bEnabled;
new 
Handle:g_hSpawnsADT;
new 
Handle:g_cvarEfxColor;
new 
Handle:g_cvarRecoilMulFloat:g_fRecoilMul;
new 
Handle:g_cvarDamageString:g_sDamage[8];
new 
g_iPointHurtg_iEDEntityIndexg_iEDOwnerIndexFloat:g_fLastPosVec[3], bool:g_bIsRoundEnd;
new 
g_ihOwnerEntityg_iiClip1g_iiAmmo;
new 
g_iRingColor[4], g_iBeamSpriteg_iHaloSpriteg_iGlowSprite;
new 
String:g_sMapCfgPath[PLATFORM_MAX_PATH];

public 
Plugin:myinfo 
{
    
name NAME,
    
author "meng",
    
version VERSION,
    
description "special deagle for CSS",
    
url "http://www.sourcemod.net"
};

public 
OnPluginStart()
{
    
CreateConVar("sm_evildeagle_version"VERSIONNAMEFCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
    
g_cvarEfxColor CreateConVar("sm_evildeagle_efxcolor""0""The color of the evil deagle's location effects. [0 = red | 1 = gold]"_true0.0true1.0);
    
g_cvarRecoilMul CreateConVar("sm_evildeagle_recoil""400""Recoil effect adjustment. [range 100 - 700]"_true100.0true700.0);
    
g_cvarDamage CreateConVar("sm_evildeagle_damage""300""Damage adjustment. [range 100 - 700]"_true100.0true700.0);
    
HookConVarChange(g_cvarRecoilMulOnSettingChanged);
    
HookConVarChange(g_cvarDamageOnSettingChanged);

    
g_hSpawnsADT CreateArray(3);

    
g_ihOwnerEntity FindSendPropOffs("CBaseCombatWeapon""m_hOwnerEntity");
    
g_iiClip1 FindSendPropOffs("CBaseCombatWeapon""m_iClip1");
    
g_iiAmmo FindSendPropInfo("CCSPlayer""m_iAmmo");

    
RegAdminCmd("sm_evildeagle"CommandEDControlADMFLAG);
    
RegAdminCmd("sm_evildeagle_show"CommandShowPosADMFLAG);
    
RegAdminCmd("sm_evildeagle_save"CommandSavePosADMFLAG);
    
RegAdminCmd("sm_evildeagle_remove"CommandRemovePosADMFLAG);

    
HookEvent("round_start"EventRoundStartEventHookMode_PostNoCopy);
    
HookEvent("weapon_fire"EventWeaponFire);
    
HookEvent("player_hurt"EventPlayerHurt);
    
HookEvent("player_death"EventPlayerDeath);
    
HookEvent("round_end"EventRoundEndEventHookMode_PostNoCopy);

    
decl String:configspath[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMconfigspathsizeof(configspath), "configs/evil-deagle");
    if (!
DirExists(configspath))
    {
        
CreateDirectory(configspath0x0265);
    }

    new 
Handle:topmenu;
    if (
LibraryExists("adminmenu") && ((topmenu GetAdminTopMenu()) != INVALID_HANDLE))
    {
        
OnAdminMenuReady(topmenu);
    }
}

public 
OnMapStart()
{
    
g_iBeamSprite PrecacheModel("materials/sprites/laser.vmt");
    
g_iHaloSprite PrecacheModel("materials/sprites/halo01.vmt");

    
decl String:map[64];
    
GetCurrentMap(mapsizeof(map));
    
BuildPath(Path_SMg_sMapCfgPathsizeof(g_sMapCfgPath), "configs/evil-deagle/%s.cfg"map);

    new 
Handle:hKV CreateKeyValues("EDSP");
    if (
FileToKeyValues(hKVg_sMapCfgPath) && KvGotoFirstSubKey(hKVfalse))
    {
        
decl Float:fVec[3];
        do
        {
            
KvGetVector(hKVNULL_STRINGfVec);
            
PushArrayArray(g_hSpawnsADTfVec);
        } while (
KvGotoNextKey(hKVfalse));
    }

    
CloseHandle(hKV);
}

public 
OnConfigsExecuted()
{
    if (
GetConVarInt(g_cvarEfxColor) == 1)
    {
        
g_iRingColor = {1501250255};
        
g_iGlowSprite PrecacheModel("sprites/yellowglow1.vmt");
    }
    else
    {
        
g_iRingColor = {2552515255};
        
g_iGlowSprite PrecacheModel("sprites/redglow3.vmt");
    }

    
g_fRecoilMul = -1.0*GetConVarFloat(g_cvarRecoilMul);
    
GetConVarString(g_cvarDamageg_sDamagesizeof(g_sDamage));
}

public 
OnSettingChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
    if (
convar == g_cvarRecoilMul)
    {
        
g_fRecoilMul = (-1.0 StringToFloat(newValue));
    }
    else if (
convar == g_cvarDamage)
    {
        
strcopy(g_sDamagesizeof(g_sDamage), newValue);
    }
}

public 
OnMapEnd()
{
    
ClearArray(g_hSpawnsADT);
}

public 
Action:CommandEDControl(clientargs)
{
    if (
args != 1)
    {
        
ReplyToCommand(client"[SM] Usage: sm_evildeagle <0/1>");
        return 
Plugin_Handled;
    }

    
decl String:sArg[8];
    
GetCmdArgString(sArgsizeof(sArg));
    new 
ibuffer StringToInt(sArg);
    switch (
ibuffer)
    {
        case 
0:
        {
            
g_bEnabled false;
            
ReplyToCommand(client"\x04[Evil Deagle] \x03Plugin DISABLED");
        }
        case 
1:
        {
            if (
GetArraySize(g_hSpawnsADT) < 1)
            {
                
g_bEnabled false;
                
ReplyToCommand(client"\x04[Evil Deagle] \x03No saved spawn positions. Plugin DISABLED");
            }
            else
            {
                
g_bEnabled true;
                
ReplyToCommand(client"\x04[Evil Deagle] \x03Plugin ENABLED");
            }
        }
    }

    return 
Plugin_Handled;
}

public 
Action:CommandShowPos(clientargs)
{
    new 
arraySize GetArraySize(g_hSpawnsADT);
    if (
arraySize 1)
    {
        
ReplyToCommand(client"\x04[Evil Deagle] \x03No saved spawn positions.");
        return 
Plugin_Handled;
    }


    
CreateTimer(1.0TimerShowSpawnsclientTIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
    
ReplyToCommand(client"\x04[Evil Deagle] \x03Showing spawns for 1 minute.");

    return 
Plugin_Handled;
}

public 
Action:TimerShowSpawns(Handle:timerany:client)
{
    static 
timesRepeated;
    new 
arraySize GetArraySize(g_hSpawnsADT);

    if ((
timesRepeated++ > 60) || (arraySize 1) || !IsClientInGame(client))
    {
        
timesRepeated 0;
        return 
Plugin_Stop;
    }

    
decl Float:fVec[3];
    for (new 
0arraySizei++)
    {
        
GetArrayArray(g_hSpawnsADTifVec);
        
TE_SetupGlowSprite(fVecg_iGlowSprite1.00.7217);
        
TE_SendToClient(client);
    }

    
PrintHintText(client"Total Saved Spawns: %i"arraySize);

    return 
Plugin_Continue;
}

public 
Action:CommandSavePos(clientargs)
{
    new 
Handle:hKV CreateKeyValues("EDSP");
    
decl Float:fVec[3], String:sBuffer[32];
    
GetClientAbsOrigin(clientfVec);
    
fVec[2] += 16.0;
    
Format(sBuffersizeof(sBuffer), "vec:%i%i"RoundToFloor(FloatAbs(fVec[0])), RoundToFloor(FloatAbs(fVec[1])));
    
FileToKeyValues(hKVg_sMapCfgPath);
    
KvSetVector(hKVsBufferfVec);
    
KeyValuesToFile(hKVg_sMapCfgPath);
    
PushArrayArray(g_hSpawnsADTfVec);
    
ReplyToCommand(client"\x04[Evil Deagle] \x03Spawn position saved! [total spawn positions: %d]"GetArraySize(g_hSpawnsADT));
    
CloseHandle(hKV);

    return 
Plugin_Handled;
}

public 
Action:CommandRemovePos(clientargs)
{
    
decl Float:client_fVec[3], Float:spawn_fVec[3], String:sBuffer[32];
    
GetClientAbsOrigin(clientclient_fVec);
    
client_fVec[2] += 16.0;
    new 
arraySize GetArraySize(g_hSpawnsADT);
    if (
arraySize 0)
    {
        for (new 
0arraySizei++)
        {
            
GetArrayArray(g_hSpawnsADTispawn_fVec);
            if (
GetVectorDistance(client_fVecspawn_fVec) < 48.0)
            {
                new 
Handle:hKV CreateKeyValues("EDSP");
                
FileToKeyValues(hKVg_sMapCfgPath);
                
Format(sBuffersizeof(sBuffer), "vec:%i%i"RoundToFloor(FloatAbs(spawn_fVec[0])), RoundToFloor(FloatAbs(spawn_fVec[1])));
                if (
KvJumpToKey(hKVsBuffer))
                {
                    
KvDeleteThis(hKV);
                    
RemoveFromArray(g_hSpawnsADTi);
                    
KvRewind(hKV);
                    
KeyValuesToFile(hKVg_sMapCfgPath);
                    
ReplyToCommand(client"\x04[Evil Deagle] \x03Spawn position successfully removed!");
                }
                else
                {
                    
LogError("Error removing spawn position. Invalid KV key (%s)."sBuffer);
                }

                
CloseHandle(hKV);

                return 
Plugin_Handled;
            }
        }
    }

    
ReplyToCommand(client"\x04[Evil Deagle] \x03No valid spawn position found.");

    return 
Plugin_Handled;
}

public 
EventRoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
    if (!
g_bEnabled)
    {
        return;
    }

    if (
GetArraySize(g_hSpawnsADT) < 1)
    {
        
g_bEnabled false;
        return;
    }

    
g_bIsRoundEnd false;
    
g_iEDEntityIndex = -1;
    
g_iEDOwnerIndex = -1;
    
g_fLastPosVec[0] = 0.0;
    
g_iPointHurt CreateEntityByName("point_hurt");
    
DispatchSpawn(g_iPointHurt);
    
CreateTimer(1.0TimerTrackEDINVALID_HANDLETIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}

public 
EventRoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    
g_bIsRoundEnd true;
}

SpawnNewED(spott)
{
    new 
entity CreateEntityByName("weapon_deagle");
    
DispatchSpawn(entity);
    
decl Float:fVec[3];
    switch (
spott)
    {
        case 
0/* array position */
        
{
            new 
arraysize GetArraySize(g_hSpawnsADT);
            if (
arraysize 1)
            {
                
g_bEnabled false;
                return;
            }
            
GetArrayArray(g_hSpawnsADTGetURandomIntRange(0arraysize-1), fVec);
        }
        case 
1/* last owner position */
        
{
            
fVec g_fLastPosVec;
        }
    }
    
TeleportEntity(entityfVecNULL_VECTORNULL_VECTOR);
    
SetEntData(entityg_iiClip11);
    
g_iEDEntityIndex entity;
}

public 
Action:TimerTrackED(Handle:timer)
{
    if (
g_bIsRoundEnd)
    {
        return 
Plugin_Stop;
    }

    if (!
IsValidEntity(g_iEDEntityIndex))
    {
        
SpawnNewED(g_fLastPosVec[0] == 0.0 1);
        return 
Plugin_Continue;
    }

    if ((
g_iEDOwnerIndex GetEntDataEnt2(g_iEDEntityIndexg_ihOwnerEntity)) != -1)
    {
        if (
GetEntData(g_iEDEntityIndexg_iiClip1) > 1)
        {
            
SetEntData(g_iEDEntityIndexg_iiClip11);
        }
        if (
GetEntData(g_iEDOwnerIndexg_iiAmmo 4) > 1)
        {
            
SetEntData(g_iEDOwnerIndexg_iiAmmo 40);
        }

        return 
Plugin_Continue;
    }

    
decl Float:fVec[3];
    
GetEntPropVector(g_iEDEntityIndexProp_Data"m_vecOrigin"fVec);
    
TE_SetupGlowSprite(fVecg_iGlowSprite1.00.7217);
    
TE_SendToAll();
    
fVec[2] += 3;
    
TE_SetupBeamRingPoint(fVec8.036.0g_iBeamSpriteg_iHaloSprite0101.07.01.0g_iRingColor70);
    
TE_SendToAll();

    return 
Plugin_Continue;
}

public 
EventWeaponFire(Handle:event,const String:name[],bool:dontBroadcast)
{
    if (!
g_bEnabled)
    {
        return;
    }

    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if (
client == g_iEDOwnerIndex)
    {
        
decl String:weapon[16];
        
GetEventString(event"weapon"weaponsizeof(weapon));
        if (
StrEqual(weapon"deagle"))
        {
            
SetEntData(clientg_iiAmmo 41);
            if (
GetEntData(g_iEDEntityIndexg_iiClip1) == 1)
            {
                
CreateTimer(0.01TimerRecoilclient);
            }
        }
    }
}

public 
Action:TimerRecoil(Handle:timerany:client)
{
    static 
Float:fPlayerAng[3], Float:fPlayerVel[3], Float:fPush[3];
    
GetClientEyeAngles(clientfPlayerAng);
    
GetEntPropVector(clientProp_Data"m_vecVelocity"fPlayerVel);
    
fPlayerAng[0] *= -1.0;
    
fPlayerAng[0] = DegToRad(fPlayerAng[0]);
    
fPlayerAng[1] = DegToRad(fPlayerAng[1]);
    
fPush[0] = g_fRecoilMul*Cosine(fPlayerAng[0])*Cosine(fPlayerAng[1])+fPlayerVel[0];
    
fPush[1] = g_fRecoilMul*Cosine(fPlayerAng[0])*Sine(fPlayerAng[1])+fPlayerVel[1];
    
fPush[2] = g_fRecoilMul*Sine(fPlayerAng[0])+fPlayerVel[2]; 
    
TeleportEntity(clientNULL_VECTORNULL_VECTORfPush);
}

public 
EventPlayerHurt(Handle:event,const String:name[],bool:dontBroadcast)
{
    if (!
g_bEnabled)
    {
        return;
    }

    new 
attacker GetClientOfUserId(GetEventInt(event"attacker"));
    if (
attacker == g_iEDOwnerIndex)
    {
        
decl String:weapon[16];
        
GetEventString(event"weapon"weaponsizeof(weapon));
        if (
StrEqual(weapon"deagle") && IsValidEntity(g_iPointHurt))
        {
            new 
victim GetClientOfUserId(GetEventInt(event,"userid"));
            
decl Float:attackerPos[3];
            
GetClientAbsOrigin(attackerattackerPos);
            
TeleportEntity(g_iPointHurtattackerPosNULL_VECTORNULL_VECTOR);
            
DispatchKeyValue(victim"targetname""hurt");
            
DispatchKeyValue(g_iPointHurt"DamageTarget""hurt");
            
DispatchKeyValue(g_iPointHurt"Damage"g_sDamage);
            
DispatchKeyValue(g_iPointHurt"DamageType""0");
            
AcceptEntityInput(g_iPointHurt"Hurt"attacker);
            
DispatchKeyValue(victim"targetname""nohurt");
        }
    }
}

public 
EventPlayerDeath(Handle:event,const String:name[],bool:dontBroadcast)
{
    if (!
g_bEnabled)
    {
        return;
    }

    new 
client GetClientOfUserId(GetEventInt(event,"userid"));
    if (
client == g_iEDOwnerIndex)
    {
        
GetClientAbsOrigin(clientg_fLastPosVec);
        
g_fLastPosVec[2] += 16.0;
    }
}

/*
    get U random int. *added v1.3 *thx to psychonic
*/

stock GetURandomIntRange(minmax)
{
    return (
GetURandomInt() % (max-min+1)) + min;
}  

/* 
    menu support *added v1.3 
*/

public OnLibraryRemoved(const String:name[])
{
    if (
StrEqual(name"adminmenu"))
    {
        
g_hAdminMenu INVALID_HANDLE;
    }
}

public 
OnAdminMenuReady(Handle:topmenu)
{
    if (
topmenu == g_hAdminMenu)
    {
        return;
    }

    
g_hAdminMenu topmenu;
    new 
TopMenuObject:serverCmds FindTopMenuCategory(g_hAdminMenuADMINMENU_SERVERCOMMANDS);
    
AddToTopMenu(g_hAdminMenu"sm_evildeagle"TopMenuObject_ItemTopMenuHandlerserverCmds"sm_evildeagle"ADMFLAG);
}

public 
TopMenuHandler(Handle:topmenuTopMenuAction:actionTopMenuObject:object_idclientString:buffer[], maxlength)
{
    if (
action == TopMenuAction_DisplayOption)
    {
        
Format(buffermaxlength"Evil Deagle");
    }
    else if (
action == TopMenuAction_SelectOption)
    {
        
MainMenu(client);
    }
}

MainMenu(client)
{
    new 
Handle:menu CreateMenu(MainMenuHandler);
    
SetMenuTitle(menu"Evil Deagle");
    
AddMenuItem(menu"0""Enable Plugin");
    
AddMenuItem(menu"1""Disable Plugin");
    
AddMenuItem(menu"2""Show Spawns");
    
AddMenuItem(menu"3""Save New Spawn");
    
AddMenuItem(menu"4""Remove Spawn");
    
DisplayMenu(menuclientMENU_TIME_FOREVER);
}

public 
MainMenuHandler(Handle:menuMenuAction:actionclientselection)
{
    if (
action == MenuAction_Select)
    {
        
decl String:sBuffer[7], iBuffer;
        
GetMenuItem(menuselectionsBuffersizeof(sBuffer));
        
iBuffer StringToInt(sBuffer);
        switch (
iBuffer)
        {
            case 
0:
            {
                
FakeClientCommand(client"say /evildeagle 1");
            }
            case 
1:
            {
                
FakeClientCommand(client"say /evildeagle 0");
            }
            case 
2:
            {
                
FakeClientCommand(client"say /evildeagle_show");
                
MainMenu(client);
            }
            case 
3:
            {
                
FakeClientCommand(client"say /evildeagle_save");
                
MainMenu(client);
            }
            case 
4:
            {
                
FakeClientCommand(client"say /evildeagle_remove");
                
MainMenu(client);
            }
        }
    }
    else if (
action == MenuAction_End)
    {
        
CloseHandle(menu);
    }



Merci de votre aide par avance !

Viewing all articles
Browse latest Browse all 5196

Trending Articles


Re:Mutton Pies (lleechef)