PDA

View Full Version : Flying Object


ChuckyBabe
18/04/2015, 01:29 AM
I tried to make it fly but i can't is there anyone who can help me to make it fly ? here's my code


#include <a_samp>
#include <foreach>
#include <ZCMD>
#include <YSI/y_timers.inc>
#include <streamer>
#include <sscanf2>
#define MAX_HOT_AIR_BALLOONS (100)

#define MAX_HOT_AIR_BALLOON_SPEED (20.0)

#define INVALID_HOT_AIR_BALLOON_ID (-1)
enum dataBalloon
{
modelID,
objectID,
Float:speed,
Float:position[8]
}

new
balloonID = INVALID_HOT_AIR_BALLOON_ID,
balloonData[MAX_HOT_AIR_BALLOONS][dataBalloon],
Float:balloonGoTo[MAX_HOT_AIR_BALLOONS][3],
habstopwarn[MAX_PLAYERS];
enum pData
{
pHAB
};
new PlayerData[MAX_PLAYERS + 1][pData];

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
print("\n--------------------------------------");
print(" Hot air Balloon by Inverse Roleplay");
print("--------------------------------------\n");
LoadBalloons();
return 1;
}

public OnFilterScriptExit()
{
for(new idx=1; idx<MAX_GATES; idx++)
{
if(GateInfo[idx][gModel])
{
DestroyObject(balloonData[idx][objectID]);
}
}
SaveBalloons();
return 1;
}

#else

main()
{
print("\n----------------------------------");
print(" Blank Gamemode by your name here");
print("----------------------------------\n");
}

#endif




/* ----- */


/* ----- */
/* ----- */
stock SaveBalloons()
{
new idx = 1, File:file;
new string[256];
while(idx < MAX_HOT_AIR_BALLOONS)
{

format(string, sizeof(string), "%d|%f|%f|%f|%f|%f|%f|%f|%f|%d\r\n",
balloonData[idx][modelID],
balloonData[idx][position][0],
balloonData[idx][position][1],
balloonData[idx][position][2],
balloonData[idx][position][3],
balloonData[idx][position][4],
balloonData[idx][position][5],
balloonData[idx][position][6],
balloonData[idx][position][7],
balloonData[idx][speed]);

if(idx == 1)
{
file = fopen("hab.cfg", io_write);
}
else
{
file = fopen("hab.cfg", io_append);
}
fwrite(file, string);
fclose(file);
idx++;
}
return 1;
}
stock LoadBalloons()
{

new dinfo[17][128];
new string[256];
new File:file = fopen("hab.cfg", io_read);
if(file)
{
new idx = 1;
while(idx < MAX_HOT_AIR_BALLOONS)
{
fread(file, string);
splits(string, dinfo, '|');
balloonData[idx][modelID] = strval(dinfo[0]);
balloonData[idx][position][0] = floatstr(dinfo[1]);
balloonData[idx][position][1] = floatstr(dinfo[2]);
balloonData[idx][position][2] = floatstr(dinfo[3]);
balloonData[idx][position][3] = floatstr(dinfo[4]);
balloonData[idx][position][4] = floatstr(dinfo[5]);
balloonData[idx][position][5] = floatstr(dinfo[6]);
balloonData[idx][position][6] = floatstr(dinfo[7]);
balloonData[idx][position][7] = floatstr(dinfo[8]);
balloonData[idx][speed] = strval(dinfo[9]);
if(balloonData[idx][modelID])
{
balloonData[idx][objectID] = CreateDynamicObject(balloonData[idx][modelID], balloonData[idx][position][0], balloonData[idx][position][1], balloonData[idx][position][2], balloonData[idx][position][3]
, balloonData[idx][position][4], balloonData[idx][position][5]);
}
idx++;
}

}
return 1;
}

stock CreateHotAirBalloon(playerid, giveplayerid ,modelid ,Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz = 0.0)
{
#pragma unused playerid
for(new idx=1; idx<MAX_HOT_AIR_BALLOONS; idx++)
{
if(!balloonData[idx][modelID])
{
balloonData[idx][modelID] = 19331 +modelid;
balloonData[idx][position][0] = x;
balloonData[idx][position][1] = y;
balloonData[idx][position][2] = z;
balloonData[idx][position][3] = rx;
balloonData[idx][position][4] = ry;
balloonData[idx][position][5] = rz;
balloonData[idx][speed] = 0.0;
balloonData[idx][objectID] = CreateDynamicObject(19331 + modelid, x, y, z, rx, ry, rz);
PlayerData[giveplayerid][pHAB] = idx;
idx = MAX_HOT_AIR_BALLOONS;
}
}
return 1;
}

