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

Solved entity placing problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lexzor
Veteran Member
Join Date: Nov 2020
Old 01-30-2024 , 09:30   entity placing problem
Reply With Quote #1

Hello

I'm trying to create a plugin that give possibility to place some sprites on walls and saving it in a .txt file, but there are few problems:

1. There are 4 sprites: 3 letters and an arrow. After reloading the map, the plugin simply doesn't want to apply the saved angles for the entity: https://imgur.com/a/PEOSk3r. First image it's how should be placed and the second it's how actually it's placed (first photo is taken in edit mode after i save the entity in the txt file and the second it's the loaded entity).

.TXT FILE (the entities shown in imgur link are the first 2):

Code:
;Entities for map de_dust2
"0" "-935.155578" "-863.218750" "175.680587" "0.000000" "270.000000" "0.000000" "0.200000"
"3" "-909.391418" "-863.218750" "175.246856" "0.000000" "270.000000" "90.000000" "0.200000"
Code (reading and creating the entity)

PHP Code:
    while(fgets(iFileszDatacharsmax(szData)))
    {
        if(
szData[0] == ';' || szData[0] == EOS)
        {
            continue
        }

        if(
parse(szData,
        
szEntityIDcharsmax(szEntityID),
        
szEntityOrigin[0], charsmax(szEntityOrigin[]), szEntityOrigin[1], charsmax(szEntityOrigin[]), szEntityOrigin[2], charsmax(szEntityOrigin[]),
        
szEntityAngles[0], charsmax(szEntityAngles[]), szEntityAngles[1], charsmax(szEntityAngles[]), szEntityAngles[2], charsmax(szEntityAngles[]),
        
szScalecharsmax(szScale)) != iParseContent)
        {
            
log_amx("Entity with id %i has not been loaded due to incorrect parameters info"iCount)
            continue
        }

        
iEnt rg_create_entity("env_sprite")

        if(!
is_entity(iEnt))
        {
            
log_amx("Entity with id %i failed to be created"iCount)
            continue
        }

        
iEntityID str_to_num(szEntityID)
        
fEntityOrigin[0] = str_to_float(szEntityOrigin[0])
        
fEntityOrigin[1] = str_to_float(szEntityOrigin[1])
        
fEntityOrigin[2] = str_to_float(szEntityOrigin[2])

        
fEntityAngles[0] = str_to_float(szEntityAngles[0])
        
fEntityAngles[1] = str_to_float(szEntityAngles[1])
        
fEntityAngles[2] = str_to_float(szEntityAngles[2])

        
fScale str_to_float(szScale)

        
set_entvar(iEntvar_classnameENTITY_CLASSNAME)
        
set_entvar(iEntvar_movetypeMOVETYPE_NONE)
        
set_entvar(iEntvar_solidSOLID_NOT)
        
set_entvar(iEntvar_modelENTITIES[iEntityID][PATH])
        
set_entvar(iEntvar_modelindexArrayGetCell(g_aSpritesCacheIDiEntityID))
        
set_entvar(iEntvar_originfEntityOrigin)
        
set_entvar(iEntvar_scalefScale)
        
set_entvar(iEntENTITY_LIST_IDiEntityID)
        
set_entvar(iEntvar_rendermodekRenderTransAdd)
        
set_entvar(iEntvar_renderamt255.0)
        
set_entvar(iEntvar_anglesfEntityAngles)

        
server_print("[%i] Created entity with id %i. Position: %f %f %f. Angles %f %f %f"iCountiEntityIDfEntityOrigin[0], fEntityOrigin[1], fEntityOrigin[2], fEntityAngles[0], fEntityAngles[1], fEntityAngles[2])
        
        
dllfunc(DLLFunc_SpawniEnt)

        
iCount++
    } 
The debug message i receive after the entity is created:

Code:
[0] Created entity with id 0. Position: -935.155578 -863.218750 175.680587. Angles 0.000000 270.000000 0.000000
[1] Created entity with id 3. Position: -909.391418 -863.218750 175.246856. Angles 0.000000 270.000000 90.000000
2. After saving several entities on the same map (~9 entities), the entity simply dissappear. I couldn't find any pattern for this. I just observed this happen often when i'm crossing a door: https://imgur.com/a/lH55SdQ

Code (creating entity and it's think)

PHP Code:
//Entity think
public EntityThink(const iEnt)
{
    static 
iOwner
    iOwner 
get_entvar(iEntvar_owner)
    
    if(!
is_user_connected(iOwner))
    {
        
KillEntity(iEnt)
        
log_amx("Entity %i removed because the owner with index %i is not online anymore"iEntiOwner)
        return
    }

    static 
Float:fAimOriginVector[3]
    static 
Float:fPlayerOrigin[3]
    static 
Float:fAimVector[3]
    static 
Float:fNormalVector[3]
    static 
Float:fAnglesVector[3]
    static 
Float:fFraction

    get_entvar
(iOwnervar_v_anglefAimVector)
    
angle_vector(fAimVectorANGLEVECTOR_FORWARDfAimVector)

    
get_entvar(iOwnervar_originfPlayerOrigin)

    
fAimVector[0] = fAimVector[0] * 9999.0 fPlayerOrigin[0]
    
fAimVector[1] = fAimVector[1] * 9999.0 fPlayerOrigin[1]
    
fAimVector[2] = fAimVector[2] * 9999.0 fPlayerOrigin[2]

    static 
iTr
    iTr 
create_tr2()
    
engfunc(EngFunc_TraceLinefPlayerOriginfAimVectorIGNORE_MONSTERS IGNORE_MISSILE0iTr)
    
get_tr2(iTrTR_vecEndPosfAimOriginVector)
    
get_tr2(iTrTR_vecPlaneNormalfNormalVector)
    
get_tr2(iTrTR_flFractionfFraction)
    
free_tr2(iTr)

    if(
fFraction == 0.0)
        return

    
fNormalVector[0] *= -1.0
    fNormalVector
[1] *= -1.0

    vector_to_angle
(fNormalVectorfAnglesVector)

    
fAnglesVector[0] = fAnglesVector[0], get_entvar(iEntENTITY_X_AXIS_ROTATION)
    
fAnglesVector[1] = fAnglesVector[1], get_entvar(iEntENTITY_Y_AXIS_ROTATION)
    
fAnglesVector[2] = fAnglesVector[2], get_entvar(iEntENTITY_Z_AXIS_ROTATION)
    
set_entvar(iEntvar_anglesfAnglesVector)

    
fAimOriginVector[0] -= fNormalVector[0] * 0.75
    fAimOriginVector
[1] -= fNormalVector[1] * 0.75
    fAimOriginVector
[2] += fNormalVector[2] * 0.75
    set_entvar
(iEntvar_originfAimOriginVector)

    
client_print(iOwnerprint_chat"Entity origin X:%f Y:%f Z:%f"fAimOriginVector[0], fAimOriginVector[1], fAimOriginVector[2])
    
client_print(iOwnerprint_chat"Entity angles X:%f Y:%f Z:%f"fAnglesVector[0], fAnglesVector[1], fAnglesVector[2])

    
set_entvar(iEntvar_nextthink0.01)

    return
}

//Creating entity
@MainMenuCallBack(const id, const menu, const item)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return
    }

    new 
iEnt rg_create_entity("env_sprite")

    if(!
is_entity(iEnt))
    {
        
client_print_color(idprint_team_default"%s Entity couldn't be created"CHAT_TAG)
        return
    }

    new 
Float:fOrigin[3]
    
get_entvar(idvar_originfOrigin)

    
set_entvar(iEntvar_classnameENTITY_CLASSNAME)
    
set_entvar(iEntvar_movetypeMOVETYPE_NONE)
    
set_entvar(iEntvar_solidSOLID_NOT)
    
set_entvar(iEntvar_modelENTITIES[item][PATH])
    
set_entvar(iEntvar_modelindexArrayGetCell(g_aSpritesCacheIDitem))
    
set_entvar(iEntvar_originfOrigin)
    
set_entvar(iEntvar_scaleDEFAULT_SIZE_AMOUNT)
    
set_entvar(iEntvar_ownerid)
    
set_entvar(iEntENTITY_LIST_IDitem)
    
set_entvar(iEntvar_rendermodekRenderTransAdd)
    
set_entvar(iEntvar_renderamt255.0)

    
client_print_color(idprint_team_default"%s Entity created"CHAT_TAG)

    
g_eUserData[id][CURRENT_ENTITY] = iEnt

    SetThink
(iEnt"EntityThink")

    
set_entvar(iEntvar_nextthink0.01)

    
OptionMenu(id)

    return


Thanks in advance for response

Last edited by lexzor; 01-30-2024 at 10:28.
lexzor is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 01-30-2024 , 10:28   Re: entity placing problem
Reply With Quote #2

Using EngFunc_SetOrigin instead of var_origin, adjusting origin after all others var_* options and changing var_movetype to MOVETYPE_NOCLIP actually solved the situation.
lexzor 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 16:28.


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