AttachObjectToVehicle - 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: AttachObjectToVehicle (
/showthread.php?tid=451948)
AttachObjectToVehicle -
RALL0 - 19.07.2013
Hey, I just created a loadforklift command and I got 5 defined object, but I am really confused how can I make it that the system checks if the player is near one of the 5 objects instead just 1 of them. Here are the codes.
pawn Код:
CMD:loadforklift(playerid, params[])
{
new Float:X,Float:Y,Float:Z;
new vehicleid = GetPlayerVehicleID(playerid);
GetObjectPos(CrateObjects[1],X,Y,Z);
if(IsAForklift(vehicleid))
{
if(IsPlayerInRangeOfPoint(playerid,10,X,Y,Z))
{
ForkliftLoaded[vehicleid] = 1;
DestroyObject(CrateObjects[1]);
ForkliftObject[vehicleid][vObject] = CreateObject(964, 0, 0.9, -0.12, 0, 0, 0);
AttachObjectToVehicle(ForkliftObject[vehicleid][vObject], vehicleid, 0, 0.9, -0.12, 0, 0, 0);
}
else return SendClientMessage(playerid, COLOR_DARKRED,"[SERVER] {FFFFFF}You aren't near any crate.");
}
else return SendClientMessage(playerid, COLOR_DARKRED,"[SERVER] {FFFFFF}You must be a driver of a forklift to load a forklift.");
return 1;
}
Re: AttachObjectToVehicle -
RALL0 - 19.07.2013
Bump ;s
Re: AttachObjectToVehicle -
PaulDinam - 19.07.2013
How did you define those 5 objects?
Something like this?
new CrateObjects[5];
Then try this.
pawn Код:
stock PlayerNearCrate(playerid)
{
new Float:x, Float:y, Float:z;
for(new i = 0; i < 5; i++)
{
GetObjectPos(CrateObjects[i], x, y, z);
if(IsPlayerInRangeOfPoint(playerid, 10, x, y, z))
return i;
}
return -1;
}
CMD:loadforklift(playerid, params[])
{
new vehicleid = GetPlayerVehicleID(playerid);
new crate = PlayerNearCrate(playerid);
if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SCM(playerid, COLOR_DARKRED, "You must be the driver.");
if(!IsAForklift(vehicleid)) return SendClientMessage(playerid, COLOR_DARKRED,"[SERVER] {FFFFFF}You must be a driver of a forklift to load a forklift.");
if(crate != -1)
{
ForkliftLoaded[vehicleid] = 1;
DestroyObject(CrateObjects[crate]);
ForkliftObject[vehicleid][vObject] = CreateObject(964, 0, 0.9, -0.12, 0, 0, 0);
AttachObjectToVehicle(ForkliftObject[vehicleid][vObject], vehicleid, 0, 0.9, -0.12, 0, 0, 0);
}
else return SendClientMessage(playerid, COLOR_DARKRED,"[SERVER] {FFFFFF}You aren't near any crate.");
return 1;
}
Re: AttachObjectToVehicle -
RALL0 - 19.07.2013
Exactly, thanks