stock DestroyHotAirBalloon(habid)
{
if(IsHotAirBalloonCreated(habid))
{
balloonID--;
balloonData[habid][modelID] = 0;
balloonData[habid][position][0] = 0.0;
balloonData[habid][position][1] = 0.0;
balloonData[habid][position][2] = 0.0;
balloonData[habid][position][3] = 0.0;
balloonData[habid][position][4] = 0.0;
balloonData[habid][position][5] = 0.0;
balloonData[habid][speed] = 0.0;
DestroyObject(balloonData[habid][objectID]);
foreach(Player, u)
{
if((GetPVarInt(u, "balloonID") - 1) == habid)
{
SetPVarInt(u, "balloonID", 0);
ClearAnimations(u);
SetPlayerPosFindZ(u, GetPlayerPosX(u), GetPlayerPosY(u), GetPlayerPosZ(u));
break;
}
}
return true;
}
return false;
}

stock IsHotAirBalloonCreated(habid)
{
if(balloonData[habid][modelID]) return true;
return false;
}

stock GetNumberOfHotAirBalloons() return balloonID;

stock StopHotAirBalloon(habid)
{
if(!IsHotAirBalloonCreated(habid)) return false;
balloonData[habid][speed] = 0.0;
StopObject(balloonData[habid][objectID]);
return true;
}

stock SetHotAirBalloonSpeed(habid, Float:balloonspeed = MAX_HOT_AIR_BALLOON_SPEED)
{
if(!IsHotAirBalloonCreated(habid)) return false;
if(balloonspeed > MAX_HOT_AIR_BALLOON_SPEED) balloonData[habid][speed] = MAX_HOT_AIR_BALLOON_SPEED;
else balloonData[habid][speed] = balloonspeed;
return true;
}


stock IsHotAirBalloonOccupied(habid)
{
if(!IsHotAirBalloonCreated(habid)) return INVALID_PLAYER_ID;
foreach(Player, u)
{
if((GetPVarInt(u, "balloonID") - 1) == habid) return u;
}
return INVALID_PLAYER_ID;
}

/* ----- */

stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
new
Float:angle;
GetPlayerPos(playerid, x, y, angle);
GetPlayerFacingAngle(playerid, angle);
x += (distance * floatsin(-angle, degrees));
y += (distance * floatcos(-angle, degrees));
}

forward Float:GetPlayerPosX(playerid);
Float:GetPlayerPosX(playerid)
{
new
Float:pos[3];
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
return Float:pos[0];
}

forward Float:GetPlayerPosY(playerid);
Float:GetPlayerPosY(playerid)
{
new
Float:pos[3];
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
return Float:pos[1];
}

forward Float:GetPlayerPosZ(playerid);
Float:GetPlayerPosZ(playerid)
{
new
Float:pos[3];
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
return Float:pos[2];
}

/* ----- */
/* ----- */

CMD:balloon( playerid, params[])
{

new
Float:objPos[3];
if(!GetPVarInt(playerid, "balloonID"))
{
if(IsPlayerInRangeOfPoint(playerid, 1.7, balloonData[PlayerData[playerid][pHAB]][position][0], balloonData[PlayerData[playerid][pHAB]][position][1], balloonData[PlayerData[playerid][pHAB]][position][2]))
{
new
isOccupied = IsHotAirBalloonOccupied(PlayerData[playerid][pHAB]);
if(isOccupied != INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFFFFFFFF, "(balloon) Someone is already flying on this hot air balloon!");
SetPVarInt(playerid, "balloonID", 1);
GetDynamicObjectPos(balloonData[PlayerData[playerid][pHAB]][objectID], objPos[0], objPos[1], objPos[2]);
SetPlayerPos(playerid, objPos[0], objPos[1], objPos[2] + 1.0);
SetPlayerFacingAngle(playerid, balloonData[PlayerData[playerid][pHAB]][position][5]);
ApplyAnimation(playerid, "ped", "DRIVE_BOAT", 4.0, 1, 0, 0, 0, 0);
SendClientMessage(playerid, 0xFFFFFFFF, "Flying started. Use \"/balloon\" command to stop with the flying.");
}
else SendClientMessage(playerid, 0xFFFFFFFF, "You're not near any hot air balloon or you're not close enough to it.");
}
else
{
StopHotAirBalloon(PlayerData[playerid][pHAB]);
SetPVarInt(playerid, "balloonID", 0);
ClearAnimations(playerid);
SendClientMessage(playerid, 0xFFFFFFFF, "Flying stopped. Use \"/balloon\" command to start with the flying again.");
}
return true;
}
// Timer Name: hab()
// TickRate: 1 secs.
Timer:hab[1000]()
{
foreach(Player, i)
{
new
habid = PlayerData[i][pHAB];
if(GetPVarInt(i, "balloonID") == 1)
{
if(!IsPlayerInRangeOfPoint(i, 1.7, balloonData[habid][position][0], balloonData[habid][position][1], balloonData[habid][position][2]))
{
habstopwarn[i] ++;
if(habstopwarn[i] >= 2) {
StopHotAirBalloon(habid);
SetPVarInt(i, "balloonID", 0);
habstopwarn[i] = 0;
ClearAnimations(i);
DestroyObject(balloonData[habid][objectID]);
SendClientMessage(i, 0xFFFFFFFF, "Flying with hot air balloon stopped - hot air balloon is re-spawned.");
SetPlayerPosFindZ(i, GetPlayerPosX(i), GetPlayerPosY(i), GetPlayerPosZ(i));
CreateDynamicObject(19331 + balloonData[habid][modelID], balloonData[habid][position][0], balloonData[habid][position][1], balloonData[habid][position][2], balloonData[habid][position][3], balloonData[habid][position][4], balloonData[habid][position][5]);
}
}
}
}
}
/* ----- */

