AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Better description of some natives (https://forums.alliedmods.net/showthread.php?t=295782)

Depresie 04-04-2017 12:51

[HELP] Better description of some natives
 
get_user_weapons(iPlayer, iWeapons, iNum)
get_weaponid(szWeaponName)

What these two actually retrieve ? the weapon index ( CSW_* ) or the entity index ?

edon1337 04-04-2017 14:03

Re: [HELP] Better description of some natives
 
Code:
 /* Returns all carried weapons as bit sum. Gets  *  also theirs indexes.  * Note that num is incremental - if you pass 0, you get  *  32 weapons towards the total.  Afterwards, num will  *  will contain the number of weapons retrieved.  * However, subsequent calls to get_user_weapons() will  *  return the next batch of weapons, in case the mod  *  supports more than 32 weapons.  * This means to call get_user_weapons() on the same  *  inputs twice, you must reset num to 0 to get the  *  original output again.  */ native get_user_weapons(index,weapons[32],&num);

Code:
/**   * Returns the weapon id, otherwise 0 when no id found.  * The weapon name is case sensitive, and has the weapon_* form.  */ native get_weaponid(const name[]);

get_user_weapons returns every weapon player owns as bitsum (1<<CSW_KNIFE) and get_weaponid returns the weapon ID (CSW_KNIFE)

Depresie 04-05-2017 08:15

Re: [HELP] Better description of some natives
 
Any idea how you write this without a stock ?

PHP Code:

public function(index)
{
      new 
iWeaponEntity fm_find_ent_by_owner(entityszclassnameowner)
}

stock fm_find_ent_by_owner(entity, const classname[], owner)
{
    while ((
entity engfunc(EngFunc_FindEntityByStringentity"classname"classname)) && pev(entitypev_owner) != owner) { /* keep looping */ }
    return 
entity;


Something like

PHP Code:

public function(index)
{
    new 
iWeaponEntity ???
    ???
    ???
    


And could someone explain to me better how it works ?

klippy 04-05-2017 08:25

Re: [HELP] Better description of some natives
 
What exactly are you trying to do? I don't see anything wrong with that fm_find_ent_by_owner() function you provided.

Natsheh 04-05-2017 08:33

Re: [HELP] Better description of some natives
 
Quote:

Originally Posted by Depresie (Post 2509531)
Any idea how you write this without a stock ?

PHP Code:

public function(index)
{
      new 
iWeaponEntity fm_find_ent_by_owner(entityszclassnameowner)
}

stock fm_find_ent_by_owner(entity, const classname[], owner)
{
    while ((
entity engfunc(EngFunc_FindEntityByStringentity"classname"classname)) && pev(entitypev_owner) != owner) { /* keep looping */ }
    return 
entity;


Something like

PHP Code:

public function(index)
{
    new 
iWeaponEntity ???
    ???
    ???
    


And could someone explain to me better how it works ?


No 💡

Depresie 04-05-2017 08:40

Re: [HELP] Better description of some natives
 
Eh, missed some brackets/what ever initially, figured it out, mostly..

Sorry for newbie questions, i have a hobby lately of learning how every line of code works

Here is what i came up with so far, if anyone has any idea how to make it more compact for readability, i'm all ears..

PHP Code:

new iWeaponEntityID = -1

while((iWeaponEntityID engfunc(EngFunc_FindEntityByStringiWeaponEntityID"classname"szWeaponName)) && pev(iWeaponEntityIDpev_owner) != iPlayer)
{
      
// Keep Looping until we meet the conditions above



Arkshine 04-05-2017 09:11

Re: [HELP] Better description of some natives
 
What's wrong with using find_ent_by_owner?

fysiks 04-05-2017 09:20

Re: [HELP] Better description of some natives
 
Quote:

Originally Posted by Depresie (Post 2509531)
Any idea how you write this without a stock ?

PHP Code:

public function(index)
{
      new 
iWeaponEntity fm_find_ent_by_owner(entityszclassnameowner)
}

stock fm_find_ent_by_owner(entity, const classname[], owner)
{
    while ((
entity engfunc(EngFunc_FindEntityByStringentity"classname"classname)) && pev(entitypev_owner) != owner) { /* keep looping */ }
    return 
entity;



Easy. Just move the code from the stock into your plugin. Done. OR, just use the stock (this is the better idea).

Depresie 04-05-2017 09:53

Re: [HELP] Better description of some natives
 
I wanted to make it more compact, without using a stock.. mainly because i want to learn more and also because i'm working on a big project which i plan to make in on single file, so making things more compact/simple would be better ( ex, no 100 function communication )

I also have this problem while coding, called symmetry obsession, it's like a cancer, haha

klippy 04-05-2017 10:23

Re: [HELP] Better description of some natives
 
But functions are good for reusability. There's never rnough functions, splitting logic is good. Functions actually make code simpler.


All times are GMT -4. The time now is 17:54.

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