SA-MP Forums Archive
Picking up crates - array - playertopoint - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Picking up crates - array - playertopoint (/showthread.php?tid=632250)



Picking up crates - array - playertopoint - Saddin - 11.04.2017

I have a problem and a question.

I am trying to make command that picks first close (available) create to do something with it... with a command.

For example, I type /pickupcrate it should check for playertopoint if it is close enough to pick it up and than do something with it. I have already done that. Problem is when 5 crates in an array (crates[5]) are on one big pile and when I type /pickupcrate i pick all of them.

Also there is a problem. When I use another command for example /leavecrate I can't make it work because I cannot get information from last command (/pickupcrate) which crate I picked up. For example if I picked up crate[3] how do I know is that corred position of crate array.

Commands:

PHP Code:
YCMD:pickupcrate(playeridparams[], help)
{
    
#pragma unused help
    
new Float:xFloat:yFloat:z;
        for(new 
ii<=sizeof(crate); i++)
        {
        
GetObjectPos(crate[i], xyz); //gets position of every crate 
    
if(PlayerToPoint(1playeridxyz))//any crate???
    
{
            
//picking up that crate
            
ApplyAnimation(playerid"CARRY""liftup"4.001111);
        
SetTimerEx("PokupioKutiju"1000false"i"playerid);
        
SetPlayerSpecialAction(playeridSPECIAL_ACTION_CARRY);
    
    }else 
SendClientMessage(playeridCOLOR_WHITE"You are not close enough to any crate".);
    }
    return 
1;

timer "PokupioKutiju":

PHP Code:
forward PokupioKutiju(playerid);
public 
PokupioKutiju(playerid)
{
    
SetPlayerAttachedObject(playerid0301460.0959990.251999, -0.146999, -116.199989, -20.90000579.199981);
    
//DestroyObject(crate[i]); // how to work with this ???
    
ApplyAnimation(playerid"CARRY""crry_prtial"4.011111);
    
SetPlayerSpecialAction(playeridSPECIAL_ACTION_CARRY);
    
    return 
1;

Command /leavecrate:

PHP Code:
YCMD:leavecrate(playeridparams[], help)
{
    
#pragma unused help
    
    
    
new Float:pxFloat:pyFloat:pz;
    
GetPlayerPos(playeridpxpypz);
    for(new 
i=0i<MAX_PLAYER_ATTACHED_OBJECTSi++){if(IsPlayerAttachedObjectSlotUsed(playeridi)) RemovePlayerAttachedObject(playeridi);}
    
ApplyAnimation(playerid"CARRY""putdwn"4.001011);
    
SetTimerEx("SpustioKutiju"1000false"i"playerid); //this timer only clear animations
    
crate[i] = CreateObject(3014pxpypz-0.800.000000.000000); //???
    
SetObjectPos(crate01pxpypz-0.80);
    return 
1;




Re: Picking up crates - array - playertopoint - DarkSkull - 11.04.2017

I don't know anything about the crates, But the array:

PHP Code:
crates[5
Has 6 items instead of 5:
PHP Code:
crates[0]
crates[1]
crates[2]
crates[3]
crates[4]
crates[5
So you must edit your loop accordingly.


Re: Picking up crates - array - playertopoint - AndreiWow - 11.04.2017

you can create another variable for example

playercrate[3] and when the player picks the third crate set playercrate[3] = 1;

if he tries to drop it check which variable is on and for example if playercrate[3] has value 1, it means that he is holding crate 3 and this way you can update the location of crate 3.


Re: Picking up crates - array - playertopoint - Saddin - 11.04.2017

Quote:
Originally Posted by DarkSkull
View Post
I don't know anything about the crates, But the array:

PHP Code:
crates[5
Has 6 items instead of 5:
PHP Code:
crates[0]
crates[1]
crates[2]
crates[3]
crates[4]
crates[5
So you must edit your loop accordingly.
i just gave the example...


Re: Picking up crates - array - playertopoint - DarkSkull - 11.04.2017

PHP Code:
forward PokupioKutiju(playeridcrateid);
public 
PokupioKutiju(playeridcrateid)
{
    
SetPlayerAttachedObject(playerid0301460.0959990.251999, -0.146999, -116.199989, -20.90000579.199981);
    
//DestroyObject(crate[crateid]); // how to work with this ???
    
ApplyAnimation(playerid"CARRY""crry_prtial"4.011111);
    
SetPlayerSpecialAction(playeridSPECIAL_ACTION_CARRY);
    
    return 
1;

You can set your function to pass the crate id as well. Your timer will look something like:

PHP Code:
SetTimerEx("PokupioKutiju"1000false"ii"playeridi);