AttachObjectToVehicle
#1

hello, i used the filescript to create boxes using (ivo) AttachObjectToVehicle
when the player type / pbox......2 player is more work together giving the same command
while delivering the box, it disappears from the first that took and buga, how do I not give bug?

example:

pawn Код:
if(PlayerW[playerid][Work] == box){
    box1 = CreateObject(id ,0,0,-1000,0,0,0,100);
    box2 = CreateObject(id,0,0,-1000,0,0,0,100);
    AttachObjectToVehicle(box1, GetPlayerVehicleID(playerid), 0.000000,-0.750000,0.300000,0.000000,0.000000,89.099983);
    AttachObjectToVehicle(box2, GetPlayerVehicleID(playerid), 0.075000,-0.750000,0.449999,0.000000,0.000000,89.099983);
    SetPlayerMapIcon(playerid, 37, 1324.5773,286.8284,20.0452, 17, 0, MAPICON_GLOBAL);
    tbox[playerid] = 1;
Reply
#2

Quote:
Originally Posted by Clarck
Посмотреть сообщение
hello, i used the filescript to create boxes using (ivo) AttachObjectToVehicle
when the player type / pbox......2 player is more work together giving the same command
while delivering the box, it disappears from the first that took and buga, how do I not give bug?

example:

pawn Код:
if(PlayerW[playerid][Work] == box){
    box1 = CreateObject(id ,0,0,-1000,0,0,0,100);
    box2 = CreateObject(id,0,0,-1000,0,0,0,100);
    AttachObjectToVehicle(box1, GetPlayerVehicleID(playerid), 0.000000,-0.750000,0.300000,0.000000,0.000000,89.099983);
    AttachObjectToVehicle(box2, GetPlayerVehicleID(playerid), 0.075000,-0.750000,0.449999,0.000000,0.000000,89.099983);
    SetPlayerMapIcon(playerid, 37, 1324.5773,286.8284,20.0452, 17, 0, MAPICON_GLOBAL);
    tbox[playerid] = 1;
What is the code stub? If you want to help lay out more information.

PHP код:
if (PlayerW [playerid] [Work] == box) {
box1 CreateObject(id0,0, -1000,0,0,0,100); // ID that be? you declared new box1, box2;?
box2 CreateObject(id0,0, -1000,0,0,0,100); // If you specify a floating-point better to write it as well
AttachObjectToVehicle (box1GetPlayerVehicleID (playerid), 0.000000, -0.750000,0.300000,0.000000,0.000000,89.099983);
AttachObjectToVehicle (box2GetPlayerVehicleID (playerid), 0.075000, -0.750000,0.449999,0.000000,0.000000,89.099983);
SetPlayerMapIcon (playerid37 1324.5773,286.8284,20.0452170MAPICON_GLOBAL);
tbox [playerid] = 1
Example:
PHP код:
#define MAX_MSG_SIZE (256)
public OnPlayerCommandText(playeridcmdtext[])
{
    new 
msg[MAX_MSG_SIZE];
    if (
strcmp("/mbox"cmdtexttrue10) == 0)
    {
        if (
IsPlayerInAnyVehicle(playerid)) {
            new 
vehicleid GetPlayerVehicleID(playerid);
            new 
box1 CreateObject(198320.0,0.0,0.00.0,0.0,0.0100.0);
            new 
box2 CreateObject(198320.0,0.0,0.00.0,0.0,0.0100.0);
            
AttachObjectToVehicle(box1vehicleid0.000000,-0.750000,0.3000000.000000,0.000000,89.099983);
            
AttachObjectToVehicle(box2vehicleid0.075000,-0.750000,0.4499990.000000,0.000000,89.099983);
            
SetPlayerMapIcon(playerid371324.5773,286.8284,20.0452170MAPICON_GLOBAL);
            
format(msgMAX_MSG_SIZE"MBox: box1 (%d), box2 (%d) created and attached vehicle (%d)"box1box2,vehicleid);
            
SendClientMessage(playerid0x00FF00FFmsg);
        } else {
            
SendClientMessage(playerid0xFF0000FF"You not in car!");
        }
        return 
1;
    }
    return 
0;

Reply
#3

if you and I get the box, when I unload my box, your disappear ,my box should disappear when I unload, not your box, this is the bug
Reply
#4

Having "box1" and "box2" as global variables and more than 1 player use them at a time will mess the IDs up.

Let's say player A uses the command and it creates the two objects. Player B uses the command too and "box1", "box2" hold the objectid from the player B. When player A is done and you want to delete the objects, you haven't stored them anywhere as they were overwritten by player B so it destroys the objects from player B.

If each player can have 2 boxes, then create a global array:
pawn Код:
// global:
new Player_Box[2][MAX_PLAYERS];

// OnPlayerConnect:
Player_Box[0][playerid] = Player_Box[1][playerid] = INVALID_OBJECT_ID;
pawn Код:
Player_Box[0][playerid] = CreateObject(id ,0,0,-1000,0,0,0,100);
Player_Box[1][playerid] = CreateObject(id,0,0,-1000,0,0,0,100);
AttachObjectToVehicle(Player_Box[0][playerid], GetPlayerVehicleID(playerid), 0.000000,-0.750000,0.300000,0.000000,0.000000,89.099983);
AttachObjectToVehicle(Player_Box[1][playerid], GetPlayerVehicleID(playerid), 0.075000,-0.750000,0.449999,0.000000,0.000000,89.099983);
When you destroy them, set the variables to INVALID_OBJECT_ID as in OnPlayerConnect.
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
[pawn]
// global:
new Player_Box[2][MAX_PLAYERS];

// OnPlayerConnect:
Player_Box[0][playerid] = Player_Box[1][playerid] = INVALID_OBJECT_ID;
PHP код:
new Player_Box[2][MAX_PLAYERS] = {{INVALID_OBJECT_ID,...},{INVALID_OBJECT_ID,...}}; // initialize all the variables with the value 65535 instead of each assignment 
Example:
PHP код:
#define foreach2(%1,%2) for(new %1; %1<%2; %1++)
main() {
    new 
Player_Box[2][MAX_PLAYERS] = {{65535,...},{65535,...}};
    
    
foreach2(p1000) {
        
foreach2(i2) {
            
printf("player %d box[%d] value %d",piPlayer_Box[i][p]);
        }
    }

Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)