Заменить/Дать свойства entity на карте

AlmazON

Не путать с самим yand3xmail
Сообщения
5,099
Реакции
2,755
без результатов
Попробуй пересоздать мяч со своими характеристиками:
PHP:
#include <sdktools>

public OnPluginStart() RegConsoleCmd("sm_ball", CreateSoccerBall, "Создать мяч вместо объекта на прицеле.");

public OnMapStart()
{
	AddFileToDownloadsTable("models/forlix/soccer/soccerball.dx80.vtx");
	AddFileToDownloadsTable("models/forlix/soccer/soccerball.dx90.vtx");
	AddFileToDownloadsTable("models/forlix/soccer/soccerball.mdl");
	AddFileToDownloadsTable("models/forlix/soccer/soccerball.phy");
	AddFileToDownloadsTable("models/forlix/soccer/soccerball.sw.vtx");
	AddFileToDownloadsTable("models/forlix/soccer/soccerball.vvd");
	AddFileToDownloadsTable("models/forlix/soccer/soccerball.xbox.vtx");
	AddFileToDownloadsTable("materials/models/forlix/soccer/soccerball.vmt");
	AddFileToDownloadsTable("materials/models/forlix/soccer/soccerball.vtf");

	PrecacheModel("models/forlix/soccer/soccerball.mdl");
}

public Action:CreateSoccerBall(client, args)
{
    if (client)
    {
        decl entity;
        if ((entity = GetClientAimTarget(client, false)) != -1)
        {
			decl Float:origin[3];
			GetEntPropVector(entity, Prop_Data, "m_vecOrigin", origin);
			RemoveEdict(entity);
			if ((entity = CreateEntityByName("prop_physics_override")) != -1)
			{
				SetEntityModel(entity, "models/forlix/soccer/soccerball.mdl");
				DispatchKeyValue(entity, "StartDisabled", "false");
				DispatchKeyValue(entity, "Solid", "6");
				DispatchKeyValue(entity, "spawnflags", "1026");
				DispatchKeyValue(entity, "classname", "models/forlix/soccer/soccerball.mdl");
				DispatchKeyValueVector(entity, "origin", origin);
				DispatchSpawn(entity);
				AcceptEntityInput(entity, "TurnOn");
				AcceptEntityInput(entity, "EnableCollision");
				SetEntProp(entity, Prop_Data, "m_CollisionGroup", 5);
				//SetEntityMoveType(entity, MOVETYPE_VPHYSICS);
				//AcceptEntityInput(entity, "Wake");
				//AcceptEntityInput(entity, "EnableMotion");
				PrintToChat(client, "\x01Объект \x03%i \x01заменён на \x05мяч\x01.", entity);
			}
        }
    }
    return Plugin_Handled;
}

public OnGameFrame()
{
    static String:classname[32], entity;
    for (new i = 1; i <= MaxClients; ++i)
    {
        if (IsClientInGame(i) && (entity = GetClientAimTarget(i, false)) != -1)
        {
            GetEdictClassname(entity, classname, sizeof(classname));
            PrintHintText(i, "Вы смотрите на\nEntity index: %i classname: %s", entity, classname);
        }
    }
}
Модели скачать в теме [CS: Source] - Soccer Ball 1.2.
 

Kruzi

Участник
Сообщения
153
Реакции
20
Попробуй пересоздать мяч со своими характеристиками:
PHP:
#include <sdktools>

public OnPluginStart() RegConsoleCmd("sm_ball", CreateSoccerBall, "Создать мяч вместо объекта на прицеле.");

public OnMapStart()
{
    AddFileToDownloadsTable("models/forlix/soccer/soccerball.dx80.vtx");
    AddFileToDownloadsTable("models/forlix/soccer/soccerball.dx90.vtx");
    AddFileToDownloadsTable("models/forlix/soccer/soccerball.mdl");
    AddFileToDownloadsTable("models/forlix/soccer/soccerball.phy");
    AddFileToDownloadsTable("models/forlix/soccer/soccerball.sw.vtx");
    AddFileToDownloadsTable("models/forlix/soccer/soccerball.vvd");
    AddFileToDownloadsTable("models/forlix/soccer/soccerball.xbox.vtx");
    AddFileToDownloadsTable("materials/models/forlix/soccer/soccerball.vmt");
    AddFileToDownloadsTable("materials/models/forlix/soccer/soccerball.vtf");

    PrecacheModel("models/forlix/soccer/soccerball.mdl");
}

