PDA

View Full Version : Picking up crates - array - playertopoint


Saddin
11/04/2017, 01:27 PM
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:

YCMD:pickupcrate(playerid, params[], help)
{
#pragma unused help
new Float:x, Float:y, Float:z;
for(new i; i<=sizeof(crate); i++)
{
GetObjectPos(crate[i], x, y, z); //gets position of every crate
if(PlayerToPoint(1, playerid, x, y, z))//any crate???
{
//picking up that crate
ApplyAnimation(playerid, "CARRY", "liftup", 4.0, 0, 1, 1, 1, 1);
SetTimerEx("PokupioKutiju", 1000, false, "i", playerid);
SetPlayerSpecialAction(playerid, SPECIAL_ACTION_CARRY);

}else SendClientMessage(playerid, COLOR_WHITE, "You are not close enough to any crate".);
}
return 1;
}

timer "PokupioKutiju":

forward PokupioKutiju(playerid);
public PokupioKutiju(playerid)
{
SetPlayerAttachedObject(playerid, 0, 3014, 6, 0.095999, 0.251999, -0.146999, -116.199989, -20.900005, 79.199981);
//DestroyObject(crate[i]); // how to work with this ???
ApplyAnimation(playerid, "CARRY", "crry_prtial", 4.0, 1, 1, 1, 1, 1);
SetPlayerSpecialAction(playerid, SPECIAL_ACTION_CARRY);

return 1;
}

Command /leavecrate:

YCMD:leavecrate(playerid, params[], help)
{
#pragma unused help


new Float:px, Float:py, Float:pz;
GetPlayerPos(playerid, px, py, pz);
for(new i=0; i<MAX_PLAYER_ATTACHED_OBJECTS; i++){if(IsPlayerAttachedObjectSlotUsed(playerid, i)) RemovePlayerAttachedObject(playerid, i);}
ApplyAnimation(playerid, "CARRY", "putdwn", 4.0, 0, 1, 0, 1, 1);
SetTimerEx("SpustioKutiju", 1000, false, "i", playerid); //this timer only clear animations
crate[i] = CreateObject(3014, px, py, pz-0.80, 0.00000, 0.00000, 0); //???
SetObjectPos(crate01, px, py, pz-0.80);


return 1;
}

DarkSkull
11/04/2017, 01:40 PM
I don't know anything about the crates, But the array:

crates[5]

Has 6 items instead of 5:
crates[0]
crates[1]
crates[2]
crates[3]
crates[4]
crates[5]

So you must edit your loop accordingly.

AndreiWow
11/04/2017, 01:41 PM
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.

Saddin
11/04/2017, 01:42 PM
I don't know anything about the crates, But the array:

crates[5]

Has 6 items instead of 5:
crates[0]
crates[1]
crates[2]
crates[3]
crates[4]
crates[5]

So you must edit your loop accordingly.

i just gave the example...

DarkSkull
11/04/2017, 01:44 PM
forward PokupioKutiju(playerid, crateid);
public PokupioKutiju(playerid, crateid)
{
SetPlayerAttachedObject(playerid, 0, 3014, 6, 0.095999, 0.251999, -0.146999, -116.199989, -20.900005, 79.199981);
//DestroyObject(crate[crateid]); // how to work with this ???
ApplyAnimation(playerid, "CARRY", "crry_prtial", 4.0, 1, 1, 1, 1, 1);
SetPlayerSpecialAction(playerid, SPECIAL_ACTION_CARRY);

return 1;
}

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

SetTimerEx("PokupioKutiju", 1000, false, "ii", playerid, i);