Raised This Month: $51 Target: $400
 12% 

[QUESTION]What is the difference betwen these functions


Post New Thread Reply   
 
Thread Tools Display Modes
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-16-2015 , 15:47   Re: [QUESTION]What is the difference betwen these functions
Reply With Quote #31

They don't cause crashes, and packed arrays (for saving memory) have some use in scripting (like in that code, but bit fields would work better anyway). Packed strings are the ones that don't work properly. They won't cause crashes, but you can't use packed strings in AMXX to save memory, as they are not supported by natives. They can't be properly formatted and/or printed.
klippy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-16-2015 , 15:51   Re: [QUESTION]What is the difference betwen these functions
Reply With Quote #32

Quote:
Originally Posted by Bugsy View Post
Unfortunately the AMX-X string natives are not built to use packed strings.
It is not unfortunate actually. UTF-8 requires up to 4 bytes to store certain characters. If using packed strings, you would be limited to ASCII.
__________________

Last edited by fysiks; 08-16-2015 at 15:56.
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-16-2015 , 15:54   Re: [QUESTION]What is the difference betwen these functions
Reply With Quote #33

Quote:
Originally Posted by Depresie View Post
what do you mean by this ?
"Unfortunately the AMX-X string natives are not built to use packed strings"

It could cause server crash? or something? because i encounter server crashes on linux with no error logs running the plugin containing that code, and i couldn't find a solution for several weeks

link here:
https://forums.alliedmods.net/showthread.php?t=270179
No, it means that when you use copy/formatex/format/client_print/get_user_name/get_user_authid etc, it expects strings in the non-packed format because that is how it was programmed.

Assume '1' is a character in a string and you need to store 4 characters, they are stored as listed below for each type:
non-packed: 0001 0001 0001 0001
packed: 1111

The only thing that happens when you use char is it reduces the number of cells that are declared because the compiler thinks you will be using every byte within the cell. So if you did szName[ 32 char ] you are doing the same as szName[ 8 ]. Now if you tried to use get_user_name() with szName, you would only have enough room for 8 characters, not 32.
__________________
Bugsy is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-17-2015 , 17:35   Re: [QUESTION]What is the difference betwen these functions
Reply With Quote #34

oh, i understood
i have another question, what does this do exactly ?
i know it seems quite obvious, but i want to know for sure and i couldnt find anything about it around

set_pev( Snark, pev_enemy, NULL_ENT );

Last edited by Depresie; 08-17-2015 at 17:36.
Depresie is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-17-2015 , 18:38   Re: [QUESTION]What is the difference betwen these functions
Reply With Quote #35

It appears to set your enemy to the null entity (which is probably 0 which is also known as "worldspawn"). As for what pev_enemy actually means, you'd probably have to look at the context of it's usage (assuming it's used in an actual working plugin).
__________________

Last edited by fysiks; 08-17-2015 at 18:40.
fysiks is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 08-18-2015 , 01:47   Re: [QUESTION]What is the difference betwen these functions
Reply With Quote #36

Quote:
Originally Posted by fysiks View Post
It appears to set your enemy to the null entity (which is probably 0 which is also known as "worldspawn"). As for what pev_enemy actually means, you'd probably have to look at the context of it's usage (assuming it's used in an actual working plugin).
I've looked around and it seems to be conected to zombie AI
pev_enemy being the player the monster follows/attacks/whatever
it also seems to be originally from half life AI

so I guess setting it to null means the monster is not attacking anyone

some questions need to be asked in context
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.

Last edited by aron9forever; 08-18-2015 at 01:48.
aron9forever is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-18-2015 , 07:08   Re: [QUESTION]What is the difference betwen these functions
Reply With Quote #37

yes, indeed is a monster who is hunting humans, sorry for placing it out of context, thanks for the answer

i also have one more question about these two functions, why i get run time errors index out of bound ?

what checks i should add in these two cases ( fwd_touch + prethink, and the trace_attack ) to not get run time errors about index out of bounds?

im sorry for posting this in the same thread, but i think it is be better than creating multiple topics for this kind of questions

Code:
public fwd_touch(id, world)
{

    if(!is_user_alive(id))
             return FMRES_IGNORED
        
    if(zp_core_is_zombie(id) && zp_class_assassin_get(id))    
    {
               pev(id, pev_origin, g_wallorigin[id])
    }

return FMRES_IGNORED
}

public fw_PlayerPreThink
{

        if(zp_core_is_zombie(id) && zp_class_assassin_get(id))    
            {
        static Float:gameTime = 0.0, Float:VAngle[3], Float:Forward[3];
        gameTime = get_gametime();
        
        static Float:origin[3]
        pev(id, pev_origin, origin)
        
        if(get_distance_f(origin, g_wallorigin[id]) > 25.0)
            return FMRES_IGNORED  // if not near wall
        }

    return FMRES_IGNORED
}

public fw_TraceAttack(victim, attacker, Float:damage, direction[3], traceresult, dmgbits)
{
    if(item_have_bat[attacker] && is_user_alive(victim))
    {
        switch(random_num(1,100))
        {
            case 1..15: 
            {
                set_tr2(traceresult, TR_iHitgroup, HIT_HEAD)
            }

        }
    }
}
Depresie is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-18-2015 , 07:28   Re: [QUESTION]What is the difference betwen these functions
Reply With Quote #38

"Index out of bounds" happens when you try to index an elemental in an array outside its range/size. So if you have
PHP Code:
new PlayerArray[33]; 
It will throw an error if you try to index it with a negative number or a number higher than 32.

So just a check if the player is alive, connected or between 1(inclusive) and maxplayers(also inclusive) should save you from that error (if you are dealing with player arrays, like in your case).
fw_PlayerPreThink (your are missing function parameters in your post) *should* always be called on a player, so such check is probably redundant, but I would always add it just to be safe.
klippy is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-18-2015 , 08:55   Re: [QUESTION]What is the difference betwen these functions
Reply With Quote #39

i undestood, also, if i use is_user_alive it won't be needed to use is_user_connected anymore, right?
Depresie is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-18-2015 , 09:03   Re: [QUESTION]What is the difference betwen these functions
Reply With Quote #40

Yes. A user can't be alive without being connected.
__________________

Last edited by HamletEagle; 08-18-2015 at 09:03.
HamletEagle 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 05:41.


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