Command Help
#1

Alright so i've been working on making a forklift attachment thing when you type /getcrate you will get a crate attached to the forklift. The thing is once i type the command when i'm inside of the vehicle, nothing gets attached even when I told it to attach it when i'm inside of the forklift. Please help

Код:
#include <a_samp>
#include <zcmd>
#include <streamer>
#include <YSI\y_timers>

#define SendFormattedMessage(%0,%1,%2) do{new _str[128]; format(_str,128,%2); SendClientMessageEx(%0,%1,_str);}while(FALSE)

#define GetVehicleName(%0) VehicleName[GetVehicleModel(%0)-400]
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_CYAN 0x00FFFFFF

IsAForklift(carid)
{
	new Forklift[] = { 530 };
	for(new i = 0; i < sizeof(Forklift); i++)
	{
		if(GetVehicleModel(carid) == Forklift[i]) return 1;
	}
	return 0;
}

public OnFilterScriptInit()
{
	CreateDynamicObject(3574,2353.8000500,-2026.0999800,15.3000000,0.0000000,0.0000000,0.0000000); //object(lasdkrtgrp2) (1)
	CreateDynamicObject(944,2360.1001000,-2020.1999500,13.4000000,0.0000000,0.0000000,0.0000000); //object(packing_carates04) (5)
	CreateDynamicObject(944,2357.3000500,-2020.1999500,13.4000000,0.0000000,0.0000000,0.0000000); //object(packing_carates04) (6)
	CreateDynamicObject(944,2354.3999000,-2020.1999500,13.4000000,0.0000000,0.0000000,0.0000000); //object(packing_carates04) (7)
	CreateDynamicObject(944,2351.6001000,-2020.1999500,13.4000000,0.0000000,0.0000000,0.0000000); //object(packing_carates04) (8)
    return 1;
}

new CrateBox;

CMD:getcrate(playerid, params[])
{
	if (IsPlayerInRangeOfPoint(playerid, 10.0, 2353.8000500, -2026.0999800, 15.3000000)) // Matrun 3
	{
		new vehicle = GetPlayerVehicleID(playerid);
		if(IsAForklift(vehicle))
		{
	    	        CrateBox = CreateObject(1685, 10.0, 10.0, 10.0, 0, 0, 0);
			AttachObjectToVehicle(CrateBox, 530, 0.000000, 0.999999, 0.529999, 0.000000, 0.000000, 0.000000); //Object Model: 1685 | obj
		}
		else SendClientMessage(playerid, COLOR_YELLOW, "You are not inside of a Forklift or near the Get Crate point");
 	}
 	return 1;
}
I compiled the whole thing, nothing seems to be wrong.. I just can't figure out why this is happening
Reply
#2

You are attaching the object to vehicle id 530

Check this

pawn Код:
AttachObjectToVehicle(CrateBox, 530, 0.000000, 0.999999, 0.529999, 0.000000, 0.000000, 0.000000);
and this

pawn Код:
AttachObjectToVehicle(objectid, vehicleid, Float:OffsetX, Float:OffsetY, Float:OffsetZ, Float:RotX, Float:RotY, Float:RotZ);

Try like this

pawn Код:
CMD:getcrate(playerid, params[])
{
    if (IsPlayerInRangeOfPoint(playerid, 10.0, 2353.8000500, -2026.0999800, 15.3000000)) // Matrun 3
    {
        new vehicle = GetPlayerVehicleID(playerid);
        if(IsAForklift(vehicle))
        {
            CrateBox = CreateObject(1685, 10.0, 10.0, 10.0, 0, 0, 0);
            AttachObjectToVehicle(CrateBox, vehicle, 0.000000, 0.999999, 0.529999, 0.000000, 0.000000, 0.000000); //Object Model: 1685 | obj
        }
        else SendClientMessage(playerid, COLOR_YELLOW, "You are not inside of a Forklift or near the Get Crate point");
    }
    return 1;
}
Reply
#3

Could you help me make it so if the player leaves the vehicle it destroys the object? and when the vehicle gets respawned the item gets destroyed? please
Reply
#4

This was just a quick one (Probably half an hour with breaks, lol):
pawn Код:
#include <a_samp>
#include <zcmd>
#include <streamer>
#include <YSI\y_timers>

#define SendFormattedMessage(%0,%1,%2) do{new _str[128]; format(_str,128,%2); SendClientMessageEx(%0,%1,_str);}while(FALSE)

