Raised This Month: $51 Target: $400
 12% 

Inconsistent Prop Spawning


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Weetabix
Member
Join Date: Feb 2017
Location: United Kingdom
Old 05-25-2020 , 13:13   Inconsistent Prop Spawning
Reply With Quote #1

Good day,

I'm in the process of remaking one of my old plugins, however I am once again plagued with a weird bug. I use the code below to spawn a challenge coin from Bloodhound and trigger so players can interact with it.

However, sometimes (usually consecutively), the coin model will appear and then disappear almost immediately and the trigger still functions as normal. I've tested it in a plain server and had no issues. My assumption is a plugin is causing it but I can't make sense of it.

Any help is amazing. Thank you.



PHP Code:
void SpawnCoin(const float vPos[3])
{
    
int iCoin CreateEntityByName("prop_dynamic");
    
int iTrigger CreateEntityByName("trigger_multiple");
    
    if(
IsValidEntity(iCoin) && IsValidEntity(iTrigger))
    {
        
//Coin Setup
        
DispatchKeyValue(iCoin"model""models/coop/challenge_coin.mdl");
        
SetEntPropFloat(iCoinProp_Send"m_flModelScale"0.7);
        
        
DispatchSpawn(iCoin);
        
        
SetVariantString("challenge_coin_idle");
        
AcceptEntityInput(iCoin"SetAnimation");
        
        
SetEntityRenderColor(iCoin2552150255);
        
        
TeleportEntity(iCoinvPosNULL_VECTORNULL_VECTOR);
        
        
//Trigger Setup
        
DispatchSpawn(iTrigger);
        
ActivateEntity(iTrigger);
        
        
SetEntityModel(iTrigger"models/props/cs_office/vending_machine.mdl");
        
        
TeleportEntity(iTriggervPosNULL_VECTORNULL_VECTOR);
                
        
float vMin[3], vMax[3];
        
        for (
int i 03i++) {
            
vMin[i] = -10.0;
        }

        for (
int i 03i++) {
            
vMax[i] = 10.0;
        }
        
        
SetEntPropVector(iTriggerProp_Send"m_vecMins"vMin);
        
SetEntPropVector(iTriggerProp_Send"m_vecMaxs"vMax);
        
SetEntPropEnt(iTriggerProp_Send"m_hOwnerEntity"iCoin);
        
SetEntProp(iTriggerProp_Send"m_nSolidType"2);
        
SetEntProp(iTriggerProp_Send"m_fEffects"GetEntProp(iTriggerProp_Send"m_fEffects") | 32);  
        
        
SDKHook(iTriggerSDKHook_StartTouchHook_StartTouch);

        
g_hTriggers.Push(iTrigger);
    }
}

public 
Action Hook_StartTouch(int iTriggerint iClient)
{
    if(
IsValidClient(iClient))
    {
        
int iCoin GetEntPropEnt(iTriggerProp_Send"m_hOwnerEntity");
        
        if(
IsValidEntity(iCoin))
        {    
            
int iEffect CreateEntityByName("info_particle_system");
            
            if(
IsValidEntity(iEffect))
            {
                
float vPos[3];
                
GetEntPropVector(iCoinProp_Data"m_vecOrigin"vPos);
            
                
DispatchKeyValue(iEffect"effect_name""confetti_B_omni");
                
                
DispatchSpawn(iEffect);
                
                
TeleportEntity(iEffectvPosNULL_VECTORNULL_VECTOR);
                
                
ActivateEntity(iEffect);
                
                
AcceptEntityInput(iEffect"Start");        
            }
            
            
CPrintToChatAll("%N"iClient);
                        
            
AcceptEntityInput(iCoin"Kill");
        }
        
        
g_hTriggers.Erase(g_hTriggers.FindValue(iTrigger));

        
AcceptEntityInput(iTrigger"Kill");
    }

Weetabix is offline
Balimbanana
Member
Join Date: Jan 2017
Old 05-25-2020 , 14:04   Re: Inconsistent Prop Spawning
Reply With Quote #2

Well, not quite sure why it would be removed, but you could try a prop_dynamic_override in case there is some sort of model issue.
There are many methods of doing the same sort of thing, before making a lot of changes, maybe make a backup just in case you want to go back to the method it is now.
Since it is being spawned, you might as well be using the engine to handle the properties of the coin:
Code:
SetEntPropFloat(iCoin, Prop_Send, "m_flModelScale", 0.7);
becomes:
DispatchKeyValue(iCoin, "modelscale", "0.7");

SetEntityRenderColor(iCoin, 255, 215, 0, 255);
becomes:
DispatchKeyValue(iCoin, "rendercolor", "255 215 0");
DispatchKeyValue(iCoin, "renderamt", "255");
and it wouldn't hurt to ActivateEntity(iCoin); and possibly AcceptEntityInput(iCoin, "Enable"); as well.
You could try teleporting the trigger before DispatchSpawn(iTrigger); there is a minor potential that it could be triggered at origin "0 0 0" just before it is teleported. The trigger could still be functioning because it is a trigger_multiple, could test if it is all still working with a trigger_once perhaps.
If the issue is that a trigger_once could give a starttouch at the wrong time, dispatch the key spawnflags 1 and possibly run it by a:
Code:
HookSingleEntityOutput(iTrigger, "OnStartTouch", Hook_StartTouch);
Then change the callback to:
public Action Hook_StartTouch(const char[] output, int caller, int activator, float delay)
Where the caller is the trigger, and activator is the client, it will only work if spawnflags 1 is set.

Other than that, it could be another plugin doing it.
It is a bit spammy, but if you want to see a lot of inputs/outputs, you can set the CVar developer to 2 on the server, and see if your coin is receiving inputs from somewhere else. To make it a bit easier to find in the inputs/outputs, dispatch a targetname for the coin.
Balimbanana is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:03.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode