Skip to content

Instantly share code, notes, and snippets.

@icequeenzz
Created September 4, 2010 17:34
Show Gist options
  • Save icequeenzz/565342 to your computer and use it in GitHub Desktop.
Save icequeenzz/565342 to your computer and use it in GitHub Desktop.
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#define VERSION "0.1"
new Float:g_pos[3];
new prophealth[MAXPLAYERS+1][70];
new propindex[MAXPLAYERS+1][70];
new bool:fwmap;
new bool:fwbuild;
public Plugin:myinfo =
{
name = "[TF2] FortWars",
author = "Icequeenzz",
description = "FortWars",
version = VERSION,
url = "http://www.sourcemod.net"
}
public OnPluginStart()
{
CreateConVar("sm_test_version", VERSION, "test Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
RegAdminCmd("sm_test", Command_Test, ADMFLAG_SLAY);
}
public OnMapStart()
{
new String: map[3];
GetCurrentMap(map, 3);
// check if its a fortwars map and adjust bools towards it
if(StrContains(map, "fw_", false) != -1)
{
fwmap = true;
fwbuild = true;
PrintToChatAll("this is a fortwars map !");
}
else
{
fwmap = false;
fwbuild = false;
}
for(new i = 0; i < MAXPLAYERS+1; i++)
{
for(new j = 0; j < 70; j++)
{
prophealth[i][j] = -1;
}
}
// check if it is a fortwars map and adjust towards it
}
public Action:Command_Test(client, args)
{
if(!SetTeleportEndPoint(client))
{
PrintToChat(client, "[SM] Could not find spawn point.");
return Plugin_Handled;
}
if(GetEntityCount() >= GetMaxEntities()-32)
{
PrintToChat(client, "[SM] Entity limit is reached.");
return Plugin_Handled;
}
PrecacheModel("models/props_farm/concrete_block001.mdl" ,true);
new Prop = CreateEntityByName("prop_physics_override");
DispatchKeyValue(Prop, "model", "models/props_farm/concrete_block001.mdl");
if(IsValidEntity(Prop))
{
DispatchSpawn(Prop);
g_pos[2] -= 10.0;
TeleportEntity(Prop, g_pos, NULL_VECTOR, NULL_VECTOR);
AcceptEntityInput(Prop, "DisableMotion");
AcceptEntityInput(Prop, "SetHealth 100");
SDKHook(Prop, SDKHook_OnTakeDamage, OnPropTakeDamage);
SetPropHealth(Prop,client,400);
PrintToChatAll("prop id and client id: %i %N", Prop, client);
}
TurnProp(client, Prop);
MainMenu(client);
return Plugin_Handled;
}
SetTeleportEndPoint(client)
{
decl Float:vAngles[3];
decl Float:vOrigin[3];
decl Float:vBuffer[3];
decl Float:vStart[3];
decl Float:Distance;
GetClientEyePosition(client,vOrigin);
GetClientEyeAngles(client, vAngles);
//get endpoint for teleport
new Handle:trace = TR_TraceRayFilterEx(vOrigin, vAngles, MASK_SHOT, RayType_Infinite, TraceEntityFilterPlayer);
if(TR_DidHit(trace))
{
TR_GetEndPosition(vStart, trace);
GetVectorDistance(vOrigin, vStart, false);
Distance = -35.0;
GetAngleVectors(vAngles, vBuffer, NULL_VECTOR, NULL_VECTOR);
g_pos[0] = vStart[0] + (vBuffer[0]*Distance);
g_pos[1] = vStart[1] + (vBuffer[1]*Distance);
g_pos[2] = vStart[2] + (vBuffer[2]*Distance);
}
else
{
CloseHandle(trace);
return false;
}
CloseHandle(trace);
return true;
}
TurnAtAim(client)
{
decl aimprop;
if((aimprop = GetClientAimTarget(client, false)) != -1)
{
TurnProp(client, aimprop)
}
else
{
// print hud message that u need to aim at a prop.
}
}
TurnProp(client, prop)
{
decl Float:vAngles[3];
GetClientEyeAngles(client, vAngles);
vAngles[0] = 0.0;
vAngles[2] = 0.0;
TeleportEntity(prop, NULL_VECTOR, vAngles, NULL_VECTOR);
}
SetPropHealth(prop,client,health)
{
decl index;
for(new i = 0; i < 70; i++)
{
if(prophealth[client][i] == -1)
{
index = i;
break;
}
}
PrintToChatAll("index: %i", index);
prophealth[client][index] = health;
propindex[client][index] = prop;
}
public bool:TraceEntityFilterPlayer(entity, contentsMask)
{
return entity > GetMaxClients() || !entity;
}
public Action:MainMenu(clientId)
{
new Handle:menu = CreateMenu(MainMenuH);
SetMenuTitle(menu, "FortWars")
AddMenuItem(menu, "option1", "Create Prop")
AddMenuItem(menu, "option2", "Remove Prop")
AddMenuItem(menu, "option3", "Turn Prop")
AddMenuItem(menu, "option4", "Unstuck")
SetMenuExitButton(menu, true);
DisplayMenu(menu, clientId, 10);
}
public MainMenuH(Handle:menu, MenuAction:action, client, itemNum)
{
if ( action == MenuAction_Select )
{
switch (itemNum)
{
case 0:
{
}
case 1:
{
}
case 2:
{
TurnAtAim(client);
}
case 3:
{
}
}
}
else if (action == MenuAction_Cancel || action == MenuAction_End)
{
CloseHandle(menu);
}
}
public Action:OnPropTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype)
{
decl owner;
decl location;
//PrintToChatAll("prop id and client id: %i %N", victim, owner);
// get at what location the props thats attacked is is stored
for(new i = 0; i < MAXPLAYERS+1; i++)
{
for(new j = 0; j < 70; j++)
{
if(propindex[i][j] == victim)
{
owner = i;
location = j;
}
}
}
PrintToChatAll("location: %i", location);
// check if the prop is dead
if((prophealth[owner][location] - RoundFloat(damage)) < 0)
{
AcceptEntityInput(victim, "Kill");
prophealth[owner][location] = -1;
propindex[owner][location] = -1;
}
else
{
prophealth[owner][location] = (prophealth[owner][location] - RoundFloat(damage));
decl ocu;
ocu = RoundFloat(255.0/400.0 * float(prophealth[owner][location]));
SetEntityRenderColor(victim, ocu, ocu, ocu, ocu);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment