Raised This Month: $32 Target: $400
 8% 

Set armor and helmet using only engine


Post New Thread Reply   
 
Thread Tools Display Modes
CryWolf
Veteran Member
Join Date: Jul 2008
Location: Romania
Old 04-05-2021 , 14:16   Re: Set armor and helmet using only engine
Reply With Quote #11

I don't see why we need so many optimizations, since we are not using Pentium II CPU-s anymore, and HLDS is an old engine, will work on P2 as well.

I did once, moved the biohazard 1.93 mod to a Metamod module, and wasn't to much optimization, and a completly waste of time, and was well coded.
__________________
I dont walk trough this world with fear in my heart.
www.dark-arena.com L4D, CS1.6, CZ Servers
CryWolf is offline
Send a message via MSN to CryWolf Send a message via Yahoo to CryWolf
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-05-2021 , 15:08   Re: Set armor and helmet using only engine
Reply With Quote #12

Quote:
Originally Posted by CryWolf View Post
I don't see why we need so many optimizations, since we are not using Pentium II CPU-s anymore, and HLDS is an old engine, will work on P2 as well.
These sort of "optimizations" wouldn't even make a difference in a Pentium II to be honest.
__________________

Last edited by HamletEagle; 04-05-2021 at 15:08.
HamletEagle is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-05-2021 , 23:45   Re: Set armor and helmet using only engine
Reply With Quote #13

