Raised This Month: $ Target: $400
 0% 

Comparing Origin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-06-2012 , 11:55   Comparing Origin
Reply With Quote #1

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

__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 07-06-2012 , 12:26   Re: Comparing Origin
Reply With Quote #2

Code:
bool:xs_vec_equal( const Float:vec1[], const Float:vec2[] )
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-06-2012 , 12:43   Re: Comparing Origin
Reply With Quote #3

Quote:
Originally Posted by hornet View Post
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?
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-06-2012 , 13:00   Re: Comparing Origin
Reply With Quote #4

You have to include <xs>. (xs.inc)
__________________

Last edited by Arkshine; 07-06-2012 at 13:01.
Arkshine is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-06-2012 , 13:13   Re: Comparing Origin
Reply With Quote #5

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?
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-06-2012 , 13:16   Re: Comparing Origin
Reply With Quote #6

You can use pev_origin (fakemeta), or EV_VEC_origin (engine) to retrieve origin.
You can use too IVecFVec to convert to float origin.
__________________

Last edited by Arkshine; 07-06-2012 at 13:17.
Arkshine is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-06-2012 , 21:28   Re: Comparing Origin
Reply With Quote #7

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...")
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-06-2012 , 21:49   Re: Comparing Origin
Reply With Quote #8

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]);

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-06-2012 , 22:11   Re: Comparing Origin
Reply With Quote #9

Quote:
Originally Posted by ConnorMcLeod View Post
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....
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-06-2012 , 22:16   Re: Comparing Origin
Reply With Quote #10

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
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 07-06-2012 at 22:18.
ConnorMcLeod 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 15:15.


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