#pragma semicolon 1
#include <sdktools>
#pragma newdecls required
#define dPush 100.0
int
Screen[MAXPLAYERS+1],
Melon[MAXPLAYERS+1];
float
MelonPos[MAXPLAYERS],
MelonEndPos[MAXPLAYERS+1],
MelonVel[MAXPLAYERS+1][3];
public void OnPluginStart(){
HookEvent("player_spawn", OnPlayerSpawn);
HookEvent("round_end", OnRoundEnd);
CreateTimer(0.1, GlobalTimer, _, 1|1);
}
public void OnMapStart(){
PrecacheModel("models/props_junk/watermelon01.mdl", true);
AddFileToDownloadsTable("models/props_junk/watermelon01.dx80.vtx");
AddFileToDownloadsTable("models/props_junk/watermelon01.dx90.vtx");
AddFileToDownloadsTable("models/props_junk/watermelon01.mdl");
AddFileToDownloadsTable("models/props_junk/watermelon01.phy");
AddFileToDownloadsTable("models/props_junk/watermelon01.sw.vtx");
AddFileToDownloadsTable("models/props_junk/watermelon01.vvd");
}
public void OnPlayerSpawn(Event event, const char[] name, bool db){
int client = GetClientOfUserId(event.GetInt("userid"));
Melon[client] = CreateEntityByName("prop_physics");
if(Melon[client] < 1)
return;
float pos[3]; GetClientEyePosition(client, pos);
SetEntityModel(Melon[client], "models/props_junk/watermelon01.mdl");
TeleportEntity(Melon[client], pos, NULL_VECTOR, NULL_VECTOR);
DispatchSpawn(Melon[client]);
SetScreen(client, Melon[client]);
}
stock Action SetScreen(int client, int ToEnt){
if(IsValidClient(client)){
int entity = CreateEntityByName("prop_dynamic_ornament");
if(entity < 1) return Plugin_Handled;
Screen[client] = entity;
DispatchKeyValue(entity, "model", "models/props_junk/watermelon01.mdl");
DispatchKeyValue(entity, "solid", "0");
SetEntityRenderMode(entity, RENDER_NONE)
float pos[3]; GetEntPropVector(Melon[client], Prop_Send, "m_vecOrigin", pos);
pos[2] += 100.0;
DispatchKeyValueVector(entity, "origin", pos);
float ang[3] = {90.0, 0.0, 0.0};
DispatchKeyValueVector(entity, "angles", ang);
DispatchSpawn(entity);
SetVariantString("!activator");
AcceptEntityInput(entity, "SetParent", ToEnt, entity);
// SetVariantString("primary");
// AcceptEntityInput(entity, "SetParentAttachment", client, entity);
// SetVariantString("baseorigin");
// AcceptEntityInput(entity, "SetParentAttachmentMaintainOffset", client, entity, 2);
SetClientViewEntity(client, entity);
}
return Plugin_Continue;
}
public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon, int &subtype, int &cmdnum, int &tickcount, int &seed, int mouse[2]) {
if(IsValidClient(client) && IsPlayerAlive(client)){
if(IsValidEntity(Melon[client])){
float push[3];
for(int x; x<3; x++)
push[x] = MelonVel[client][x];
if(buttons & IN_FORWARD || buttons & IN_MOVELEFT || buttons & IN_MOVERIGHT || buttons & IN_BACK || buttons & IN_JUMP){
float sPush = dPush*1.3;
if(buttons & IN_FORWARD)
push[0] = Lerp(0.05, 0.01, push[0], sPush);
if(buttons & IN_MOVELEFT)
push[1] = Lerp(0.05, 0.01, push[1], sPush);
if(buttons & IN_MOVERIGHT)
push[1] = Lerp(0.05, 0.01, push[1], -sPush);
if(buttons & IN_BACK)
push[0] = Lerp(0.05, 0.01, push[0], -sPush);
if(buttons & IN_JUMP)
if(push[2] < 0.1 && (MelonPos[client] - MelonEndPos[client]) < 8.87)
push[2] = Lerp(0.05, 0.75, push[2], sPush*2);
for(int x; x<3; x++)
MelonVel[client][x] = push[x];
TeleportEntity(Melon[client], NULL_VECTOR, NULL_VECTOR, push);
}
}
}
return Plugin_Continue;
}
public Action GlobalTimer(Handle timer){
for(int client = 1; client <= MaxClients; client++){
if(IsValidClient(client) && IsPlayerAlive(client)){
if(IsValidEntity(Melon[client])){
float push[3];
for(int x; x<3; x++)
push[x] = MelonVel[client][x];
if(!(GetClientButtons(client)&IN_FORWARD))
push[0] = Lerp(0.05, 0.05, push[0], 0.0);
if(!(GetClientButtons(client)&IN_MOVELEFT))
push[1] = Lerp(0.05, 0.05, push[1], 0.0);
if(!(GetClientButtons(client)&IN_BACK))
push[0] = Lerp(0.05, 0.05, push[0], 0.0);
if(!(GetClientButtons(client)&IN_MOVERIGHT))
push[1] = Lerp(0.05, 0.05, push[1], 0.0);
float ang[3] = {90.0, 0.0, 0.0};
float pos[3], EndPos[3];
GetEntPropVector(Melon[client], Prop_Send, "m_vecOrigin", pos);
TR_TraceRayFilter(pos, ang, MASK_SOLID, RayType_Infinite, EndPosFilter, Melon[client]);
TR_GetEndPosition(EndPos);
MelonPos[client] = pos[2];
MelonEndPos[client] = EndPos[2];
if((MelonPos[client] - MelonEndPos[client]) > 9.0)
push[2] = Lerp(0.05, 0.05, push[2], -300.0);
else push[2] = 0.0;
PrintHintText(client, "[%.1f][%.1f][%.1f]\n[%.1f]-[%.1f]=[%.1f]", push[0], push[1], push[2], MelonPos[client], MelonEndPos[client], MelonPos[client]-MelonEndPos[client]);
TeleportEntity(Melon[client], NULL_VECTOR, NULL_VECTOR, push);
for(int x; x<3; x++)
MelonVel[client][x] = push[x];
}
}
}
}
public void OnRoundEnd(Event event, const char[] name, bool db){
for(int client = 1; client <= MaxClients; client++){
if(IsValidEntity(Melon[client])){
AcceptEntityInput(Melon[client], "kill");
Melon[client] = 0;
}
if(IsValidEntity(Screen[client])){
AcceptEntityInput(Screen[client], "kill");
Screen[client] = 0;
}
}
}
stock float Lerp(float MinDiff, float t, float start, float end){
float result = start + t * (end - start);
if(MinDiff > 0.0){
if(result > start && result - start < MinDiff){
result = start + MinDiff;
}
else if(result < start && start - result < MinDiff){
result = start - MinDiff;
}
}
return result;
}
public bool EndPosFilter(int ent, int mask, any index){
return index != ent;
}
stock bool IsValidClient(int iClient){
if(iClient <= 0 || iClient > MaxClients || !IsClientInGame(iClient) || !IsClientConnected(iClient))
return false;
return true;
}