07.06.2013, 10:25
Exiting Tram without having problems
Introduction
Have you ever try to remove a player from a tram?
And receive a message from the ejected player telling you
"My camera is stuck at the tram vehicle"
And you've to tell him to relog or respawn him. That would be waste of time.
With this short tutorial, A newbie scripter can fix this problem with some Player Pos getting and setting player pos.
Ah, for Advance Scripter, i know this is to much simple. But my main goal in this tutorial is to teach newbie scripter to fix this small problem without wasting time in searching or wasting time to eject, or respawn the player.
I'm not sure if killing the player or respawning the player while having this issue will fix the problem. So sorry if that way works better than this.
Explanation
Full Code:
-----
Explaining Part:
Well it detects if player presses any valid keys in SAMP.
newkeys - the new keys that player presses
oldkeys - the old keys that player is using before pressing the new keys!
If player presses the KEY_SECONDARY_ATTACK, it will processed the code below. For short info, It is key F or key ENTER. I'm not sure. So read the Wiki.
Creates a new variable which checks if player's vehicleID.
If the player vehicleID is 449 which is Tram. It will processed the below code. If it is not it will not processed the below code.
Creates a variable, with Float tag. If we create just a var (without tag) which is called integer it will give tag mismatch in GetPlayerPos. GetPlayerPos requires the var to have Float: tag!
Remember the var we create earlier? Which has Float tag. Now we will gonna use it to store the player's current position to the variable, which we will use it to set player's position.
Sets player position, with the current x, y and z. Player's x coord will be setted (+1).
Sets the player camera behind the player.
Note: If you spawn a car using a /car or something like a command /v and press F so fast. The camera will not set back to the player. You've to ride back to the tram again and processed the same step. Setting the camera back behind the player will take 1 second to set back behind the player.
Introduction
Have you ever try to remove a player from a tram?
And receive a message from the ejected player telling you
"My camera is stuck at the tram vehicle"
And you've to tell him to relog or respawn him. That would be waste of time.
With this short tutorial, A newbie scripter can fix this problem with some Player Pos getting and setting player pos.
Ah, for Advance Scripter, i know this is to much simple. But my main goal in this tutorial is to teach newbie scripter to fix this small problem without wasting time in searching or wasting time to eject, or respawn the player.
I'm not sure if killing the player or respawning the player while having this issue will fix the problem. So sorry if that way works better than this.
Explanation
Full Code:
pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys == KEY_SECONDARY_ATTACK)
{
new vid = GetPlayerVehicleID(playerid);
if(vid == 449)
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
SetPlayerPos(playerid, x+1, y, z);
SetCameraBehindPlayer(playerid);
}
}
return 1;
}
Explaining Part:
pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
newkeys - the new keys that player presses
oldkeys - the old keys that player is using before pressing the new keys!
pawn Code:
if(newkeys == KEY_SECONDARY_ATTACK)
pawn Code:
new vid = GetPlayerVehicleID(playerid);
pawn Code:
if(vid == 449)
pawn Code:
new Float:x, Float:y, Float:z;
pawn Code:
GetPlayerPos(playerid, x, y, z);
pawn Code:
SetPlayerPos(playerid, x+1, y, z);
pawn Code:
SetCameraBehindPlayer(playerid);
Note: If you spawn a car using a /car or something like a command /v and press F so fast. The camera will not set back to the player. You've to ride back to the tram again and processed the same step. Setting the camera back behind the player will take 1 second to set back behind the player.