public Action:CreateSoccerBall(client, args)
{
    if (client)
    {
        decl entity;
        if ((entity = GetClientAimTarget(client, false)) != -1)
        {
            decl Float:origin[3];
            GetEntPropVector(entity, Prop_Data, "m_vecOrigin", origin);
            RemoveEdict(entity);
            if ((entity = CreateEntityByName("prop_physics_override")) != -1)
            {
                SetEntityModel(entity, "models/forlix/soccer/soccerball.mdl");
                DispatchKeyValue(entity, "StartDisabled", "false");
                DispatchKeyValue(entity, "Solid", "6");
                DispatchKeyValue(entity, "spawnflags", "1026");
                DispatchKeyValue(entity, "classname", "models/forlix/soccer/soccerball.mdl");
                DispatchKeyValueVector(entity, "origin", origin);
                DispatchSpawn(entity);
                AcceptEntityInput(entity, "TurnOn");
                AcceptEntityInput(entity, "EnableCollision");
                SetEntProp(entity, Prop_Data, "m_CollisionGroup", 5);
                //SetEntityMoveType(entity, MOVETYPE_VPHYSICS);
                //AcceptEntityInput(entity, "Wake");
                //AcceptEntityInput(entity, "EnableMotion");
                PrintToChat(client, "\x01Объект \x03%i \x01заменён на \x05мяч\x01.", entity);
            }
        }
    }
    return Plugin_Handled;
}

