Помогите настроить спавн предметов

DimaKols

Участник
Сообщения
1
Реакции
0
Здравствуйте, есть плагин (оригинал tProps)

в нем ставлю, спавнится модели оружий, но они неподвижны.
есть другой плагин (во втором коде)
в нем все спавнится прекрасно, как можно эти 2 плагина объединить?
или хотя бы во втором, логику довести до того, чтоб можно было добавлять от себя модели, и прикреплять к ним доп.команду

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

#pragma semicolon 1

new PropCount[MAXPLAYERS+1];
new Movementtoggle[MAXPLAYERS+1];

new Handle:hRemoveProps;
new Handle:public_prop_menu = INVALID_HANDLE;

new Handle:hAdminMenu = INVALID_HANDLE;

public Plugin:myinfo =
{
name = "tProps",
author = "Totenfluch",
description = "spawn props in game at aim point",
version = "1.h5",
url = "SourceMod: Half-Life 2 Scripting"
};

public OnPluginStart()
{
HookEvent("round_start", Event_RoundStart);
HookEvent("player_death", Event_PlayerDeath);
HookEvent("player_disconnect", Event_PlayerDisconnect);

RegAdminCmd("sm_props", PropCommand, ADMFLAG_GENERIC, "opens the main prop menu");
RegAdminCmd("sm_propstoggle", PropCommandToggle, ADMFLAG_GENERIC, "toggles between psy and static props");
RegAdminCmd("sm_propsrm", PropCommandRM, ADMFLAG_GENERIC, "Removes prop aimed at");
RegAdminCmd("sm_propsrmall", PropCommandRMAll, ADMFLAG_GENERIC, "Removes all player props");
RegAdminCmd("sm_propsrmroot", RMAllPluginProps, ADMFLAG_ROOT, "Removes all props made by plugin");

hRemoveProps = CreateConVar("prop_removeondeath", "1", "0 is keep the props on death, 1 is remove them on death. Default: 1");

new Handle:topmenu;
if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
{ OnAdminMenuReady(topmenu); }
}
public OnLibraryRemoved(const String:name[])
{
if (StrEqual(name, "adminmenu"))
hAdminMenu = INVALID_HANDLE;
}
public CategoryHandler(Handle:topmenu,TopMenuAction:action,TopMenuObject:object_id,
param,String:buffer[],maxlength)
{
if (action == TopMenuAction_DisplayTitle)
Format(buffer, maxlength, "tProps");
else if (action == TopMenuAction_DisplayOption)
Format(buffer, maxlength, "tProps");
}

public OnAdminMenuReady(Handle:topmenu)
{
/* Block us from being called twice */
if (topmenu == hAdminMenu)
return;
hAdminMenu = topmenu;
new TopMenuObject:obj_tPropsMenu = AddToTopMenu(hAdminMenu,
"tProps",TopMenuObject_Category,CategoryHandler,INVALID_TOPMENUOBJECT);

AddToTopMenu(hAdminMenu, "item1", TopMenuObject_Item, ItemHandler, obj_tPropsMenu, "sm_props");
AddToTopMenu(hAdminMenu, "item2", TopMenuObject_Item, ItemHandler, obj_tPropsMenu, "sm_propstoggle");
AddToTopMenu(hAdminMenu, "item3", TopMenuObject_Item, ItemHandler, obj_tPropsMenu, "sm_propsrm");
AddToTopMenu(hAdminMenu, "item4", TopMenuObject_Item, ItemHandler, obj_tPropsMenu, "sm_propsrmall");
AddToTopMenu(hAdminMenu, "item5", TopMenuObject_Item, ItemHandler, obj_tPropsMenu, "sm_propsrmroot");
}

public ItemHandler(Handle:topmenu, TopMenuAction:action, TopMenuObject:object_id,
param, String:buffer[], maxlength)
{
new String:obj_str[64]; GetTopMenuObjName(topmenu, object_id, obj_str, sizeof(obj_str));

if (action == TopMenuAction_DisplayOption)
{
if (StrEqual(obj_str, "item1")) { Format(buffer, maxlength, "Props Spawn Menu"); }
if (StrEqual(obj_str, "item2")) {
if (Movementtoggle[param]) { Format(buffer, maxlength, "Toggle to PHYSICS props"); }
else { Format(buffer, maxlength, "Toggle to STATIC props"); }
}
if (StrEqual(obj_str, "item3")) { Format(buffer, maxlength, "remove prop aimed at"); }
if (StrEqual(obj_str, "item4")) { Format(buffer, maxlength, "remove your %d props", PropCount[param]); }
if (StrEqual(obj_str, "item5")) { Format(buffer, maxlength, "remove ALL Plugins props"); }
}
else if (action == TopMenuAction_SelectOption)
{
if (StrEqual(obj_str, "item1")) { PropCommand(param, param); return; }
if (StrEqual(obj_str, "item2")) { PropCommandToggle(param, param); }
if (StrEqual(obj_str, "item3")) { PropCommandRM(param, param); }
if (StrEqual(obj_str, "item4")) { PropCommandRMAll(param, param); }
if (StrEqual(obj_str, "item5")) { RMAllPluginProps(param, param); }
RedisplayAdminMenu(Handle:hAdminMenu,param);
}
}