Are you accounting for everything that cs_set_user_armor() does?
PHP Code:
static cell AMX_NATIVE_CALL cs_set_user_armor(AMX *amxcell *params// cs_set_user_armor(index, armorvalue, CsArmorType:armortype); = 3 params
{
    
// Set armor and set what type and send a message to client...
    // params[1] = user index
    // params[2] = armor value
    // params[3] = armor type (no armor/vest/vest+helmet)

    
CHECK_PLAYER(params[1]);

    
// Make into edict pointer
    
edict_t *pPlayer MF_GetPlayerEdict(params[1]);

    
// Set armor value
    
pPlayer->v.armorvalue params[2];

    
// Set armor type
    
*((int *)pPlayer->pvPrivateData OFFSET_ARMORTYPE) = params[3];
    
    if (
params[3] == CS_ARMOR_KEVLAR || params[3] == CS_ARMOR_ASSAULTSUIT)
    {
        
// And send appropriate message
        
MESSAGE_BEGIN(MSG_ONEGET_USER_MSG_ID(PLID"ArmorType"NULL), NULLpPlayer);
        
WRITE_BYTE(params[3] == CS_ARMOR_ASSAULTSUIT 0);
        
MESSAGE_END();
    }

    return 
1;

__________________
Bugsy is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 04-11-2021 , 08:11   Re: Set armor and helmet using only engine
Reply With Quote #14

Quote:
Originally Posted by Bugsy View Post
Are you accounting for everything that cs_set_user_armor() does?
Which do you think is better compared to entity_set_float

PHP Code:
static cell AMX_NATIVE_CALL entity_set_float(AMX *amxcell *params)
{
    
int iEnt params[1];
    
int idx params[2];
    
REAL fVal amx_ctof(params[3]);

    
CHECK_ENTITY_SIMPLE(iEnt);

    
edict_t *pEnt TypeConversion.id_to_edict(iEnt);

    switch (
idx)
    {
        case 
impacttime:
            
pEnt->v.impacttime fVal;
            break;
        case 
starttime:
            
pEnt->v.starttime fVal;
            break;
        case 
idealpitch:
            
pEnt->v.idealpitch fVal;
            break;
        case 
pitch_speed:
            
pEnt->v.pitch_speed fVal;
            break;
        case 
ideal_yaw:
            
pEnt->v.ideal_yaw fVal;
            break;
        case 
yaw_speed:
            
pEnt->v.yaw_speed fVal;
            break;
        case 
ltime:
            
pEnt->v.ltime fVal;
            break;
        case 
nextthink:
            
pEnt->v.nextthink fVal;
            break;
        case 
gravity:
            
pEnt->v.gravity fVal;
            break;
        case 
friction:
            
pEnt->v.friction fVal;
            break;
        case 
frame:
            
pEnt->v.frame fVal;
            break;
        case 
animtime:
            
pEnt->v.animtime fVal;
            break;
        case 
framerate:
            
pEnt->v.framerate fVal;
            break;
        case 
health:
            
pEnt->v.health fVal;
            break;
        case 
frags:
            
pEnt->v.frags fVal;
            break;
        case 
takedamage:
            
pEnt->v.takedamage fVal;
            break;
        case 
max_health:
            
pEnt->v.max_health fVal;
            break;
        case 
teleport_time:
            
pEnt->v.teleport_time fVal;
            break;
        case 
armortype:
            
pEnt->v.armortype fVal;
            break;
        case 
armorvalue:
            
pEnt->v.armorvalue fVal;
            break;
        case 
dmg_take:
            
pEnt->v.dmg_take fVal;
            break;
        case 
dmg_save:
            
pEnt->v.dmg_save fVal;
            break;
        case 
dmg:
            
pEnt->v.dmg fVal;
            break;
        case 
dmgtime:
            
pEnt->v.dmgtime fVal;
            break;
        case 
speed:
            
pEnt->v.speed fVal;
            break;
        case 
air_finished:
            
pEnt->v.air_finished fVal;
            break;
        case 
pain_finished:
            
pEnt->v.pain_finished fVal;
            break;
        case 
radsuit_finished:
            
pEnt->v.radsuit_finished fVal;
            break;
        case 
scale:
            
pEnt->v.scale fVal;
            break;
        case 
renderamt:
            
pEnt->v.renderamt fVal;
            break;
        case 
maxspeed:
            
pEnt->v.maxspeed fVal;
            break;
        case 
fov:
            
pEnt->v.fov fVal;
            break;
        case 
flFallVelocity:
            
pEnt->v.flFallVelocity fVal;
            break;
        case 
fuser1:
            
pEnt->v.fuser1 fVal;
            break;
        case 
fuser2:
            
pEnt->v.fuser2 fVal;
            break;
        case 
fuser3:
            
pEnt->v.fuser3 fVal;
            break;
        case 
fuser4:
            
pEnt->v.fuser4 fVal;
            break;
        default:
            return 
0;
            break;
    }

    return 
1;

__________________
mlibre is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 04-11-2021 , 10:49   Re: Set armor and helmet using only engine
Reply With Quote #15

There is set_pev from fakemeta and if you're using reapi, set_entvar, but neither is better than the other, they just offer different functions. Which one to use? well, it depends on what you need. You can include as many modules as you want, just avoid fakemeta_util.

Unless this isn't for counter-strike, I don't see reason for replacing cstrike with say, engine. You need to explain what you're trying to do.

Btw, you'll find some tips for optimizing a plugin in this link.
https://wiki.alliedmods.net/Optimizi...d_X_Scripting)
__________________









Last edited by CrazY.; 04-11-2021 at 10:58.
CrazY. is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 04-11-2021 , 16:30   Re: Set armor and helmet using only engine
Reply With Quote #16

Quote:
Originally Posted by CrazY. View Post
just avoid fakemeta_util.
I've heard this many times. So when I need something in fakemeta_util I copy the function I need into my plugin and access it from there. Is this a better way or the same as using fakemeta_util?...
__________________
hellmonja is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 04-12-2021 , 11:27   Re: Set armor and helmet using only engine
Reply With Quote #17

The problem is that some functions make a bunch of calls. Look at fm_give_item for example

Code:
stock fm_give_item(index, const item[]) {     if (!equal(item, "weapon_", 7) && !equal(item, "ammo_", 5) && !equal(item, "item_", 5) && !equal(item, "tf_weapon_", 10))         return 0;     new ent = fm_create_entity(item);     if (!pev_valid(ent))         return 0;     new Float:origin[3];     pev(index, pev_origin, origin);     set_pev(ent, pev_origin, origin);     set_pev(ent, pev_spawnflags, pev(ent, pev_spawnflags) | SF_NORESPAWN);     dllfunc(DLLFunc_Spawn, ent);     new save = pev(ent, pev_solid);     dllfunc(DLLFunc_Touch, ent, index);     if (pev(ent, pev_solid) != save)         return ent;     engfunc(EngFunc_RemoveEntity, ent);     return -1; }

You could simply replace that with fun's give_item, which is just one line

Code:
give_item(id, "weapon_name)

If you look at fun source, you'll notice that it does almost the same amount of calls as fakemeta_util but it's supposed to be faster.

Code:
// native give_item(index, const item[])
static cell AMX_NATIVE_CALL give_item(AMX *amx, cell *params)
{
	enum args { arg_count, arg_index, arg_item };

	CHECK_PLAYER(params[arg_index]);

	auto itemLength = 0;
	const auto item = MF_GetAmxString(amx, params[arg_item], 1, &itemLength);

	if (!itemLength
		||(strncmp(item, "weapon_", 7) != 0
		&& strncmp(item, "ammo_", 5) != 0
		&& strncmp(item, "item_", 5) != 0
		&& strncmp(item, "tf_weapon_", 10) != 0))
	{
		return 0;
	}

	auto pEntity = CREATE_NAMED_ENTITY(ALLOC_STRING(item));

	if (FNullEnt(pEntity))
	{
		MF_LogError(amx, AMX_ERR_NATIVE, "Item \"%s\" failed to create", item);
		return 0;
	}

	const auto pPlayer = TypeConversion.id_to_edict(params[arg_index]);

	pEntity->v.origin = pPlayer->v.origin;
	pEntity->v.spawnflags |= SF_NORESPAWN;

	MDLL_Spawn(pEntity);

	const auto oldSolid = pEntity->v.solid;

	MDLL_Touch(pEntity, pPlayer);

	if (pEntity->v.solid == oldSolid)
	{
		REMOVE_ENTITY(pEntity); // The function did not fail - we're just deleting the item
		return -1;
	}

	return TypeConversion.edict_to_id(pEntity);
}
Avoid when possible, but if you need to use it for some reason, go ahead. If it was that harmful, amxx dev would have already removed it.
__________________









Last edited by CrazY.; 04-12-2021 at 11:32.
CrazY. 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 01:16.


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