Skip to content

Commit

Permalink
Fix a bug in cmdbuffer.pwn and modify flymode.pwn
Browse files Browse the repository at this point in the history
1 - Fix OnPlayerConnect & OnPlayerCommandText Not Calling After cmdbuffer.pwn
2 - Use DynamicObjects in flymode.pwn instead of player objects ( using player objects and dynamic objects at same time will cause disappear some dynamic objects )
  • Loading branch information
erfanasbari authored Jun 11, 2020
1 parent 7bab917 commit 8669913
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
6 changes: 4 additions & 2 deletions filterscripts/tstudio/cmdbuffer.pwn
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ public OnPlayerCommandText(playerid, cmdtext[])
// Insert the command and it's parameters into the buffer
//CommandBuffer[playerid][0][0] = EOS;
format(CommandBuffer[playerid][0], 128, "%s", cmdtext);
*/

#if defined CB_OnPlayerCommandText
CB_OnPlayerCommandText(playerid, cmdtext);
#endif
*/

return 0;
}
#if defined _ALS_OnPlayerCommandText
Expand All @@ -65,11 +66,12 @@ public OnPlayerConnect(playerid)
// Reset the player's buffer
new tmpCommandBuffer[MAX_COMMAND_BUFFER][128];
CommandBuffer[playerid] = tmpCommandBuffer;
*/

#if defined CB_OnPlayerConnect
CB_OnPlayerConnect(playerid);
#endif
*/

return 1;
}
#if defined _ALS_OnPlayerConnect
Expand Down
37 changes: 29 additions & 8 deletions filterscripts/tstudio/flymode.pwn
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,27 @@ public OnPlayerConnect(playerid)

//--------------------------------------------------

public OnPlayerDisconnect(playerid, reason)
{
if(noclipdata[playerid][cameramode] == CAMERA_MODE_FLY) CancelFlyMode(playerid);

#if defined FM_OnPlayerDisconnect
FM_OnPlayerDisconnect(playerid, reason);
#endif
return 1;
}
#if defined _ALS_OnPlayerDisconnect
#undef OnPlayerDisconnect
#else
#define _ALS_OnPlayerDisconnect
#endif
#define OnPlayerDisconnect FM_OnPlayerDisconnect
#if defined FM_OnPlayerDisconnect
forward FM_OnPlayerDisconnect(playerid, reason);
#endif

//--------------------------------------------------

YCMD:flymode(playerid, arg[], help)
{
if(help)
Expand Down Expand Up @@ -209,7 +230,7 @@ public OnPlayerUpdate(playerid)
{
if((noclipdata[playerid][udold] != 0 || noclipdata[playerid][lrold] != 0) && ud == 0 && lr == 0)
{ // All keys have been released, stop the object the camera is attached to and reset the acceleration multiplier
StopPlayerObject(playerid, noclipdata[playerid][flyobject]);
StopDynamicObject(noclipdata[playerid][flyobject]);
noclipdata[playerid][mode] = 0;
noclipdata[playerid][accelmul] = 0.0;
}
Expand Down Expand Up @@ -276,7 +297,7 @@ tsfunc MoveCamera(playerid)
{
new Float:FV[3], Float:CP[3];
//GetPlayerCameraPos(playerid, CP[0], CP[1], CP[2]); // Cameras position in space
GetPlayerObjectPos(playerid, noclipdata[playerid][flyobject], CP[0], CP[1], CP[2]); // Cameras position in space
GetDynamicObjectPos(noclipdata[playerid][flyobject], CP[0], CP[1], CP[2]); // Cameras position in space
GetPlayerCameraFrontVector(playerid, FV[0], FV[1], FV[2]); // Where the camera is looking at

// Increases the acceleration multiplier the longer the key is held
Expand All @@ -288,7 +309,7 @@ tsfunc MoveCamera(playerid)
// Calculate the cameras next position based on their current position and the direction their camera is facing
new Float:X, Float:Y, Float:Z;
GetNextCameraPosition(noclipdata[playerid][mode], CP, FV, X, Y, Z);
MovePlayerObject(playerid, noclipdata[playerid][flyobject], X, Y, Z, speed);
MoveDynamicObject(noclipdata[playerid][flyobject], X, Y, Z, speed, 0.0, 0.0, 0.0);

//SendClientMessage(playerid, -1, sprintf("(%0.1f, %0.1f, %0.1f) - (%0.1f, %0.1f, %0.1f) - (%0.1f, %0.1f, %0.1f)", CP[0], CP[1], CP[2], FV[0], FV[1], FV[2], X, Y, Z));

Expand All @@ -301,7 +322,7 @@ tsfunc SetFlyModePos(playerid, Float:x, Float:y, Float:z)
{
if(FlyMode[playerid])
{
SetPlayerObjectPos(playerid, noclipdata[playerid][flyobject], x, y, z);
SetDynamicObjectPos(noclipdata[playerid][flyobject], x, y, z);
noclipdata[playerid][lastmove] = GetTickCount();
return 1;
}
Expand All @@ -311,7 +332,7 @@ tsfunc GetFlyModePos(playerid, &Float:x, &Float:y, &Float:z)
{
if(FlyMode[playerid])
{
GetPlayerObjectPos(playerid, noclipdata[playerid][flyobject], x, y, z);
GetDynamicObjectPos(noclipdata[playerid][flyobject], x, y, z);
return 1;
}
return 0;
Expand Down Expand Up @@ -391,7 +412,7 @@ tsfunc CancelFlyMode(playerid)
CancelEdit(playerid);
TogglePlayerSpectating(playerid, false);

DestroyPlayerObject(playerid, noclipdata[playerid][flyobject]);
DestroyDynamicObject(noclipdata[playerid][flyobject]);
noclipdata[playerid][cameramode] = CAMERA_MODE_NONE;
return 1;
}
Expand All @@ -406,12 +427,12 @@ tsfunc StartFlyMode(playerid)
// Create an invisible object for the players camera to be attached to
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
noclipdata[playerid][flyobject] = CreatePlayerObject(playerid, 19300, X, Y, Z, 0.0, 0.0, 0.0);
noclipdata[playerid][flyobject] = CreateDynamicObject(19300, X, Y, Z, 0.0, 0.0, 0.0, .playerid = playerid, .streamdistance = 300.0, .drawdistance = 300.0);

// Place the player in spectating mode so objects will be streamed based on camera location
TogglePlayerSpectating(playerid, true);
// Attach the players camera to the created object
AttachCameraToPlayerObject(playerid, noclipdata[playerid][flyobject]);
AttachCameraToDynamicObject(playerid, noclipdata[playerid][flyobject]);

FlyMode[playerid] = true;
noclipdata[playerid][cameramode] = CAMERA_MODE_FLY;
Expand Down

0 comments on commit 8669913

Please sign in to comment.