public OnClientPostAdminCheck(client){
if(!IsFakeClient(client) && CheckCommandAccess(client, "override_string", ADMFLAG_GENERIC))
Movementtoggle[client] = 1;
}

public Event_PlayerDeath(Handle: event , const String: name[] , bool: dontBroadcast)
{
new victim = GetClientOfUserId(GetEventInt(event, "userid"));
new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));

if(!Client_IsValid(attacker))
return;

if(GetConVarInt(hRemoveProps))
KillProps(victim);
}
public Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
for(new i=1; i<=MaxClients; i++) {
if(IsClientConnected(i) && !IsFakeClient(i) && PropCount > 0)
PropCount = 0;
}
}

public Event_PlayerDisconnect(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid")); KillProps(client);
}

public Action:PropCommand(client, args)
{
if (client) {
new String:textPath[255];
BuildPath(Path_SM, textPath, sizeof(textPath), "data/propslist.txt");
new Handle:kv = CreateKeyValues("Props");
FileToKeyValues(kv, textPath);
public_prop_menu = CreateMenu(Public_Prop_Menu_Handler);
SetMenuTitle(public_prop_menu, "propSpawn Menu");
PopLoop(kv); DisplayMenu(public_prop_menu, client, MENU_TIME_FOREVER);
}
return Plugin_Handled;
}

public Public_Prop_Menu_Handler(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_Select) {
PropSpawn(param1, param2); new String:textPath[255];
BuildPath(Path_SM, textPath, sizeof(textPath), "data/propslist.txt");
new Handle:kv = CreateKeyValues("Props"); FileToKeyValues(kv, textPath);
public_prop_menu = CreateMenu(Public_Prop_Menu_Handler);
SetMenuTitle(public_prop_menu, "propSpawn Menu");
PopLoop(kv); DisplayMenu(public_prop_menu, param1, MENU_TIME_FOREVER);
}
}

PopLoop(Handle:kv)
{
if (KvGotoFirstSubKey(kv)) {
do {
new String:buffer[256];
KvGetSectionName(kv, buffer, sizeof(buffer));
AddMenuItem(public_prop_menu, buffer, buffer);
}
while (KvGotoNextKey(kv));
CloseHandle(kv);
}
}

public PropSpawn(client, param2)
{
new String:prop_choice[255];

GetMenuItem(public_prop_menu, param2, prop_choice, sizeof(prop_choice));

new String:name[255]; GetClientName(client, name, sizeof(name));

decl String:modelname[255]; new String:file[255];
BuildPath(Path_SM, file, 255, "data/propslist.txt");
new Handle:kv = CreateKeyValues("Props");
FileToKeyValues(kv, file); KvJumpToKey(kv, prop_choice);
KvGetString(kv, "model", modelname, sizeof(modelname),"");

decl Ent; PrecacheModel(modelname,true);
Ent = CreateEntityByName("prop_physics_override");

new String:EntName[256];
Format(EntName, sizeof(EntName), "tPropSpawn%d_n%d", client, PropCount[client]);

DispatchKeyValue(Ent, "physdamagescale", "0.0");
DispatchKeyValue(Ent, "model", modelname);
DispatchKeyValue(Ent, "targetname", EntName);

if (StrContains(modelname, "barrel") > -1) {
DispatchKeyValue(Ent, "spawnflags", "48");
DispatchKeyValue(Ent, "health", "40"); DispatchKeyValue(Ent, "minhealthdmg", "2");
DispatchKeyValue(Ent, "ExplodeRadius", "800"); DispatchKeyValue(Ent, "ExplodeDamage", "25");
}

DispatchSpawn(Ent);

decl Float:viewpos[3]; viewpos = GetViewPoint(client);

decl Float:propang[3], Float:clientang[3];
GetClientEyeAngles(client, clientang);
propang[1] = clientang[1] + 90;

TeleportEntity(Ent, viewpos, propang, NULL_VECTOR);

if (Movementtoggle[client] == 0) { SetEntityMoveType(Ent, MOVETYPE_VPHYSICS); }
else { SetEntityMoveType(Ent, MOVETYPE_PUSH); }

if(viewpos[0] == 0.0 && viewpos[1] == 0.0 && viewpos[2] == 0.0){
new prop = Entity_FindByName(EntName);
AcceptEntityInput(prop, "kill");
}
else{ PrintToChat(client, "[SM] You spawned \x05%s", prop_choice); }
CloseHandle(kv); PropCount[client] += 1; return;
}

