[INC] ESF UTIL

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

[INC] ESF UTIL

Post by Archive-Poster »

ESF UTIL

I made a update for viewtopic.php?t=66
I added more stocks yay !!
More info about stocks, inside of INC file ~


This include contain :

- ESF Weapon ID's
- And some usefull stocks

The stocks are:

esf_get_ki( index );
esf_set_ki( index, 1000 );
esf_get_powerlevel( index );
esf_set_powerlevel( index, 940000 );
esf_get_acpl( index );
esf_set_acpl( index, 940000 );
esf_get_maxhealth( index );
esf_set_maxhealth( index, 1000 );
esf_get_player_class( index );
esf_set_speed( index, speed );
esf_get_speed( index );
esf_set_swoopspeed( index, speed );
esf_get_swoopspeed( index );
esf_get_fly( index );
esf_get_turbo( index );
esf_get_powerup( index );
esf_get_swooping( index );
esf_get_attack_charge( index );
esf_get_advancedmelee( index );
esf_get_block( index );
esf_get_throw( index );
esf_get_user_deaths( index );
esf_get_team( index );



The weapons ID's are:

ESFW_NONE
ESFW_MELEE
ESFW_SWORD
ESFW_KIBLAST
ESFW_GENERICBEAM
ESFW_GALLITGUN
ESFW_KAMEHAMEHA
ESFW_DESTRUCTODISC
ESFW_SOLARFLARE
ESFW_EYELASER
ESFW_FRIEZADISC
ESFW_SPECIALBEAMCANNON
ESFW_SPIRITBOMB
ESFW_BIGBANG
ESFW_FINGERLASER
ESFW_FINALFLASH
ESFW_MASENKO
ESFW_DEATHBALL
ESFW_BURNINGATTACK
ESFW_SCATTERBEAM
ESFW_CANDY
ESFW_SCATTERSHOT
ESFW_POWERBEAM
ESFW_MOUTHBLAST
ESFW_FINISHINGBUSTER
ESFW_SENSU
ESFW_DRAGONBALL
ESFW_BODYPART
ESFW_SHIELDATTACK
ESFW_REGENERATION
ESFW_RENZOKU
ESFW_KAMETORPEDO
ESFW_TELEKINESIS
ESFW_FLAMETHROWER

Added ESF Weapon Names in /* */:

Code: Select all

/*
"weapon_melee"            
"weapon_sword"            
"weapon_kiblast"        
"weapon_genericbeam"         
"weapon_gallitgun"        
"weapon_kamehameha"        
"weapon_destructodisc"        
"weapon_solarflare"        
"weapon_eyelaser"    
"weapon_friezadisc"        
"weapon_specialbeamcannon"    
"weapon_spiritbomb"        
"weapon_bigbang"        
"weapon_fingerlaser"        
"weapon_finalflash"        
"weapon_masenko"        
"weapon_deathball"        
"weapon_burningattack"        
"weapon_scatterbeam"            
"weapon_candy"            
"weapon_scattershot"        
"weapon_powerbeam"        
"weapon_mouthblast"        
"weapon_finishingbuster"    
"weapon_sensu"            
"weapon_dragonball"        
"weapon_bodypart"    
"weapon_shieldattack"        
"weapon_regeneration"        
"weapon_renzoku"        
"weapon_kametorpedo"        
"weapon_telekinesis"        
"weapon_flamethrower"
*/ 
Attachments
esf_util.inc.zip
(2.84 KiB) Downloaded 27 times
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: [INC] ESF UTIL

Post by Archive-Poster »

Code: Select all

/***************************************
|                        |
|   Set KI to a player                   |
|   Note: if you set KI over 1000,      |
|   the KI box will have a bigger width |
|   How to use: esf_set_ki( id , 250 )  |
|                    |
****************************************/
stock esf_set_ki( index, value )
{
    set_pev( id, pev_fuser4, float( value ) );
}



/*******************************************
|                            |
|     Set PowerLevel to a player            |
|     How to use:                     |
|     esf_set_powerlevel( id , 60.000.000 ) |
|                          |
********************************************/
stock esf_set_powerlevel( index, thp ) 
{
    set_pdata_int( index, 460, thp );
}



/****************************************
|                         |
|   Return PowerLevel from a player     |
|   How to use: esf_get_powerlevel( id ) |
|                     |
*****************************************/
stock esf_get_powerlevel( index )
{
    return get_pdata_int( index, 460 );
}



/*****************************************
|                          |
|   Return ActualPowerLevel from a player |
|   How to use: esf_get_acpl( id )        |
|                      |
******************************************/
stock esf_get_acpl( index )
{
    return get_pdata_int( index, 463 );
}

/***********************************************
|                                |
|   Get the player model                |
|   How to use: esf_get_model( id, model, len )    |
|                            |
************************************************/
stock esf_get_model( index, model[], len )
{
    engfunc( EngFunc_InfoKeyValue, engfunc( EngFunc_GetInfoKeyBuffer, index ), "model", model, len );
}
Use a macro for all of these.
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: [INC] ESF UTIL

