FlacoBey

Untitled

May 29th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 24.04 KB | None | 0 0
  1. #pragma semicolon 1
  2. #include <sourcemod>
  3. #include <sdktools>
  4. #include <sdktools_functions>
  5.  
  6. #define SOUNDCLIPEMPTY           "weapons/ClipEmpty_Rifle.wav"
  7. #define SOUNDRELOAD              "weapons/shotgun/gunother/shotgun_load_shell_2.wav"
  8. #define SOUNDREADY               "weapons/shotgun/gunother/shotgun_pump_1.wav"
  9.  
  10. #define WEAPONCOUNT 17
  11.  
  12. #define SOUND0 "weapons/hunting_rifle/gunfire/hunting_rifle_fire_1.wav"
  13. #define SOUND1 "weapons/rifle/gunfire/rifle_fire_1.wav"
  14. #define SOUND2 "weapons/auto_shotgun/gunfire/auto_shotgun_fire_1.wav"
  15. #define SOUND3 "weapons/shotgun/gunfire/shotgun_fire_1.wav"
  16. #define SOUND4 "weapons/SMG/gunfire/smg_fire_1.wav"
  17. #define SOUND5 "weapons/pistol/gunfire/pistol_fire.wav"
  18. #define SOUND6 "weapons/magnum/gunfire/magnum_shoot.wav"
  19. #define SOUND7 "weapons/rifle_ak47/gunfire/rifle_fire_1.wav"
  20. #define SOUND8 "weapons/rifle_desert/gunfire/rifle_fire_1.wav"
  21. #define SOUND9 "weapons/sg552/gunfire/sg552-1.wav"
  22. #define SOUND10 "weapons/shotgun_chrome/gunfire/shotgun_fire_1.wav"
  23. #define SOUND11 "weapons/auto_shotgun_spas/gunfire/shotgun_fire_1.wav"
  24. #define SOUND12 "weapons/sniper_military/gunfire/sniper_military_fire_1.wav"
  25. #define SOUND13 "weapons/scout/gunfire/scout_fire-1.wav"
  26. #define SOUND14 "weapons/awp/gunfire/awp1.wav"
  27. #define SOUND15 "weapons/mp5navy/gunfire/mp5-1.wav"
  28. #define SOUND16 "weapons/smg_silenced/gunfire/smg_fire_1.wav"
  29.  
  30. #define MODEL0 "weapon_hunting_rifle"
  31. #define MODEL1 "weapon_rifle"
  32. #define MODEL2 "weapon_autoshotgun"
  33. #define MODEL3 "weapon_pumpshotgun"
  34. #define MODEL4 "weapon_smg"
  35. #define MODEL5 "weapon_pistol"
  36. #define MODEL6 "weapon_pistol_magnum"
  37. #define MODEL7 "weapon_rifle_ak47"
  38. #define MODEL8 "weapon_rifle_desert"
  39. #define MODEL9 "weapon_rifle_sg552"
  40. #define MODEL10 "weapon_shotgun_chrome"
  41. #define MODEL11 "weapon_shotgun_spas"
  42. #define MODEL12 "weapon_sniper_military"
  43. #define MODEL13 "weapon_sniper_scout"
  44. #define MODEL14 "weapon_sniper_awp"
  45. #define MODEL15 "weapon_smg_mp5"
  46. #define MODEL16 "weapon_smg_silenced"
  47.  
  48.  
  49. new g_PointHurt=0;
  50. new String:SOUND[WEAPONCOUNT+3][70]=
  51. {SOUND0, SOUND1, SOUND2, SOUND3, SOUND4, SOUND5, SOUND6, SOUND7,SOUND8,SOUND9, SOUND10, SOUND11,SOUND12,SOUND13,SOUND14, SOUND15,SOUND16,SOUNDCLIPEMPTY, SOUNDRELOAD, SOUNDREADY};
  52.  
  53. new String:MODEL[WEAPONCOUNT][32]=
  54. {MODEL0, MODEL1, MODEL2, MODEL3, MODEL4, MODEL5,MODEL6, MODEL7,MODEL8,MODEL9,MODEL10, MODEL11, MODEL12 ,MODEL13,MODEL14, MODEL15, MODEL16};
  55.  
  56. new String:weaponbulletdamagestr[WEAPONCOUNT][10]={"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""};
  57.  
  58. //weapon data
  59. new Float:fireinterval[WEAPONCOUNT]={0.25, 0.068, 0.30, 0.65, 0.060, 0.20, 0.33, 0.145, 0.14, 0.064, 0.65, 0.30, 0.265, 0.9, 1.25, 0.065, 0.055};
  60.  
  61. new Float:bulletaccuracy[WEAPONCOUNT]={1.15, 1.4, 3.5, 3.5, 1.6, 1.7 , 1.7, 1.5, 1.6, 1.5, 3.5, 3.5, 1.15, 1.00, 0.8, 1.6 ,1.6};
  62.  
  63. new Float:weaponbulletdamage[WEAPONCOUNT]={90.0, 30.0, 25.0, 30.0, 20.0, 30.0, 60.0, 70.0, 40.0, 40.0, 30.0, 30.0, 90.0, 100.0, 150.0, 35.0, 35.0};
  64.  
  65. new weaponclipsize[WEAPONCOUNT]={15, 50, 10, 8, 50, 30, 8, 40, 20, 50, 8, 10, 30, 15, 20, 50, 50};
  66.  
  67. new weaponbulletpershot[WEAPONCOUNT]={1, 1, 7, 7, 1, 1, 1, 1, 1, 1, 7, 7,1, 1, 1,1,1};
  68.  
  69. new Float:weaponloadtime[WEAPONCOUNT]={2.0, 1.5, 0.3, 0.3, 1.5, 1.5, 1.9, 1.5, 1.5, 1.6, 0.3, 0.3, 2.0,2.0, 2.0, 1.5, 1.5};
  70.  
  71. new weaponloadcount[WEAPONCOUNT]={15, 50, 1,1, 50, 30, 8, 40, 60, 50, 1, 1, 30, 15, 20, 50, 50};
  72.  
  73. new bool:weaponloaddisrupt[WEAPONCOUNT]={false,false, true, true,false,false, false, false, false, true, true, false, false, false, false, false};
  74. //weapon data
  75.  
  76. new robot[MAXPLAYERS+1];
  77. new keybuffer[MAXPLAYERS+1];
  78. new weapontype[MAXPLAYERS+1];
  79. new bullet[MAXPLAYERS+1];
  80. new Float:firetime[MAXPLAYERS+1];
  81. new bool:reloading[MAXPLAYERS+1];
  82. new Float:reloadtime[MAXPLAYERS+1];
  83. new Float:scantime[MAXPLAYERS+1];
  84. new Float:walktime[MAXPLAYERS+1];
  85. new Float:botenerge[MAXPLAYERS+1];
  86.  
  87. new SIenemy[MAXPLAYERS+1];
  88. new CIenemy[MAXPLAYERS+1];
  89. new Float:CIenemyTime[MAXPLAYERS+1];
  90.  
  91. new Float:robotangle[MAXPLAYERS+1][3];
  92.  
  93. new Handle:l4d_robot_limit = INVALID_HANDLE;
  94. new Handle:l4d_robot_reactiontime = INVALID_HANDLE;
  95. new Handle:l4d_robot_scanrange = INVALID_HANDLE;
  96. new Handle:l4d_robot_energy= INVALID_HANDLE;
  97. new Handle:l4d_robot_damagefactor= INVALID_HANDLE;
  98.  
  99. new Float:robot_reactiontime;
  100. new Float:robot_scanrange;
  101. new Float:robot_energy;
  102. new Float:robot_damagefactor;
  103.  
  104. new g_sprite;
  105.  
  106. new bool:L4D2Version=false;
  107. new GameMode=0;
  108.  
  109. new bool:gamestart=false;
  110.  
  111. public Plugin:myinfo =
  112. {
  113.     name = "Robot system",
  114.     author = "Pan Xiaohai",
  115.     description = "Robot system",
  116.     version = "1.2",
  117.     url = "http://forums.alliedmods.net"
  118. }
  119. public OnPluginStart()
  120. {
  121.     l4d_robot_limit = CreateConVar("l4d_robot_limit", "2", "number of robot [0-3]", FCVAR_PLUGIN);
  122.     l4d_robot_reactiontime = CreateConVar("l4d_robot_reactiontime", "2.0", "robot reaction time [0.5,5.0]", FCVAR_PLUGIN);
  123.     l4d_robot_scanrange = CreateConVar("l4d_robot_scanrange", "600.0", "scan enemy range[100.0, 10000.0]", FCVAR_PLUGIN);
  124.     l4d_robot_energy = CreateConVar("l4d_robot_energy", "5.0", "time limit  of a robot for a player (minutes)[0.0, 100.0]", FCVAR_PLUGIN);
  125.     l4d_robot_damagefactor = CreateConVar("l4d_robot_damagefactor", "0.5", "damage factor [0.2,1.0]", FCVAR_PLUGIN);
  126.    
  127.  
  128.     AutoExecConfig(true, "l4d_robot_12");
  129.     HookConVarChange(l4d_robot_reactiontime, ConVarChange);
  130.     HookConVarChange(l4d_robot_scanrange, ConVarChange);
  131.     HookConVarChange(l4d_robot_energy, ConVarChange);
  132.     HookConVarChange(l4d_robot_damagefactor, ConVarChange);
  133.     GetConVar();
  134.  
  135.     decl String:GameName[16];
  136.     GetConVarString(FindConVar("mp_gamemode"), GameName, sizeof(GameName));
  137.    
  138.     if (StrEqual(GameName, "survival", false))
  139.         GameMode = 3;
  140.     else if (StrEqual(GameName, "versus", false) || StrEqual(GameName, "teamversus", false) || StrEqual(GameName, "scavenge", false) || StrEqual(GameName, "teamscavenge", false))
  141.         GameMode = 2;
  142.     else if (StrEqual(GameName, "coop", false) || StrEqual(GameName, "realism", false))
  143.         GameMode = 1;
  144.     else
  145.     {
  146.         GameMode = 0;
  147.     }
  148.    
  149.     GetGameFolderName(GameName, sizeof(GameName));
  150.     if (StrEqual(GameName, "left4dead2", false))
  151.     {
  152.         L4D2Version=true;
  153.     }  
  154.     else
  155.     {
  156.         L4D2Version=false;
  157.     }
  158.  
  159.     RegConsoleCmd("sm_robot", sm_robot);
  160.     HookEvent("player_use", player_use);
  161.     HookEvent("round_start", RoundStart);
  162.    
  163.     HookEvent("player_hurt", Event_PlayerHurt);
  164.    
  165.     HookEvent("round_end", RoundEnd);
  166.     HookEvent("finale_win", RoundEnd);
  167.     HookEvent("mission_lost", RoundEnd);
  168.     HookEvent("map_transition", RoundEnd);
  169.     HookEvent("player_spawn", Event_Spawn);  
  170.     gamestart=false ;
  171.    
  172. }
  173. GetConVar()
  174. {
  175.     robot_reactiontime=GetConVarFloat(l4d_robot_reactiontime );
  176.     robot_scanrange=GetConVarFloat(l4d_robot_scanrange );
  177.     robot_energy=GetConVarFloat(l4d_robot_energy )*60.0;
  178.     robot_damagefactor=GetConVarFloat(l4d_robot_damagefactor);
  179.     new String:str[10];
  180.     for(new i=0; i<WEAPONCOUNT; i++)
  181.     {
  182.         Format(str, sizeof(str), "%d", RoundFloat(weaponbulletdamage[i]*robot_damagefactor));
  183.         weaponbulletdamagestr[i]=str;
  184.     }
  185. }
  186. public ConVarChange(Handle:convar, const String:oldValue[], const String:newValue[])
  187. {
  188.     GetConVar();
  189. }
  190.  
  191. public OnMapStart()
  192. {
  193.  
  194.     PrecacheModel( MODEL[0] , true );
  195.     PrecacheModel( MODEL[1] , true );
  196.     PrecacheModel( MODEL[2] , true );
  197.     PrecacheModel( MODEL[3] , true );
  198.     PrecacheModel( MODEL[4] , true );
  199.     PrecacheModel( MODEL[5] , true );
  200.  
  201.     PrecacheSound(SOUND[0], true) ;
  202.     PrecacheSound(SOUND[1], true) ;
  203.     PrecacheSound(SOUND[2], true) ;
  204.     PrecacheSound(SOUND[3], true) ;
  205.     PrecacheSound(SOUND[4], true) ;
  206.     PrecacheSound(SOUND[5], true) ;
  207.    
  208.     PrecacheSound(SOUNDCLIPEMPTY, true) ;
  209.     PrecacheSound(SOUNDRELOAD, true) ;
  210.     PrecacheSound(SOUNDREADY, true) ;  
  211.  
  212.    
  213.     if(L4D2Version)
  214.     {
  215.         g_sprite = PrecacheModel("materials/sprites/laserbeam.vmt");   
  216.        
  217.         for(new i=6; i<WEAPONCOUNT; i++)
  218.         {
  219.             PrecacheModel( MODEL[i] , true );
  220.             PrecacheSound(SOUND[i], true) ;
  221.         }
  222.     }
  223.     else
  224.     {
  225.         g_sprite = PrecacheModel("materials/sprites/laser.vmt");   
  226.  
  227.     }
  228.     gamestart=false ;
  229.    
  230. }
  231.  
  232. public Action:RoundStart (Handle:event, const String:name[], bool:dontBroadcast)
  233. {
  234.  
  235.     for (new i = 1; i <= MaxClients; i++)
  236.     {
  237.         if(robot[i]>0)
  238.         {
  239.             Release(i, false);   
  240.         }
  241.         botenerge[i]=0.0;
  242.     }
  243.     g_PointHurt=0;
  244.    
  245.     return Plugin_Continue;
  246. }
  247. public Action:RoundEnd (Handle:event, const String:name[], bool:dontBroadcast)
  248. {
  249.  
  250.     for (new i = 1; i <= MaxClients; i++)
  251.     {
  252.         if(robot[i]>0)
  253.         {
  254.             Release(i, false);   
  255.         }
  256.     }
  257.     gamestart=false;
  258.      
  259.     return Plugin_Continue;
  260. }
  261. public player_use (Handle:hEvent, const String:name[], bool:dontBroadcast)
  262. {
  263.     new client=GetClientOfUserId(GetEventInt(hEvent, "userid"));
  264.     new entity = GetEventInt(hEvent, "targetid");
  265.     for (new i = 1; i <= MaxClients; i++)
  266.     {
  267.         if(robot[i]>0 && robot[i]==entity)
  268.         {
  269.             //RemovePlayerItem(client, entity);
  270.             PrintHintText(i, "%N try to steal your robot", client);
  271.             PrintHintText(client, "you try to steal %N 's robot",i);
  272.             Release(i);
  273.             AddRobot(i);
  274.         }
  275.     }
  276.      
  277. }
  278. public Event_Spawn(Handle:Spawn_Event, const String:Spawn_Name[], bool:Spawn_Broadcast)
  279. {
  280.     new client = GetClientOfUserId(GetEventInt(Spawn_Event, "userid"));
  281.     robot[client]=0;
  282. }
  283.  
  284. public Action:Event_PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
  285. {
  286.     if(!gamestart)return;
  287.     new  attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
  288.     new  victim = GetClientOfUserId(GetEventInt(event, "userid"));
  289.     if(attacker>0 )
  290.     {  
  291.         if(attacker!=victim && GetClientTeam(attacker)==3)
  292.         {
  293.             scantime[victim]=GetEngineTime();
  294.             SIenemy[victim]=attacker;
  295.         }
  296.     }
  297.     else
  298.     {
  299.         new ent= GetEventInt(event, "attackerentid");  
  300.         CIenemy[victim]=ent;
  301.     }
  302. }
  303. DelRobot(ent)
  304. {
  305.     if (ent > 0 && IsValidEntity(ent))
  306.     {
  307.         decl String:item[65];
  308.         GetEdictClassname(ent, item, sizeof(item));
  309.         if(StrContains(item, "weapon")>=0)
  310.         {
  311.             RemoveEdict(ent);
  312.         }
  313.     }
  314. }
  315.  
  316. Release(controller, bool:del=true)
  317. {
  318.     new r=robot[controller];
  319.     if(r>0)
  320.     {
  321.         robot[controller]=0;
  322.      
  323.         if(del)DelRobot(r);
  324.     }
  325.     if(gamestart)
  326.     {
  327.         new count=0;
  328.         for (new i = 1; i <= MaxClients; i++)
  329.         {
  330.             if(robot[i]>0)
  331.             {
  332.                 count++;
  333.             }
  334.         }
  335.         if(count==0) gamestart=false;
  336.     }
  337. }
  338.  
  339. public Action:sm_robot(client, args)
  340. {  
  341.     if(GameMode==2)return Plugin_Continue;
  342.     if(!IsValidAliveClient(client)) return Plugin_Continue;
  343.     if(robot[client]>0)
  344.     {
  345.         PrintToChat(client, "you already have a robot");
  346.         return Plugin_Handled;
  347.     }
  348.     new count=0;
  349.     for (new i = 1; i <= MaxClients; i++)
  350.     {
  351.         if(robot[i]>0)
  352.         {
  353.             count++;
  354.         }
  355.     }
  356.    
  357.     if(count+1>GetConVarInt(l4d_robot_limit))
  358.     {
  359.         PrintToChat(client, "no more robot");
  360.         return Plugin_Handled;
  361.     }
  362.     //  #define MODEL0 "weapon_hunting_rifle"
  363.     //#define MODEL1 "weapon_rifle"
  364.     //#define MODEL2 "weapon_autoshotgun"
  365.     //#define MODEL3 "weapon_pumpshotgun"
  366.     //#define MODEL4 "weapon_smg"
  367.     //#define MODEL5 "weapon_pistol"
  368.     //#define MODEL6 "weapon_pistol_magnum"
  369.  
  370.     if(args>=1)
  371.     {
  372.         new String:arg[128];
  373.         GetCmdArg(1, arg, sizeof(arg));
  374.         if(StrContains(arg, "hunting", false)!=-1) weapontype[client]=0;   
  375.         else if(StrContains(arg, "rifle", false)!=-1) weapontype[client]=1;
  376.         else if(StrContains(arg, "auto", false)!=-1) weapontype[client]=2;
  377.         else if(StrContains(arg, "pump", false)!=-1) weapontype[client]=3;
  378.         else if(StrContains(arg, "smg", false)!=-1) weapontype[client]=4;  
  379.         else if(StrContains(arg, "pistol", false)!=-1) weapontype[client]=5;
  380.         else if(StrContains(arg, "magnum", false)!=-1 && L4D2Version) weapontype[client]=6;
  381.         else if(StrContains(arg, "ak47", false)!=-1 && L4D2Version) weapontype[client]=7;      
  382.         else if(StrContains(arg, "desert", false)!=-1 && L4D2Version) weapontype[client]=8;
  383.         else if(StrContains(arg, "sg552", false)!=-1 && L4D2Version) weapontype[client]=9; 
  384.         else if(StrContains(arg, "chrome", false)!=-1 && L4D2Version) weapontype[client]=10;       
  385.         else if(StrContains(arg, "spas", false)!=-1 && L4D2Version) weapontype[client]=11;     
  386.         else if(StrContains(arg, "military", false)!=-1 && L4D2Version) weapontype[client]=12;     
  387.         else if(StrContains(arg, "scout", false)!=-1 && L4D2Version) weapontype[client]=13;
  388.         else if(StrContains(arg, "awp", false)!=-1 && L4D2Version) weapontype[client]=14;  
  389.         else if(StrContains(arg, "mp5", false)!=-1 && L4D2Version) weapontype[client]=15;  
  390.         else if(StrContains(arg, "silenced", false)!=-1 && L4D2Version) weapontype[client]=16; 
  391.         else
  392.         {
  393.             if(L4D2Version) weapontype[client]=GetRandomInt(0, WEAPONCOUNT-1);
  394.             else weapontype[client]=GetRandomInt(0, 5);
  395.         }
  396.     }  
  397.     else
  398.     {
  399.         if(L4D2Version) weapontype[client]=GetRandomInt(0, WEAPONCOUNT-1);
  400.         else weapontype[client]=GetRandomInt(0, 5);
  401.     }
  402.     AddRobot(client, true);
  403.     return Plugin_Handled;
  404. }
  405. AddRobot(client, bool:showmsg=false)
  406. {
  407.     bullet[client]=weaponclipsize[weapontype[client]];
  408.     new Float:vAngles[3];
  409.     new Float:vOrigin[3];
  410.     new Float:pos[3];
  411.  
  412.  
  413.     GetClientEyePosition(client,vOrigin);
  414.     GetClientEyeAngles(client, vAngles);
  415.  
  416.     new Handle:trace = TR_TraceRayFilterEx(vOrigin, vAngles, MASK_SOLID,  RayType_Infinite, TraceEntityFilterPlayer);
  417.  
  418.     if(TR_DidHit(trace))
  419.     {
  420.         TR_GetEndPosition(pos, trace);
  421.     }
  422.     CloseHandle(trace);
  423.  
  424.     decl Float:v1[3];
  425.     decl Float:v2[3];
  426.      
  427.     SubtractVectors(vOrigin, pos, v1);
  428.     NormalizeVector(v1, v2);
  429.  
  430.     ScaleVector(v2, 50.0);
  431.  
  432.     AddVectors(pos, v2, v1);  // v1 explode taget
  433.     new ent=0;
  434.  
  435.     ent=CreateEntityByName(MODEL[weapontype[client]]);        
  436.     DispatchSpawn(ent);          
  437.     TeleportEntity(ent, v1, NULL_VECTOR, NULL_VECTOR);
  438.  
  439.     SetEntityMoveType(ent, MOVETYPE_FLY);
  440.      
  441.    
  442.     SIenemy[client]=0;
  443.     CIenemy[client]=0;
  444.     scantime[client]=0.0;
  445.     keybuffer[client]=0;
  446.     bullet[client]=0;
  447.     reloading[client]=false;
  448.     reloadtime[client]=0.0;
  449.     firetime[client]=0.0;
  450.     robot[client]=ent;
  451.     if(showmsg)
  452.     {
  453.         PrintHintText(client, "you have a robot,press WALK+USE to turn it off");
  454.         PrintToChatAll("\x04 %N \x03 turn on robot", client);
  455.     }
  456.     gamestart=true;
  457. }
  458.  
  459. new Float:lasttime=0.0;
  460.  
  461. new button;
  462.  
  463. new Float:robotpos[3];
  464. new Float:robotvec[3];
  465.  
  466.  
  467. new Float:clienteyepos[3];
  468.  
  469.  
  470.  
  471. new Float:clientangle[3];
  472. new Float:enemypos[3];
  473. new Float:infectedorigin[3];
  474. new Float:infectedeyepos[3];
  475.  
  476. new Float:chargetime;
  477.  
  478. Do(client, Float:currenttime, Float:duration)
  479. {
  480.     if(robot[client]>0)
  481.     {
  482.         if (!IsValidEntity(robot[client]) || IsFakeClient(client) || !IsValidAliveClient(client) )
  483.         {
  484.             Release(client);
  485.         }
  486.         else  
  487.         {          
  488.             botenerge[client]+=duration;
  489.             if(botenerge[client]>robot_energy)
  490.             {
  491.                 Release(client);
  492.                 PrintHintText(client, "your bot' energe is not enough");
  493.                 return;
  494.             }
  495.            
  496.             button=GetClientButtons(client);
  497.             GetEntPropVector(robot[client], Prop_Send, "m_vecOrigin", robotpos);   
  498.              
  499.             if((button & IN_USE) && (button & IN_SPEED) && !(keybuffer[client] & IN_USE))
  500.             {
  501.                 Release(client);
  502.                 PrintToChatAll("\x04 %N \x03 turn off robot", client);
  503.                 return;
  504.             }
  505.             if(currenttime - scantime[client]>robot_reactiontime)
  506.             {
  507.                 scantime[client]=currenttime;
  508.                 SIenemy[client]=ScanEnemy(client,robotpos);
  509.                 CIenemy[client]=0;
  510.             }
  511.             new targetok=false;
  512.             if(SIenemy[client]>0 && IsClientInGame(SIenemy[client]) && IsPlayerAlive(SIenemy[client]))
  513.             {
  514.                
  515.                 GetClientEyePosition(SIenemy[client], infectedeyepos);
  516.                 GetClientAbsOrigin(SIenemy[client], infectedorigin);   
  517.                 enemypos[0]=infectedorigin[0]*0.4+infectedeyepos[0]*0.6;
  518.                 enemypos[1]=infectedorigin[1]*0.4+infectedeyepos[1]*0.6;
  519.                 enemypos[2]=infectedorigin[2]*0.4+infectedeyepos[2]*0.6;
  520.                
  521.                 SubtractVectors(enemypos, robotpos, robotangle[client]);
  522.                 GetVectorAngles(robotangle[client],robotangle[client]);
  523.                 targetok=true;
  524.             }
  525.             else
  526.             {
  527.                 SIenemy[client]=0;
  528.             }
  529.             if(!targetok)
  530.             {
  531.                 if( CIenemy[client]>0 && IsValidEntity(CIenemy[client]))
  532.                 {
  533.                     GetEntPropVector(CIenemy[client], Prop_Send, "m_vecOrigin", enemypos); 
  534.                     enemypos[2]+=40.0;
  535.                     SubtractVectors(enemypos, robotpos, robotangle[client]);
  536.                     GetVectorAngles(robotangle[client],robotangle[client]);
  537.                     targetok=true;
  538.                 }
  539.                 else
  540.                 {
  541.                     CIenemy[client]=0;
  542.                 }
  543.             }
  544.             if(reloading[client])
  545.             {
  546.                 //PrintToChatAll("%f", reloadtime[client]);
  547.                 if(bullet[client]>=weaponclipsize[weapontype[client]] && currenttime-reloadtime[client]>weaponloadtime[weapontype[client]])
  548.                 {
  549.                     reloading[client]=false;   
  550.                     reloadtime[client]=currenttime;
  551.                     EmitSoundToAll(SOUNDREADY, 0, SNDCHAN_WEAPON, SNDLEVEL_TRAFFIC, SND_NOFLAGS, SNDVOL_NORMAL, 100, _, robotpos, NULL_VECTOR, false, 0.0);
  552.                     //PrintHintText(client, " ");
  553.                 }
  554.                 else
  555.                 {
  556.                     if(currenttime-reloadtime[client]>weaponloadtime[weapontype[client]])
  557.                     {
  558.                         reloadtime[client]=currenttime;
  559.                         bullet[client]+=weaponloadcount[weapontype[client]];
  560.                         EmitSoundToAll(SOUNDRELOAD, 0, SNDCHAN_WEAPON, SNDLEVEL_TRAFFIC, SND_NOFLAGS, SNDVOL_NORMAL, 100, _, robotpos, NULL_VECTOR, false, 0.0);
  561.                         //PrintHintText(client, "reloading %d", bullet[client]);
  562.                     }
  563.                    
  564.                 }
  565.             }
  566.             if(!reloading[client])
  567.             {
  568.                 if(!targetok)
  569.                 {
  570.                     if(bullet[client]<weaponclipsize[weapontype[client]])                  
  571.                     {
  572.                         reloading[client]=true;
  573.                         reloadtime[client]=0.0;
  574.                         if(!weaponloaddisrupt[weapontype[client]])
  575.                         {
  576.                             bullet[client]=0;
  577.                         }
  578.                        
  579.                     }
  580.                    
  581.                 }  
  582.             }
  583.             chargetime=fireinterval[weapontype[client]];
  584.              
  585.             if(!reloading[client])
  586.             {
  587.                 if(currenttime-firetime[client]>chargetime)
  588.                 {
  589.                        
  590.                     if( targetok)
  591.                     {
  592.                         if(bullet[client]>0)
  593.                         {
  594.                             bullet[client]=bullet[client]-1;
  595.                            
  596.                             FireBullet(client, robot[client], enemypos, robotpos);
  597.                          
  598.                             firetime[client]=currenttime;  
  599.                             reloading[client]=false;
  600.                         }
  601.                         else
  602.                         {
  603.                             firetime[client]=currenttime;
  604.                             EmitSoundToAll(SOUNDCLIPEMPTY, 0, SNDCHAN_WEAPON, SNDLEVEL_TRAFFIC, SND_NOFLAGS, SNDVOL_NORMAL, 100, _, robotpos, NULL_VECTOR, false, 0.0);
  605.                             reloading[client]=true;
  606.                             reloadtime[client]=currenttime;
  607.                         }
  608.                        
  609.                     }
  610.  
  611.                 }
  612.  
  613.             }
  614.    
  615.  
  616.             GetClientEyePosition(client,  clienteyepos);
  617.             clienteyepos[2]+=30.0;
  618.             GetClientEyeAngles(client, clientangle);
  619.             new Float:distance = GetVectorDistance(robotpos, clienteyepos);
  620.              
  621.             if(distance>500.0)
  622.             {
  623.                 TeleportEntity(robot[client], clienteyepos,  robotangle[client] ,NULL_VECTOR);
  624.             }
  625.             else if(distance>100.0)    
  626.             {
  627.  
  628.                 MakeVectorFromPoints( robotpos, clienteyepos, robotvec);
  629.                 NormalizeVector(robotvec,robotvec);
  630.                 ScaleVector(robotvec, 5*distance);
  631.                 if (!targetok )
  632.                 {
  633.                     GetVectorAngles(robotvec, robotangle[client]);
  634.                 }
  635.                 TeleportEntity(robot[client], NULL_VECTOR,  robotangle[client] ,robotvec);
  636.                 walktime[client]=currenttime;
  637.             }
  638.             else
  639.             {
  640.                 robotvec[0]=robotvec[1]=robotvec[2]=0.0;
  641.                 if(!targetok && currenttime-firetime[client]>4.0 && currenttime-walktime[client]>1.0 )robotangle[client][1]+=5.0;
  642.                 TeleportEntity(robot[client], NULL_VECTOR,  robotangle[client] ,robotvec);
  643.             }
  644.             keybuffer[client]=button;
  645.         }
  646.     }
  647.     else
  648.     {
  649.         botenerge[client]=botenerge[client]-duration*0.5;
  650.         if(botenerge[client]<0.0)botenerge[client]=0.0;
  651.          
  652.     }
  653. }
  654. public OnGameFrame()
  655. {
  656.     if(!gamestart)return;
  657.     new Float:currenttime=GetEngineTime();
  658.     new Float:duration=currenttime-lasttime;
  659.     if(duration<0.0 || duration>1.0)duration=0.0;
  660.     for (new client = 1; client <= MaxClients; client++)
  661.     {
  662.         Do(client, currenttime, duration);
  663.     }
  664.     lasttime=currenttime;
  665.     return;
  666. }
  667. ScanEnemy(client, Float:rpos[3] )
  668. {
  669.     decl Float:infectedpos[3];
  670.     decl Float:vec[3];
  671.     decl Float:angle[3];
  672.     new find=0;
  673.     new Float:mindis=100000.0;
  674.     new Float:dis=0.0;
  675.     for (new i = 1; i <= MaxClients; i++)
  676.     {
  677.         if(IsClientInGame(i) && GetClientTeam(i)==3 && IsPlayerAlive(i))
  678.         {
  679.             GetClientEyePosition(i, infectedpos);
  680.             dis=GetVectorDistance(rpos, infectedpos) ;
  681.             //PrintToChatAll("%f %N" ,dis, i);
  682.             if(dis <robot_scanrange && dis<=mindis)
  683.             {
  684.                 SubtractVectors(infectedpos, rpos, vec);
  685.                 GetVectorAngles(vec, angle);
  686.                 new Handle:trace = TR_TraceRayFilterEx(infectedpos, rpos, MASK_SOLID, RayType_EndPoint, TraceRayDontHitSelfAndLive, robot[client]);
  687.            
  688.                 if(TR_DidHit(trace))
  689.                 {
  690.    
  691.                 }
  692.                 else
  693.                 {
  694.                     find=i;
  695.                     mindis=dis;
  696.                 }
  697.                 CloseHandle(trace);
  698.             }
  699.         }
  700.     }
  701.  
  702.     return find;
  703. }
  704. FireBullet(controller, bot, Float:infectedpos[3], Float:botorigin[3])
  705. {
  706.     decl Float:vAngles[3];
  707.     decl Float:vAngles2[3];
  708.     decl Float:pos[3];
  709.  
  710.    
  711.     SubtractVectors(infectedpos, botorigin, infectedpos);
  712.     GetVectorAngles(infectedpos, vAngles);
  713.      
  714.     new Float:arr1;
  715.     new Float:arr2;
  716.     arr1=0.0-bulletaccuracy[weapontype[controller]];   
  717.     arr2=bulletaccuracy[weapontype[controller]];
  718.    
  719.     decl Float:v1[3];
  720.     decl Float:v2[3];
  721.     //PrintToChatAll("%f %f",arr1, arr2);
  722.     for(new c=0; c<weaponbulletpershot[weapontype[controller]];c++)
  723.     {
  724.         //PrintToChatAll("fire");
  725.         vAngles2[0]=vAngles[0]+GetRandomFloat(arr1, arr2); 
  726.         vAngles2[1]=vAngles[1]+GetRandomFloat(arr1, arr2); 
  727.         vAngles2[2]=vAngles[2]+GetRandomFloat(arr1, arr2);
  728.        
  729.         new hittarget=0;
  730.         new Handle:trace = TR_TraceRayFilterEx(botorigin, vAngles2, MASK_SOLID, RayType_Infinite, TraceRayDontHitSelfAndSurvivor, bot);
  731.        
  732.         if(TR_DidHit(trace))
  733.         {
  734.            
  735.             TR_GetEndPosition(pos, trace);
  736.             hittarget=TR_GetEntityIndex( trace);
  737.            
  738.             decl Float:Direction[3];
  739.             Direction[0] = GetRandomFloat(-1.0, 1.0);
  740.             Direction[1] = GetRandomFloat(-1.0, 1.0);
  741.             Direction[2] = GetRandomFloat(-1.0, 1.0);
  742.             TE_SetupSparks(pos,Direction,1,3);
  743.             TE_SendToAll();
  744.            
  745.         }
  746.         CloseHandle(trace);
  747.  
  748.            
  749.         if(hittarget>0)    
  750.         {
  751.             DoPointHurtForInfected(weapontype[controller], hittarget, controller );
  752.         }
  753.        
  754.        
  755.         SubtractVectors(botorigin, pos, v1);
  756.         NormalizeVector(v1, v2);   
  757.         ScaleVector(v2, 36.0);
  758.         SubtractVectors(botorigin, v2, infectedorigin);
  759.      
  760.         decl color[4];
  761.         color[0] = 200;
  762.         color[1] = 200;
  763.         color[2] = 200;
  764.         color[3] = 230;
  765.        
  766.         new Float:life=0.06;
  767.         new Float:width1=0.01;
  768.         new Float:width2=0.3;      
  769.         if(L4D2Version)width2=0.08;
  770.  
  771.         TE_SetupBeamPoints(infectedorigin, pos, g_sprite, 0, 0, 0, life, width1, width2, 1, 0.0, color, 0);
  772.         TE_SendToAll();
  773.  
  774.         //EmitAmbientSound(SOUND[weapontype[controller]], vOrigin, controller, SNDLEVEL_RAIDSIREN);
  775.         EmitSoundToAll(SOUND[weapontype[controller]], 0, SNDCHAN_WEAPON, SNDLEVEL_TRAFFIC, SND_NOFLAGS, SNDVOL_NORMAL, 100, _, botorigin, NULL_VECTOR, false, 0.0);
  776.    
  777.      
  778.     }
  779.    
  780. }
  781.  
  782. CreatePointHurt()
  783. {
  784.     new pointHurt=CreateEntityByName("point_hurt");
  785.     if(pointHurt)
  786.     {
  787.  
  788.         DispatchKeyValue(pointHurt,"Damage","10");
  789.         DispatchKeyValue(pointHurt,"DamageType","2");
  790.         DispatchSpawn(pointHurt);
  791.     }
  792.     return pointHurt;
  793. }
  794. new String:N[10];
  795. DoPointHurtForInfected(wtype ,victim, attacker=0)
  796. {
  797.     if(g_PointHurt > 0)
  798.     {
  799.         if(IsValidEdict(g_PointHurt))
  800.         {
  801.             if(victim>0 && IsValidEdict(victim))
  802.             {      
  803.                 Format(N, 20, "target%d", victim);
  804.                 DispatchKeyValue(victim,"targetname", N);
  805.                 DispatchKeyValue(g_PointHurt,"DamageTarget", N);
  806.                 DispatchKeyValue(g_PointHurt,"classname",MODEL[wtype]);
  807.                 DispatchKeyValue(g_PointHurt,"Damage",weaponbulletdamagestr[wtype]);
  808.                 AcceptEntityInput(g_PointHurt,"Hurt",(attacker>0)?attacker:-1);
  809.             }
  810.         }
  811.     }
  812.     else g_PointHurt=CreatePointHurt();
  813. }
  814.  
  815. public bool:TraceRayDontHitSelf(entity, mask, any:data)
  816. {
  817.     if(entity == data)
  818.     {
  819.         return false;
  820.     }
  821.     return true;
  822. }
  823. public bool:TraceRayDontHitSelfAndLive(entity, mask, any:data)
  824. {
  825.     if(entity == data)
  826.     {
  827.         return false;
  828.     }
  829.     else if(entity>0 && entity<=MaxClients)
  830.     {
  831.         if(IsClientInGame(entity))
  832.         {
  833.             return false;
  834.         }
  835.     }
  836.     return true;
  837. }
  838. public bool:TraceRayDontHitSelfAndSurvivor(entity, mask, any:data)
  839. {
  840.     if(entity == data)
  841.     {
  842.         return false;
  843.     }
  844.     else if(entity>0 && entity<=MaxClients)
  845.     {
  846.         if(IsClientInGame(entity) && GetClientTeam(entity)==2)
  847.         {
  848.             return false;
  849.         }
  850.     }
  851.     return true;
  852. }
  853.  
  854. public bool:TraceEntityFilterPlayer(entity, contentsMask)
  855. {
  856.     return (entity > MaxClients || !entity);
  857. }
  858.  
  859. stock bool:IsValidAliveClient(iClient)
  860. {
  861.     if (iClient <= 0) return false;
  862.     if (iClient > MaxClients) return false;
  863.     if(!IsClientInGame(iClient))return false;
  864.     if (!IsPlayerAlive(iClient)) return false;
  865.     return true;
  866. }
Advertisement
Add Comment
Please, Sign In to add comment