PHP Code:
[PHP]#include <sourcemod>
#include <sdktools>
#include <zombiereloaded>
#include <zp_level>
#include <colors>
new UserMsg:g_FadeUserMsgId;
new Float:g_DrugAngles[20] = {0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 20.0, 15.0, 10.0, 5.0, 0.0, -5.0, -10.0, -15.0, -20.0, -25.0, -20.0, -15.0, -10.0, -5.0};
new Handle:g_drug_timer[MAXPLAYERS+1] = INVALID_HANDLE;
new Handle:g_speed_timer[MAXPLAYERS+1] = INVALID_HANDLE;
new Handle:g_Cvar_FoodEnabled = INVALID_HANDLE;
new String:foodname[][] =
{
/* +HP~ */
"30HP",
"25HP",
}
int foodamount[] =
{
30,
25,
}
// 0 - None, 1 - Speed, 2 - Drug
int foodskills[] =
{
0,
0,
0,
0,
1, // 5
0,
0,
0,
0,
0, // 10
2,
0,
0,
0
}
public Plugin:myinfo =
{
name = "[ZM] Item:[Food]",
author = "Zombie Paradise",
description = "",
version = "1.3",
url = ""
}
public OnPluginStart()
{
RegConsoleCmd("sm_food", Clcmd_Food);
LoadTranslations("zp_food");
g_FadeUserMsgId = GetUserMessageId("Fade");
HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
HookEvent("player_spawn", Event_Player_Spawn);
HookEvent("player_death", Event_Player_Death);
g_Cvar_FoodEnabled = CreateConVar("zp_food", "1", "激活购买食物");
}
public OnConVarChange(Handle:convar, const String:oldValue[], const String:newValue[])
{
if(convar == g_Cvar_FoodEnabled)
{
if (strcmp(oldValue, newValue) != 0)
{
if (strcmp(newValue, "1") == 0)
SetConVarInt(g_Cvar_FoodEnabled, true);
else
SetConVarInt(g_Cvar_FoodEnabled, false);
}
}
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
RegPluginLibrary("zp_food");
CreateNative("zp_earn_food", native_earn_food);
return APLRes_Success;
}
public native_earn_food(Handle:plugin, numParams)
{
new id = GetNativeCell(1);
return purchase_food(id);
}
public OnMapStart()
{
PrecacheSound("music/zmParadise/mygoodness_fix.mp3");
//PrecacheSound("music/zmParadise/AssKnife/predead.mp3");
AddFileToDownloadsTable("sound/music/zmParadise/mygoodness_fix.mp3");
//AddFileToDownloadsTable("sound/music/zmParadise/AssKnife/predead.mp3");
}
public Action:Event_RoundEnd(Handle: event , const String: name[] , bool: dontBroadcast)
{
remove_all_drug();
}
public Action:Event_Player_Spawn(Handle:event, const String:Name[], bool:Broadcast)
{
remove_all_drug();
}
public Action:Event_Player_Death(Handle:event, const String:Name[], bool:Broadcast)
{
remove_all_drug();
}
public Action:ZR_OnClientInfect(&client, &attacker, &bool:motherInfect, &bool:respawnOverride, &bool:respawn)
{
if(client >= 1 && client <= MaxClients)
{
if(IsClientInGame(client) && IsClientConnected(client))
{
kill_drug_task(client);
kill_speed_task(client);
}
}
}
public Action Clcmd_Food(int id, Arguments)
{
if(!IsClientConnected(id))
return Plugin_Continue;
if(!IsPlayerAlive(id))
return Plugin_Continue;
purchase_food(id);
return Plugin_Handled;
}
public purchase_food(id)
{
if(zp_get_user_ammo_packs(id) < 1)
{
CPrintToChat(id, "\x01[\x04Food]\x01 보유하신 탄약팩이 부족합니다!");
return;
}
if(!GetConVarInt(g_Cvar_FoodEnabled))
{
CPrintToChat(id, "\x01[\x04Food]\x01 %t", "Food Disabled");
return;
}
int multiple;
if(ZR_IsClientZombie(id))
multiple = 30;
else
multiple = 1;
int random = GetRandomInt(0, sizeof(foodamount)-1);
int hp = foodamount[random] * multiple;
if(ZR_IsClientHuman(id))
{
if(GetEntProp(id, Prop_Data, "m_iHealth") > 425)
{
CPrintToChat(id, "\x01|\x04[Food]\x01 %t", "Food Too High");
return;
}
}
CPrintToChatAll("\x01|\x04[Food] %t", "Food Ate", id, foodname[random], hp);
SetEntProp(id, Prop_Data, "m_iHealth", GetEntProp(id, Prop_Data, "m_iHealth") + hp);
if(foodskills[random] == 1)
{
if(ZR_IsClientHuman(id))
{
CPrintToChatAll("\x01|\x04[Food] %N \x01%t", id, "Food Speed");
EmitSoundToAll("music/zmParadise/mygoodness_fix.mp3");
fm_set_user_maxspeed(id, 1.4);
g_speed_timer[id] = CreateTimer(5.0, reset_user_speed, id);
}
}
if(foodskills[random] == 2)
{
CPrintToChatAll("\x01|\x04[Food] %N \x01%t", id, "Food Smoke");
EmitSoundToAll("music/zmParadise/mygoodness_fix.mp3");
fm_set_user_drug(id, 1);
g_drug_timer[id] = CreateTimer(1.0, set_drug, id, TIMER_REPEAT);
}
zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) - 1);
}
public OnClientDisconnect(id)
{
kill_speed_task(id);
kill_drug_task(id);
}
public Action:reset_user_speed(Handle:Timer, id)
{
fm_reset_user_maxspeed(id);
g_speed_timer[id] = INVALID_HANDLE;
}
public Action:set_drug(Handle:Timer, id)
{
static timer = 0;
if(timer > 5)
{
kill_drug_task(id);
fm_set_user_drug(id, 0);
return Plugin_Stop;
}
timer++;
fm_set_user_drug(id, 1);
return Plugin_Continue;
}
public kill_speed_task(id)
{
if(g_speed_timer[id] != INVALID_HANDLE)
{
fm_reset_user_maxspeed(id);
KillTimer(g_speed_timer[id]);
g_speed_timer[id] = INVALID_HANDLE;
}
}
public kill_drug_task(id)
{
if(g_drug_timer[id] != INVALID_HANDLE)
{
KillTimer(g_drug_timer[id]);
g_drug_timer[id] = INVALID_HANDLE;
}
}
stock fm_set_user_maxspeed(id, Float:speed)
{
if(ZR_IsClientHuman(id))
{
SetEntPropFloat(id, Prop_Data, "m_flLaggedMovementValue", speed);
}
}
stock fm_reset_user_maxspeed(id)
{
if(ZR_IsClientHuman(id))
{
SetEntPropFloat(id, Prop_Data, "m_flLaggedMovementValue", 1.0);
}
}
stock fm_set_user_drug(id, int flag)
{
switch(flag)
{
case 0:
{
new Float:angs[3];
GetClientEyeAngles(id, angs);
angs[2] = 0.0;
TeleportEntity(id, NULL_VECTOR, angs, NULL_VECTOR);
new clients[2];
clients[0] = id;
new duration = 1536;
new holdtime = 1536;
new flags = (0x0001 | 0x0010);
new color[4] = { 0, 0, 0, 0 };
Handle message = StartMessageEx(g_FadeUserMsgId, clients, 1);
Protobuf pb = UserMessageToProtobuf(message);
pb.SetInt("duration", duration);
pb.SetInt("hold_time", holdtime);
pb.SetInt("flags", flags);
pb.SetColor("clr", color);
EndMessage();
}
case 1:
{
new Float:angs[3];
GetClientEyeAngles(id, angs);
angs[2] = g_DrugAngles[GetRandomInt(0,100) % 20];
TeleportEntity(id, NULL_VECTOR, angs, NULL_VECTOR);
new clients[2];
clients[0] = id;
new duration = 255;
new holdtime = 255;
new flags = 0x0002;
new color[4] = { 0, 0, 0, 128 };
color[0] = GetRandomInt(0,255);
color[1] = GetRandomInt(0,255);
color[2] = GetRandomInt(0,255);
Handle message = StartMessageEx(g_FadeUserMsgId, clients, 1);
Protobuf pb = UserMessageToProtobuf(message);
pb.SetInt("duration", duration);
pb.SetInt("hold_time", holdtime);
pb.SetInt("flags", flags);
pb.SetColor("clr", color);
EndMessage();
}
default: return;
}
}
stock remove_all_drug()
{
for(int id=1; id<=MaxClients; id++)
{
if(IsClientInGame(id) && IsClientConnected(id))
{
new Float:angs[3];
GetClientEyeAngles(id, angs);
angs[2] = 0.0;
TeleportEntity(id, NULL_VECTOR, angs, NULL_VECTOR);
new clients[2];
clients[0] = id;
new duration = 1536;
new holdtime = 1536;
new flags = (0x0001 | 0x0010);
new color[4] = { 0, 0, 0, 0 };
Handle message = StartMessageEx(g_FadeUserMsgId, clients, 1);
Protobuf pb = UserMessageToProtobuf(message);
pb.SetInt("duration", duration);
pb.SetInt("hold_time", holdtime);
pb.SetInt("flags", flags);
pb.SetColor("clr", color);
EndMessage();
}
}
}