AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   origin, angles and touch optimisation (https://forums.alliedmods.net/showthread.php?t=114008)

Jack86 01-01-2010 08:19

origin, angles and touch optimisation
 
I would like to know why commented part doesnt work, and why uncommented works, cause i see no reason not to work.

PHP Code:

        // SET ORIGIN AND ANGLES
        
new randspawn random_num (0g_TotalSpawns 1)
        
//new Float:origin[3] = {g_SpawnVecs[randspawn][0], g_SpawnVecs[randspawn][1], g_SpawnVecs[randspawn][2]}
        //new Float:angles[3] = {g_SpawnAngles[randspawn][0], g_SpawnAngles[randspawn][1], g_SpawnAngles[randspawn][2]}
        
new Float:origin[3]
        new 
Float:angles[3]
        
origin g_SpawnVecs[randspawn]
        
angles g_SpawnAngles[randspawn]
        
//CREATE ENTITY
        
create_ent(origin,angles


xPaw 01-01-2010 08:21

Re: origin and angles
 
try

new Float:origin[3] = g_SpawnVecs[randspawn];

Arkshine 01-01-2010 08:23

Re: origin and angles
 
Commented : Because you need to provide a constant value. How the compiler could know the value at the compilation ? Not possible that's why you can't.

Uncommented : Because origin and g_SpawnVecs have the same size and you are allowed to do that.

Jack86 01-01-2010 09:29

Re: origin and angles
 
Ok, tnx. I have 2 more q, is sound emitted with client_cmd( id , spk...) heard by everyone or just that player, and is it ok to remove is_valid_ent check if i change

PHP Code:

public pfn_touch(ptr,ptd) {
    if(!
is_valid_ent(ptd)) { // invalid toucher
        
return PLUGIN_CONTINUE;
    }
    
    
// now check for more invalid entities or players
    
if(!is_valid_ent(ptr) || !is_valid_ent(ptd) || !is_user_connected(ptd)) {
        return 
PLUGIN_CONTINUE;
    }

    new 
classname[32];
    
entity_get_string(ptr,EV_SZ_classname,classname,31); // get name of touched
    
    
if(equal(classname,g_ent_classname)) {
        
// ASSIGN OWNER TO QUAD
        
g_quad_owner ptd 
        
        
// REMOVE ENTRY
        
remove_entity(ptr);
        
        
// enable quad for user
        
quad_enable(ptd);
        return 
PLUGIN_CONTINUE;
    }    
    return 
PLUGIN_CONTINUE;


with

PHP Code:

register_touch("dm_quad","player","touched")

public 
touched(quad,id)
{
    if(!
is_valid_ent(quad) || !is_valid_ent(id) || !is_user_connected(id))
    {
        return 
PLUGIN_CONTINUE;
    }
    
// ASSIGN OWNER TO QUAD
    
g_quad_owner id 
        
    
// REMOVE ENTRY
    
remove_entity(quad);
        
    
// enable quad for user
    
quad_enable(id);
    return 
PLUGIN_CONTINUE;




xPaw 01-01-2010 09:41

Re: origin, angles and touch optimisation
 
you can remove is_valid_ent(id) check

Arkshine 01-01-2010 10:08

Re: origin, angles and touch optimisation
 
Quote:

Ok, tnx. I have 2 more q, is sound emitted with client_cmd( id , spk...) heard by everyone or just that player, and is it ok to remove is_valid_ent check if i change
Just by that player, since you provide his index.

Better to use register_touch() when you can ( called only on the classname provided, and the check is done internally so more efficient ). About the check, the entity should be always checked (quad). Id should be checked ( or not ) depending your need. (alive, connected, etc. )

Jack86 01-01-2010 10:37

Re: origin, angles and touch optimisation
 
Tnx once again.

Jack86 01-02-2010 22:23

Re: origin, angles and touch optimisation
 
What would be better to do if i have plugin already done in fakemeta, to handle touch in fakemeta with check

PHP Code:

new classname[32]
    
entity_get_string(ptr,EV_SZ_classname,classname,31
if ( 
equal(classnameclassname2) ) 

or to include engine just for register_touch("customclass1","customslass2"
because i dont see fakemeta function for register_touch

Arkshine 01-03-2010 04:44

Re: origin, angles and touch optimisation
 
Think, do you think that a forward called for all entities and checking classname manually is more efficient than a forward called only for the entites with the classname provided and so the check is done internally ?

Jack86 01-03-2010 06:29

Re: origin, angles and touch optimisation
 
Yea, i thought so too, but i dont know how much another included module raises resource consumption so i asked :D


All times are GMT -4. The time now is 04:16.

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