AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Comparing Origin (https://forums.alliedmods.net/showthread.php?t=189371)

Liverwiz 07-06-2012 11:55

Comparing Origin
 
How would i compare a user's origin (checking to see if they haven't moved) within a task.

I have this code....but it isn't working.

PHP Code:

public task_giveHealth(in[])
{
    new 
id str_to_num(in)
    
client_print(idprint_chat"Health Task....")
    new 
now[3], then[3]
    
get_user_origin(idnow)
    
    if(!
healthOrigin[id][0])
    {
        for(new 
03i++)
            
healthOrigin[id][i] = now[i]
    }
        
        
    
healthOrigin[id] = then
    
if(compareOrigin(nowthen) && healthGain[id] < 40)
    {
        
client_print(idprint_chat"Health Given")
        new 
health get_user_health(id) + 3
        set_user_health
(idhealth)
        
healthGain[id]+= 3
    
}
    else
        
remove_task(1)
}

    
// @RETURNS: 1 if equal; -[index] if not equal
stock compareOrigin(now[3], then[3])
{
    if(
now[0] != then[0])
        return 
0
    
else if(now[1] != then[1])
        return -
1
    
else if(now[2] != then[2])
        return -
2
        
    
return 1



hornet 07-06-2012 12:26

Re: Comparing Origin
 
Code:
bool:xs_vec_equal( const Float:vec1[], const Float:vec2[] )

Liverwiz 07-06-2012 12:43

Re: Comparing Origin
 
Quote:

Originally Posted by hornet (Post 1744735)
Code:
bool:xs_vec_equal( const Float:vec1[], const Float:vec2[] )

That's an unknown function. Both in compiler and the function wiki.
Where is it?

Arkshine 07-06-2012 13:00

Re: Comparing Origin
 
You have to include <xs>. (xs.inc)

Liverwiz 07-06-2012 13:13

Re: Comparing Origin
 
Oh, thanks

but now that everything has to be floats....how do i get their origin? get_user_origin is in ints....
And wouldn't the vector workings be different than origin?

Arkshine 07-06-2012 13:16

Re: Comparing Origin
 
You can use pev_origin (fakemeta), or EV_VEC_origin (engine) to retrieve origin.
You can use too IVecFVec to convert to float origin.

Liverwiz 07-06-2012 21:28

Re: Comparing Origin
 
I tried using IVecFVec to cast all arrays, but it still isn't working.

Here is all relevant code.
PHP Code:

new healthGain[33]        // [id - health gained]
new Float:healthOrigin[33][3]        // Origin for the health power
public client_connect(id)
{
    
powers[id] = PC_INVALID
    IVecFVec
({000}, healthOrigin[id])
}
public 
task_giveHealth(in[])
{
    new 
id str_to_num(in)
    
client_print(idprint_chat"Health Task....")
    new 
Float:now[3], Float:then[3], tmp[3]
    
get_user_origin(idtmp)
    
IVecFVec(tmphealthOrigin[id])
    
    if(!
healthOrigin[id][0])
    {
        for(new 
03i++)
            
healthOrigin[id][i] = now[i]
    }
        
        
    
then healthOrigin[id]
    if(
xs_vec_equal(nowthen) && healthGain[id] < 40)
    {
        
client_print(idprint_chat"Health Given")
        new 
health get_user_health(id) + 3
        set_user_health
(idhealth)
        
healthGain[id]+= 3
    
}
        
    
healthOrigin[id] = now


task_giveHealth IS called properly. (it prints "Health task...")

ConnorMcLeod 07-06-2012 21:49

Re: Comparing Origin
 
I don't see why you float origin.
Either you use get_user_origin, either you use engine or fakemeta so you retrieve a float vector.

Anyway, xs stock is :
PHP Code:

    // Are vectors equal?
    // untested, but should work
    
XS_LIBFUNC_ATTRIB bool:xs_vec_equal(const Float:vec1[], const Float:vec2[])
    {
        return (
vec1[0] == vec2[0]) && (vec1[1] == vec2[1]) && (vec1[2] == vec2[2]);
    } 

So if you want the same with integer you can use :
PHP Code:

bool:int_vec_equal(const vec1[3], const vec2[3])
{
    return (
vec1[0] == vec2[0]) && (vec1[1] == vec2[1]) && (vec1[2] == vec2[2]);



You could use this for both integer OR floats (not both at the same time) but i don't know how to check if tags match so better not to use :
PHP Code:

bool:vec_equal(const {_,Float}:vec1[3], const {_,Float}:vec2[3])
{
    return (
vec1[0] == vec2[0]) && (vec1[1] == vec2[1]) && (vec1[2] == vec2[2]);



Liverwiz 07-06-2012 22:11

Re: Comparing Origin
 
Quote:

Originally Posted by ConnorMcLeod (Post 1745078)
I don't see why you float origin.
Either you use get_user_origin, either you use engine or fakemeta so you retrieve a float vector.

So if you want the same with integer you can use :
PHP Code:

bool:int_vec_equal(const vec1[3], const vec2[3])
{
    return (
vec1[0] == vec2[0]) && (vec1[1] == vec2[1]) && (vec1[2] == vec2[2]);



I used floats so i could use the XS stock Arkshine suggested.
What include is int_vec_equal defined in? Its not compiling....

ConnorMcLeod 07-06-2012 22:16

Re: Comparing Origin
 
It's not in any include file, just put the function in your .sma, and name it as you want.

You may be interested in get_distance native : http://www.amxmodx.org/funcwiki.php?go=func&id=283


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

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