Float:GetViewPoint(client)
{
decl Float:start[3], Float:angle[3], Float:end[3];
GetClientEyePosition(client, start);
GetClientEyeAngles(client, angle);
TR_TraceRayFilter(start, angle, MASK_SOLID, RayType_Infinite, TraceEntityFilterPlayer, client);
if (TR_DidHit(INVALID_HANDLE))
{ TR_GetEndPosition(end, INVALID_HANDLE); return end; }
else {
PrintToChat(client, "[SM] Could not spawn prop at that view positon!");
end[0] = 0.0; end[1] = 0.0; end[2] = 0.0; return end;
}
}

public bool:TraceEntityFilterPlayer(entity, contentsMask, any:data)
{
return entity > MaxClients;
}

public Action:PropCommandRM(client, args)
{
if(client){
new prop = GetClientAimTarget(client, false);
if (prop == -1)
return Plugin_Handled;

new String:EntName[256];
Entity_GetName(prop, EntName, sizeof(EntName));

new validProp = StrContains(EntName, "tPropSpawn");
if(validProp > -1) {
new String:tempInd[3];
tempInd[0] = EntName[15];
tempInd[1] = EntName[16];
tempInd[2] = EntName[17];

ReplaceString(tempInd, sizeof(tempInd), "_", "");
new clientIndex = StringToInt(tempInd);
AcceptEntityInput(prop, "kill");
PropCount[clientIndex] = PropCount[clientIndex] - 1;
PrintToChat(client, "[SM] Removed the prop you were aiming at.");
}
}
return Plugin_Handled;
}

public Action:PropCommandRMAll(client, args)
{
if(client) { KillProps(client); }
return Plugin_Handled;
}

public Action:PropCommandToggle(client, args)
{
if(client){
if(Movementtoggle[client]){
Movementtoggle[client] = 0;
PrintToChat(client, "*** You will now spawn \x05physics\x01 props.");
}
else {
Movementtoggle[client] = 1;
PrintToChat(client, "*** You will now spawn \x05static\x01 Props.");
}
}
return Plugin_Handled;
}

stock KillProps(client)
{
for(new i=0; i<=PropCount[client]; i++) {
new String:EntName[MAX_NAME_LENGTH+5];
Format(EntName, sizeof(EntName), "tPropSpawn%d_n%d", client, i);
new prop = Entity_FindByName(EntName);
if(prop != -1)
AcceptEntityInput(prop, "kill");
}
PropCount[client] = 0;
}

public Action:RMAllPluginProps(client, args)
{
new maxent = GetMaxEntities(); decl String:sClassName[64];
for (new i=MaxClients; i < maxent; i++) {
if (IsValidEntity(i) && GetEntityClassname(i, sClassName, sizeof(sClassName))) {
if (StrEqual(sClassName, "prop_physics")) {
new String:EntName[256]; Entity_GetName(i, EntName, sizeof(EntName));
if(StrContains(EntName, "tPropSpawn") > -1)
AcceptEntityInput(i, "kill");
}
}
}
for(new i=1; i<=MaxClients; i++) {
if(IsClientConnected(i) && !IsFakeClient(i) && PropCount > 0)
PropCount = 0;
}
decl String:nick[64]; GetClientName(client, nick, sizeof(nick));
PrintToChatAll("[SM] %s removed all plugin props.", nick); return Plugin_Handled;
}

вот второй плагин

#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

#define VERSION "1.3"

#define MODEL "models/weapons/w_snip_g3sg1.mdl"

new Handle:drhax_enabled = INVALID_HANDLE;
new Handle:drhax_monitor_weight = INVALID_HANDLE;
new Handle:drhax_throwing_force = INVALID_HANDLE;
new Handle:drhax_let_users_set_weight = INVALID_HANDLE;
new Handle:drhax_distance_from_spawner = INVALID_HANDLE;
new Handle:drhax_only_admins = INVALID_HANDLE;
new Handle:drhax_entity_destroy_delay = INVALID_HANDLE;
new Handle:drhax_enable_teamkill = INVALID_HANDLE;