#define GetVehicleName(%0) VehicleName[GetVehicleModel(%0)-400]
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_CYAN 0x00FFFFFF

new CrateBox[MAX_VEHICLES] = INVALID_OBJECT_ID;
new LastVehicle[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    LastVehicle[playerid] = INVALID_VEHICLE_ID;
    return 1;
}

public OnFilterScriptInit()
{
    CreateDynamicObject(3574,2353.8000500,-2026.0999800,15.3000000,0.0000000,0.0000000,0.0000000); //object(lasdkrtgrp2) (1)
    CreateDynamicObject(944,2360.1001000,-2020.1999500,13.4000000,0.0000000,0.0000000,0.0000000); //object(packing_carates04) (5)
    CreateDynamicObject(944,2357.3000500,-2020.1999500,13.4000000,0.0000000,0.0000000,0.0000000); //object(packing_carates04) (6)
    CreateDynamicObject(944,2354.3999000,-2020.1999500,13.4000000,0.0000000,0.0000000,0.0000000); //object(packing_carates04) (7)
    CreateDynamicObject(944,2351.6001000,-2020.1999500,13.4000000,0.0000000,0.0000000,0.0000000); //object(packing_carates04) (8)
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        LastVehicle[playerid] = GetPlayerVehicleID(playerid);
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(!IsPlayerConnected(i)) continue;
            if(i == playerid) continue;
            if(LastVehicle[i] != LastVehicle[playerid]) continue;
            LastVehicle[i] = INVALID_VEHICLE_ID;
            break;
        }
    }
    if(oldstate == PLAYER_STATE_DRIVER)
    {
        if(newstate == PLAYER_STATE_ONFOOT)
        {
            if(IsAForklift(LastVehicle[playerid]))
            {
                if(CrateBox[LastVehicle[playerid]] != INVALID_OBJECT_ID)
                {
                    DestroyObject(CrateBox[LastVehicle[playerid]]);
                    CrateBox[LastVehicle[playerid]] = INVALID_OBJECT_ID;
                    SendClientMessage(playerid, COLOR_YELLOW, "You have left your forklift, and your crate has been destroyed.");
                }
            }
        }
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(IsAForklift(LastVehicle[playerid]))
    {
        if(CrateBox[LastVehicle[playerid]] != INVALID_OBJECT_ID)
        {
            DestroyObject(CrateBox[LastVehicle[playerid]]);
            CrateBox[LastVehicle[playerid]] = INVALID_OBJECT_ID;
        }
    }
    LastVehicle[playerid] = INVALID_VEHICLE_ID;
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(LastVehicle[i] != vehicleid) continue;
        if(IsAForklift(vehicleid))
        {
            if(CrateBox[vehicleid] != INVALID_OBJECT_ID)
            {
                DestroyObject(CrateBox[vehicleid]);
                CrateBox[vehicleid] = INVALID_OBJECT_ID;
                //The following is optional, based on whether you want to notify the player that their crate/vehicle was destroyed.
                SendClientMessage(i, COLOR_YELLOW, "Your forklift and the crate loaded on it has been destroyed.");
                break;
            }
        }
        LastVehicle[i] = INVALID_VEHICLE_ID;
    }
    return 1;
}

CMD:getcrate(playerid, params[])
{
    new vehicle = GetPlayerVehicleID(playerid);
    if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER || !IsAForklift(vehicle)) return SendClientMessage(playerid, COLOR_YELLOW, "You must be in a forklift to load crates.");
    if(!IsPlayerInRangeOfPoint(playerid, 10.0, 2353.8000500, -2026.0999800, 15.3000000)) return SendClientMessage(playerid, COLOR_YELLOW, "You are not near the Get Crate point.");
    CrateBox[vehicle] = CreateObject(1685, 10.0, 10.0, 10.0, 0, 0, 0);
    AttachObjectToVehicle(CrateBox[vehicle], vehicle, 0.000000, 0.999999, 0.529999, 0.000000, 0.000000, 0.000000); //Object Model: 1685 | obj
    SendClientMessage(playerid, COLOR_YELLOW, "You have loaded a crate on to your forklift.");
    return 1;
}

IsAForklift(carid)
{
    if(GetVehicleModel(carid) == 530) return 1;
    return 0;
}
Read the code, understand what's happening and you'll be able to do this kind of thing yourself eventually.
Reply
#5

Damn dude, i wouldn't be able to do that until i die :3 Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)