public OnPlayerConnect(playerid)
{
ApplyAnimation(playerid, "ped", "null", 0.0, 0, 0, 0, 0, 0);

return true;
}




public OnPlayerDisconnect(playerid, reason)
{
return 1;
}


CMD:oohfuckingbitch(playerid, params[])
{
new giveplayerid, modelid;
if(sscanf(params, "ud", giveplayerid, modelid))
{
SendClientMessage(playerid, -1, "USAGE: /gvieplayerhab [playerid/partofname] [type 1-7 (HAB)]");
return 1;
}
if(modelid < 1 || modelid > 7) return SendClientMessage(playerid, -1, "Model of Ballon should be 1 to 7");
new Float:x, Float:y, Float:z;
GetPlayerPos(giveplayerid, x, y, z);
CreateHotAirBalloon(playerid, giveplayerid ,modelid ,x, y, z-1.0, 0.0, 0.0,0.0);
return 1;
}


public OnPlayerUpdate(playerid)
{
new
habid = PlayerData[playerid][pHAB];
if(habid != INVALID_HOT_AIR_BALLOON_ID && GetPVarInt(playerid, "balloonID") == 1)
{
new
keys[3], Float:floatVal[4];
GetPlayerPos(playerid, floatVal[0], floatVal[1], floatVal[2]);
floatVal[3] = balloonData[habid][speed];
GetPlayerKeys(playerid, keys[0], keys[1], keys[2]);
GetXYInFrontOfPlayer(playerid, floatVal[0], floatVal[1], 50.0);
balloonGoTo[habid][0] = floatVal[0];
balloonGoTo[habid][1] = floatVal[1];
balloonGoTo[habid][2] = balloonData[habid][position][2];
if(keys[0] == KEY_JUMP)
{
if(balloonData[habid][position][2] < 700.0) balloonData[habid][position][2] += 0.3;
else balloonData[habid][position][2] = 700.0;
}
else if(keys[0] == KEY_SPRINT)
{
if(balloonData[habid][position][2] > 2.0) balloonData[habid][position][2] -= 0.3;
else balloonData[habid][position][2] = 2.0;
}
if(keys[1] == KEY_UP)
{
if(floatVal[3] >= -2.0 && floatVal[3] < MAX_HOT_AIR_BALLOON_SPEED) balloonData[habid][speed] += 0.2;
if(floatVal[3] >= MAX_HOT_AIR_BALLOON_SPEED) balloonData[habid][speed] = MAX_HOT_AIR_BALLOON_SPEED;
}
else if(keys[1] == KEY_DOWN)
{
if(floatVal[3] >= -2.0 && floatVal[3] < MAX_HOT_AIR_BALLOON_SPEED) balloonData[habid][speed] -= 0.2;
if(floatVal[3] >= MAX_HOT_AIR_BALLOON_SPEED) balloonData[habid][speed] = MAX_HOT_AIR_BALLOON_SPEED;
}
if(keys[2] == KEY_LEFT)
{
balloonData[habid][speed] -= 0.01;
balloonData[habid][position][5] += 1.5;
SetObjectRot(balloonData[habid][objectID], balloonData[habid][position][3], balloonData[habid][position][4], balloonData[habid][position][5]);
SetPlayerFacingAngle(playerid, balloonData[habid][position][5]);
balloonGoTo[habid][0] = floatVal[0];
balloonGoTo[habid][1] = floatVal[1];
balloonGoTo[habid][2] = balloonData[habid][position][2];
}
else if(keys[2] == KEY_RIGHT)
{
balloonData[habid][speed] -= 0.01;
balloonData[habid][position][5] -= 1.5;
SetObjectRot(balloonData[habid][objectID], balloonData[habid][position][3], balloonData[habid][position][4], balloonData[habid][position][5]);
SetPlayerFacingAngle(playerid, balloonData[habid][position][5]);
balloonGoTo[habid][0] = floatVal[0];
balloonGoTo[habid][1] = floatVal[1];
balloonGoTo[habid][2] = balloonData[habid][position][2];
}
if(balloonData[habid][speed] > 0.1)
{
balloonData[habid][speed] -= 0.1;
MoveObject(balloonData[habid][objectID], balloonGoTo[habid][0], balloonGoTo[habid][1], balloonGoTo[habid][2], balloonData[habid][speed]);
}
new
string[72];
format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~Speed: ~w~%0.1f ~r~/ ~w~%0.1f", balloonData[habid][speed], MAX_HOT_AIR_BALLOON_SPEED);
GameTextForPlayer(playerid, string, 1000, 3);
}

return true;
}

+1 Rep for those who can help me