new Handle:g_hThrowedObjects = INVALID_HANDLE;



public Plugin:myinfo =
{
name = "SpawnMon",
author = "Push",
description = "Fell yourself as Dr.Hax",
version = VERSION,
url = ""
};

public OnPluginStart()
{
g_hThrowedObjects = CreateArray( 2 );

drhax_enabled = CreateConVar( "drhax_enabled", "1", "Enable the plugin?" );
drhax_monitor_weight = CreateConVar( "drhax_monitor_weight", "0.0", "Default weight of monitor." );
drhax_throwing_force = CreateConVar( "drhax_throwing_force", "1000.0" , "Force of throwing the monitor ( More = better )." );
drhax_let_users_set_weight = CreateConVar( "drhax_let_users_set_weight", "1", "Do you want to let users set monitor's weight?" );
drhax_distance_from_spawner = CreateConVar( "drhax_distance_from_spawner", "40.0", "Distance from object's creator to a spawned object." );
drhax_only_admins = CreateConVar( "drhax_only_admins", "1", "Only admins can throw monitors. Disable it at your own risk :)" );
drhax_entity_destroy_delay = CreateConVar( "drhax_entity_destroy_delay", "4", "Delay before entity will be destroyed by entity dissolver" );
drhax_enable_teamkill = CreateConVar( "drhax_enable_teamkill", "1", "Enable teamkilling by monitors?" );

AutoExecConfig( );

RegConsoleCmd( "sm_hax", CommandHandler );
}

public OnPluginEnd( )
{
CloseHandle( g_hThrowedObjects );
}

public OnConfigsExecuted( )
{
new String:szBuffer[ PLATFORM_MAX_PATH ];

PrecacheModel( MODEL );

Format( szBuffer, sizeof( szBuffer ), szBuffer );

AddFileToDownloadsTable( szBuffer );
}

public Action:CommandHandler( client, args )
{
if( GetConVarBool( drhax_enabled ) )
{
new Float:fMonitorWeight;
new Float:fDefMonitorWeight;

fDefMonitorWeight = GetConVarFloat( drhax_monitor_weight );

if( GetConVarBool( drhax_only_admins ) )
{
if( GetUserAdmin( client ) == INVALID_ADMIN_ID )
{
PrintToChat( client, "It works only for admins." );
return Plugin_Handled;
}
}

if( GetCmdArgs() == 1 && GetConVarBool( drhax_let_users_set_weight ) )
{
new String:szMonitorWeight[16];

if( GetCmdArg( 1, szMonitorWeight, sizeof( szMonitorWeight ) ) )
{
fMonitorWeight = StringToFloat( szMonitorWeight );
}
else
{
fMonitorWeight = fDefMonitorWeight;
}
}
else
{
fMonitorWeight = fDefMonitorWeight;
}

if( IsPlayerAlive( client ) )
{
new Float:fPlayerPos[3];
new Float:fPlayerAngles[3];
new Float:fThrowingVector[3];
new Float:fDistanceFromSpawner;
new Float:fThrowingForce;

new String:szMonitorWeight[ PLATFORM_MAX_PATH ];

Format( szMonitorWeight, sizeof( szMonitorWeight ), "%f", fMonitorWeight );

fDistanceFromSpawner = GetConVarFloat( drhax_distance_from_spawner );
fThrowingForce = GetConVarFloat( drhax_throwing_force );

GetClientEyeAngles( client, fPlayerAngles );
GetClientEyePosition( client, fPlayerPos );

TR_TraceRayFilter( fPlayerPos, fPlayerAngles, MASK_SOLID, RayType_Infinite, DontHitSelf, client );

if( TR_DidHit( ) )
{
new Float:fEndPosition[3];

TR_GetEndPosition( fEndPosition );

if( GetVectorDistance( fPlayerPos, fEndPosition ) < fDistanceFromSpawner ) // if distance from player to a target is so long...
{
return Plugin_Handled; // return
}
}

new Float:fLen = fDistanceFromSpawner * Sine( DegToRad( fPlayerAngles[0] + 40.0 ) );

fPlayerPos[0] = fPlayerPos[0] + fLen * Cosine( DegToRad( fPlayerAngles[1] ) );
fPlayerPos[1] = fPlayerPos[1] + fLen * Sine( DegToRad( fPlayerAngles[1] ) );
fPlayerPos[2] = fPlayerPos[2] + fDistanceFromSpawner * Sine( DegToRad( -1 * fPlayerAngles[0] ) ) ;

new entity = CreateEntityByName( "prop_physics_override" );

DispatchKeyValue( entity, "model", MODEL );
DispatchKeyValue( entity, "massScale", szMonitorWeight );
DispatchKeyValue( entity, "spawnflags", "6" );

DispatchSpawn( entity );
ActivateEntity( entity );

new Float:fScal = fThrowingForce * Sine( DegToRad( fPlayerAngles[0] + 90.0 ) );

fThrowingVector[0] = fScal * Cosine( DegToRad( fPlayerAngles[1] ) );
fThrowingVector[1] = fScal * Sine( DegToRad( fPlayerAngles[1] ) );
fThrowingVector[2] = fThrowingForce * Sine( DegToRad( -1 * fPlayerAngles[0] ) );

new iPair[2];

iPair[0] = entity;
iPair[1] = client;

PushArrayArray( g_hThrowedObjects, iPair, sizeof( iPair ) );
SDKHook( entity, SDKHook_ShouldCollide, ShouldCollide );

TeleportEntity( entity, fPlayerPos, fPlayerAngles, fThrowingVector );

CreateTimer( GetConVarFloat( drhax_entity_destroy_delay ), OnTimerTick, entity );
}
}

return Plugin_Handled;
}