public OnGameFrame()
{
    static String:classname[32], entity;
    for (new i = 1; i <= MaxClients; ++i)
    {
        if (IsClientInGame(i) && (entity = GetClientAimTarget(i, false)) != -1)
        {
            GetEdictClassname(entity, classname, sizeof(classname));
            PrintHintText(i, "Вы смотрите на\nEntity index: %i classname: %s", entity, classname);
        }
    }
}
Модели скачать в теме [CS: Source] - Soccer Ball 1.2.
Спасибо, работает.
А теперь помогите в месте спавна старого мяча сделать новый, пожалуйста, моих знаний sourcepawna явно не хватит
Вот я сделал координаты нижнего крайнего угла и противоположного угла чуть выше (как бы создал прямоугольник)
C-подобный:
//setpos 2449.041992 2501.572754 1894.288574;setang 89.000000 0.570909 0.000000
//setpos 2564.679199 2632.775879 1960.691650;setang 89.000000 179.431702 0.000000
PHP:
public OnMapStart(){
decl String:currentMap[64];
GetCurrentMap(currentMap, 64);
if(StrEqual(currentMap, "mg_bob2"))
{
//заменяем ентити по координатам
}
так? Или лучше через map config отключать и включать плагин?
Кстати, пока тестировал заметил что мяч может куда-то пропасть в 1/20 случаев.
P.S. Можно ли добавить мячу какое-то свечение либо трейл обычный как за гранатой, например?
 

AlmazON

Не путать с самим yand3xmail
Сообщения
5,099
Реакции
2,755
мяч рандомно в рамках той коробки
Без разницы, на его же месте будет новый мяч:
PHP:
#include <sdktools>

#define MAP_FOR_BALL	"mg_bob2"	//Карта, на которой необходимо заменить мяч

public OnConfigsExecuted()
{
	static bool:SoccerBall;
	decl String:map[32];
	GetCurrentMap(map, sizeof(map));
	if (strcmp(map, MAP_FOR_BALL))
	{
		if (SoccerBall)
		{
			UnhookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
			SoccerBall = false;
		}
	}
	else
	{
		FilesSoccerBall();
		if (SoccerBall == false)
		{
			HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
			SoccerBall = true;
		}
	}
}

FilesSoccerBall()
{
	AddFileToDownloadsTable("models/forlix/soccer/soccerball.dx80.vtx");
	AddFileToDownloadsTable("models/forlix/soccer/soccerball.dx90.vtx");
	AddFileToDownloadsTable("models/forlix/soccer/soccerball.mdl");
	AddFileToDownloadsTable("models/forlix/soccer/soccerball.phy");
	AddFileToDownloadsTable("models/forlix/soccer/soccerball.sw.vtx");
	AddFileToDownloadsTable("models/forlix/soccer/soccerball.vvd");
	AddFileToDownloadsTable("models/forlix/soccer/soccerball.xbox.vtx");
	AddFileToDownloadsTable("materials/models/forlix/soccer/soccerball.vmt");
	AddFileToDownloadsTable("materials/models/forlix/soccer/soccerball.vtf");

	PrecacheModel("models/forlix/soccer/soccerball.mdl");
}

public Event_RoundStart(Handle:event, String:name[], bool:dontBroadcast)
{
	decl entity;
	if ((entity = FindEntityByClassname(MaxClients + 1, "func_physbox")) != -1)
	{
		decl Float:origin[3];
		GetEntPropVector(entity, Prop_Data, "m_vecOrigin", origin);
		RemoveEdict(entity);
		if ((entity = CreateEntityByName("prop_physics_override")) != -1)
		{
			SetEntityModel(entity, "models/forlix/soccer/soccerball.mdl");
			DispatchKeyValue(entity, "StartDisabled", "false");
			DispatchKeyValue(entity, "Solid", "6");
			DispatchKeyValue(entity, "spawnflags", "1026");
			DispatchKeyValue(entity, "classname", "soccer_ball");
			DispatchKeyValueVector(entity, "origin", origin);
			DispatchSpawn(entity);
			AcceptEntityInput(entity, "EnableCollision");
			SetEntProp(entity, Prop_Data, "m_CollisionGroup", 5);
			AcceptEntityInput(entity, "TurnOn");
			//SetEntityMoveType(entity, MOVETYPE_VPHYSICS);
			//AcceptEntityInput(entity, "Wake");
			//AcceptEntityInput(entity, "EnableMotion");
		}
	}
}
 

Kruzi

Участник
Сообщения
153
Реакции
20
Без разницы, на его же месте будет новый мяч:
PHP:
#include <sdktools>

#define MAP_FOR_BALL    "mg_bob2"    //Карта, на которой необходимо заменить мяч

public OnConfigsExecuted()
{
    static bool:SoccerBall;
    decl String:map[32];
    GetCurrentMap(map, sizeof(map));
    if (strcmp(map, MAP_FOR_BALL))
    {
        if (SoccerBall)
        {
            UnhookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
            SoccerBall = false;
        }
    }
    else
    {
        FilesSoccerBall();
        if (SoccerBall == false)
        {
            HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
            SoccerBall = true;
        }
    }
}

FilesSoccerBall()
{
    AddFileToDownloadsTable("models/forlix/soccer/soccerball.dx80.vtx");
    AddFileToDownloadsTable("models/forlix/soccer/soccerball.dx90.vtx");
    AddFileToDownloadsTable("models/forlix/soccer/soccerball.mdl");
    AddFileToDownloadsTable("models/forlix/soccer/soccerball.phy");
    AddFileToDownloadsTable("models/forlix/soccer/soccerball.sw.vtx");
    AddFileToDownloadsTable("models/forlix/soccer/soccerball.vvd");
    AddFileToDownloadsTable("models/forlix/soccer/soccerball.xbox.vtx");
    AddFileToDownloadsTable("materials/models/forlix/soccer/soccerball.vmt");
    AddFileToDownloadsTable("materials/models/forlix/soccer/soccerball.vtf");

    PrecacheModel("models/forlix/soccer/soccerball.mdl");
}

public Event_RoundStart(Handle:event, String:name[], bool:dontBroadcast)
{
    decl entity;
    if ((entity = FindEntityByClassname(MaxClients + 1, "func_physbox")) != -1)
    {
        decl Float:origin[3];
        GetEntPropVector(entity, Prop_Data, "m_vecOrigin", origin);
        RemoveEdict(entity);
        if ((entity = CreateEntityByName("prop_physics_override")) != -1)
        {
            SetEntityModel(entity, "models/forlix/soccer/soccerball.mdl");
            DispatchKeyValue(entity, "StartDisabled", "false");
            DispatchKeyValue(entity, "Solid", "6");
            DispatchKeyValue(entity, "spawnflags", "1026");
            DispatchKeyValue(entity, "classname", "soccer_ball");
            DispatchKeyValueVector(entity, "origin", origin);
            DispatchSpawn(entity);
            AcceptEntityInput(entity, "EnableCollision");
            SetEntProp(entity, Prop_Data, "m_CollisionGroup", 5);
            AcceptEntityInput(entity, "TurnOn");
            //SetEntityMoveType(entity, MOVETYPE_VPHYSICS);
            //AcceptEntityInput(entity, "Wake");
            //AcceptEntityInput(entity, "EnableMotion");
        }
    }
}
А трейл трудно будет сделать?
 
Сверху Снизу