AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Entity won't spawn (https://forums.alliedmods.net/showthread.php?t=240270)

Backstabnoob 05-11-2014 17:28

Entity won't spawn
 
I use precache control by joaquimandrade: https://forums.alliedmods.net/showpo...3&postcount=41 to block some useless precached files.

For some reason this code causes problems:

PHP Code:

new iEntity create_entity"info_target" )
entity_set_stringiEntityEV_SZ_classname"tossed_knife" )
        
new 
FloatfVecAngles]
entity_get_vectoridEV_VEC_anglesfVecAngles )
        
new 
FloatfVAngles], FloatfVecVelocity]
entity_get_vectoridEV_VEC_v_anglefVAngles )
        
        
engfuncEngFunc_MakeVectorsfVAngles )
global_getglb_v_forwardfVAngles )
        
fVecVelocity[0] = fVAngles] * 350
fVecVelocity
[1] = fVAngles] * 350
fVecVelocity
[2] = fVAngles] * 350
        
new FloatfVecOrigin]
entity_get_vectoridEV_VEC_originfVecOrigin )
entity_set_originiEntityfVecOrigin )
entity_set_vectoriEntityEV_VEC_velocityfVecVelocity )
        
entity_set_stringiEntityEV_SZ_modelDEFAULT_WMODEL )
entity_set_intiEntityEV_INT_iuser1iCurrentKnife )

DispatchSpawniEntity 

It tries to precache c4 files (DispatchSpawn to be exact), which causes crash because they're unprecached. If I precache them, the entity doesn't get spawned anyway or at least I can't see it.

Am I doing anything wrong? That code is mainly by ot_207, I'm trying to create an entity for my knife API but it won't work :/

DEFAULT_WMODEL is models/w_backpack.mdl and it's precached.

meTaLiCroSS 05-11-2014 21:07

Re: Entity won't spawn
 
Didn't understand well, but there's something that I can't understand.

Why are you Spawning "info_target" entities? That's totally useless, mod just does this

PHP Code:

void CPointEntity::Spawn(void// code from CS originally
{
  
pev->solid 0;


So skip that thing from your code

Backstabnoob 05-12-2014 06:57

Re: Entity won't spawn
 
Why doesn't it appear at all then? If I comment out DispatchSpawn, it just does nothing, the entity is never created or at least visible.

Although if I do leave DispatchSpawn there it tries to precache c4 models and sounds and because I unprecached them it crashes the server. Are you sure it does ONLY that?

Arkshine 05-12-2014 07:15

Re: Entity won't spawn
 
You should use entity_set_model or Engfunc_SetModel to set a model.

Backstabnoob 05-12-2014 07:26

Re: Entity won't spawn
 
Should I leave out DispatchSpawn then? I personally never used it, but ot_207 did in his nade API and it works fine so no idea what I'm doing wrong.

Edit: Thanks, it seems to work (even without DispatchSpawn) although it just lies where I spawned it instead of falling to the ground due to the velocity (I spawn the entity with the "drop" command and it's just midair so no gravity is applied, maybe because it has no movetype defined?)

Edit2: Workaround:
PHP Code:

entity_set_stringiEntityEV_SZ_classname"tossed_knife" )
/*
new Float: fVecAngles[ 3 ]
entity_get_vector( id, EV_VEC_angles, fVecAngles )
        
new Float: fVAngles[ 3 ], Float: fVecVelocity[ 3 ]
entity_get_vector( id, EV_VEC_v_angle, fVAngles )
        
engfunc( EngFunc_MakeVectors, fVAngles )
global_get( glb_v_forward, fVAngles )
*/
        
new FloatfVecVelocity]
velocity_by_aimid350fVecVelocity )
        
new 
FloatfVecOrigin]
entity_get_vectoridEV_VEC_originfVecOrigin )
entity_set_originiEntityfVecOrigin )
entity_set_vectoriEntityEV_VEC_velocityfVecVelocity )
        
entity_set_intiEntityEV_INT_movetypeMOVETYPE_TOSS 

Not the best option since it's not like in original CS (i.e. if you aim down you will throw it under yourself) but at least it works now. Thanks for the help Arkshine

meTaLiCroSS 05-12-2014 20:37

Re: Entity won't spawn
 
If you want to imitate original weapon drop velocity, just use this imitation:

PHP Code:

                new Float:vecOrigin[3], Float:vecVelocity[3], vecAngles[3], Float:vecForward[3]

                
pev(iIdpev_originvecOrigin)
                
pev(iIdpev_anglesvecAngles)
                
                
angle_vector(vecAnglesANGLEVECTOR_FORWARDvecForward)
                        
                
vecOrigin[0] += (vecForward[0] * 10)
                
vecOrigin[1] += (vecForward[1] * 10)
                
vecOrigin[2] += (vecForward[2] * 10)
                    
                
vecAngles[0] = 0.0
                vecAngles
[2] = 0.0
                    
                vecVelocity
[0] = (vecForward[0] * 400)
                
vecVelocity[1] = (vecForward[1] * 400)
                
vecVelocity[2] = (vecForward[2] * 400)
                
                
entity_set_origin(iEntityvecOrigin)
                
set_pev(iEntitypev_anglesvecAngles)
                
set_pev(iEntitypev_velocityvecVelocity

:D


All times are GMT -4. The time now is 09:34.

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