Post by Archive-Poster »

Good suggestion

Code: Select all

stock esf_set_ki( index, value )
{
    set_pev( id, pev_fuser4, float( value ) );
} 
Here is an example on how to do a macro:

Code: Select all

#define esf_set_ki(%1,%2) set_pev( %1, pev_fuser4, float( %2 ) ) 
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: [INC] ESF UTIL

Post by Archive-Poster »

About ESF class. Why you use code from ECX? Why not just..:

Code: Select all

enum
{
        CLASS_NONE,
 
        CLASS_BUU,
        CLASS_GOKU,
        CLASS_GOHAN,
        CLASS_KRILLIN,
        CLASS_FRIEZA,
        CLASS_PICCOLO,
        CLASS_TRUNKS,
        CLASS_VEGETA,
        CLASS_CELL
};
 
#define esf_get_player_class(%1) return pev(%1, pev_playerclass);
 
/*
// Usage
// If/else
new iClass = esf_get_player_class(iClient);
 
if (iClass == CLASS_NONE)
{
        // Player is spectator/unassigned
}
else if (iClass == CLASS_VEGETA)
{
        // Player is Vegeta
}
 
// Switch
switch (esf_get_player_class(iClient))
{
        case CLASS_NONE: return;
        case CLASS_GOKU, CLASS_GOHAN, CLASS_TRUNKS, CLASS_VEGETA:
        {
                // Player is a saiyan
        }
 
        default:
        {
                // Player is not a saiyan
        }
}
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: [INC] ESF UTIL

Post by Archive-Poster »

get_user_team() already works, I just want it to return 1 for Good, 2 for Evil, or 0/-1 for FFA. get_user_team() only returns 9 for the team ID.

Code: Select all

stock esf_get_team(id)
{
    new szTeamName[6]
    get_user_team(id, szTeamName, 5)

    if (equal(szTeamName, "Good"))
        return 1

    else if (equal(szTeamName, "Evil"))
        return 2

    else
        return 0
}
Also, use stocks instead of macros. With a macro, a new stack allocation is made for each use of the macro, cluttering up DAT and using precious resources.
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: [INC] ESF UTIL

Post by Archive-Poster »

Macros are replaced at compile, so there is no reason not to use them (at least from what I understand of it).
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: [INC] ESF UTIL

Post by Archive-Poster »

There isn't "each use of macro". A macro is a rule for text replacement applied before compiling. A way of avoid a function call.
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: [INC] ESF UTIL

Post by Archive-Poster »

Will get_user_team always return 9? If it does not and returns unique numbers you could just remap it - returning 1 if get_user_team is 9, 2 if it is 8 (or whatever).

If this does not apply I would use this instead of full string comparison (assuming that those are unique):

Code: Select all

stock esf_get_team(id) 
{     
    new szTeamName[2]     
    get_user_team(id, szTeamName, 1)      

if( szTeamName[0] == 'G' )         
    return 1      

else if( szTeamName[0] == 'E' )        
    return 2      

else        
    return 0 
} 
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: [INC] ESF UTIL

Post by Archive-Poster »

Macros are replaced at compile, so there is no reason not to use them (at least from what I understand of it).
Yeah, but look at this quote from dev log:
We noticed that the DAT section is not optimized. You can repeat a string a 800 times and the DAT section will have an entry for each repetition. The solution?

Code: Select all

//BAD
#define COMMON_STRING   "Gaben"
//GOOD
new COMMON_STRING[] = "Gaben"
This way, DAT will only have one reference. Furthermore, it might even be faster because in the case of non-const the compiler won’t have to copy it into the heap first. In many cases you know it will never be modified, and the native declaration simply forgot a ‘const’ keyword.
Another example:

Code: Select all

//BAD
stock GetWeaponName(id, name[], max)
{
   if (id==0)
      copy(name, max, "weapon_none")
   else if (id==1)
      copy(name, max, "weapon_gaben")
   //....
}
//GOOD
new g_WeaponNames[] = {
     "weapon_none", //0
    "weapon_gaben", //1
}
A lookup table is near-instantaneous execution. The compiler simply has to add an integer to a base memory offset. Calling a function is expensive — branch prediction, cache misses, more instructions can add up very quickly. If you’re using the function very often, it’s a good idea to take the time to make these trivial and worth-while optimizations. You can do lookup tables in Small for anything which inputs an integer and outputs any other data type, as long as the set of inputs has fixed limits. It is okay to build the lookup table at runtime, as long as you don’t need to do it often (or building it often outweighs the cost of computing entries totally dynamically).
I was shocked at how unoptimized the Pawn compiler is. :(
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: [INC] ESF UTIL

Post by Archive-Poster »

I thought it's for strings only. So I shall not use const even if I'm not planing changing my variable?
Is it? Beats me. I'd still avoid macros anyway.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest