SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 11/04/2017, 01:27 PM   #1
Saddin
Huge Clucker
 
Saddin's Avatar
 
Join Date: Mar 2011
Posts: 372
Reputation: 35
Default Picking up crates - array - playertopoint

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;

Saddin is offline   Reply With Quote
Old 11/04/2017, 01:40 PM   #2
DarkSkull
Huge Clucker
 
DarkSkull's Avatar
 
Join Date: Aug 2014
Location: Dubai, United Arab Emirates
Posts: 325
Reputation: 43
Default Re: Picking up crates - array - playertopoint

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.
DarkSkull is offline   Reply With Quote
Old 11/04/2017, 01:41 PM   #3
AndreiWow
High-roller
 
AndreiWow's Avatar
 
Join Date: Nov 2014
Location: Romania, Bucharest
Posts: 1,046
Reputation: 48
Default Re: Picking up crates - array - playertopoint

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.
AndreiWow is offline   Reply With Quote
Old 11/04/2017, 01:42 PM   #4
Saddin
Huge Clucker
 
Saddin's Avatar
 
Join Date: Mar 2011
Posts: 372
Reputation: 35
Default Re: Picking up crates - array - playertopoint

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...
Saddin is offline   Reply With Quote
Old 11/04/2017, 01:44 PM   #5
DarkSkull
Huge Clucker
 
DarkSkull's Avatar
 
Join Date: Aug 2014
Location: Dubai, United Arab Emirates
Posts: 325
Reputation: 43
Default Re: Picking up crates - array - playertopoint

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); 
DarkSkull is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FilterScript] Weapon Crates Jelly23 Filterscripts 13 23/01/2017 12:18 AM
I need crates animation. jimdo Scripting Help 4 06/08/2016 11:57 AM
Falling crates. Sid_Alexander Scripting Help 17 02/01/2015 02:11 PM
Creating Invincible Crates iPLEOMAX Help Archive 2 23/07/2011 02:57 PM


All times are GMT. The time now is 06:33 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.