public bool:ShouldCollide( entity, collisiongroup, contentsmask, bool:originalResult )
{
if( contentsmask & MASK_PLAYERSOLID )
{
new Float:fMaxs[3];
GetEntPropVector( entity, Prop_Send, "m_vecMaxs", fMaxs );

new Float:fPos[3];
GetEntPropVector( entity, Prop_Send, "m_vecOrigin", fPos );

new Float:fDist;
fDist = GetVectorLength( fMaxs ) * 1.5;

for( new client = 1; client < MaxClients; client++ ) // Checking all players which is on a server
{
if( IsClientInGame( client ) && IsPlayerAlive( client ) )
{
new Float:fPlayerOrigin[3];
new Float:fPlayerEyesPose[3];

GetClientAbsOrigin( client, fPlayerOrigin );
GetClientEyePosition( client, fPlayerEyesPose );

for( new Float:i = 0.0; i < GetVectorDistance( fPlayerOrigin, fPlayerEyesPose ); i+=1.0 )
{
new Float:fPointInPlayer[3];
new bool:bPlayerKilled = false;

fPointInPlayer[0] = fPlayerOrigin[0];
fPointInPlayer[1] = fPlayerOrigin[1];
fPointInPlayer[2] = fPlayerOrigin[2] + i;

if( GetVectorDistance( fPointInPlayer, fPos ) <= fDist )
{
new iArrSize = GetArraySize( g_hThrowedObjects );

if( iArrSize != 0 )
{
for( new count = 0; count < iArrSize; count++ )
{
new iPair[2];

GetArrayArray( g_hThrowedObjects, count, iPair, sizeof( iPair ) );
if( entity == iPair[0] )
{
if( client != iPair[1] && IsPlayerAlive( client ) )
{
if( !GetConVarBool( drhax_enable_teamkill ) && GetClientTeam( client ) != GetClientTeam( iPair[1] )
|| GetConVarBool( drhax_enable_teamkill ) )
{
bPlayerKilled = true;
ForcePlayerSuicide( client );

break;
}
}
}
}
}
}

if( bPlayerKilled )
{
bPlayerKilled = false;

break;
}
}
}
}
}

return true;
}

public bool:DontHitSelf( entity, mask, any:data )
{
if( entity == data )
{
return false;
}

return true;
}

public Action:OnTimerTick( Handle:hTimer, any:data )
{
new iArrSize = GetArraySize( g_hThrowedObjects );
Dissolve( data );

if( iArrSize != 0 )
{
for( new i = 0; i < iArrSize; i++ )
{
new iPair[2];
GetArrayArray( g_hThrowedObjects, i, iPair, sizeof( iPair ) );

if( iPair[0] == data )
{
iArrSize--;
RemoveFromArray( g_hThrowedObjects, i-- );
}
}
}

return Plugin_Continue;
}

stock void:Dissolve(edict)
{
if(IsValidEntity(edict))
{
new String:dname[32], ent = CreateEntityByName("env_entity_dissolver");

Format(dname, sizeof(dname), "dis_%d", edict);

if (ent > 0)
{
DispatchKeyValue(edict, "targetname", dname);
DispatchKeyValue(ent, "dissolvetype", "3");
DispatchKeyValue(ent, "target", dname);
AcceptEntityInput(ent, "Dissolve");
AcceptEntityInput(ent, "kill");
}
}
}
 
Сверху Снизу