[Tutorial] Exiting Tram without having problem
#1

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:

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)
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!

pawn Code:
if(newkeys == KEY_SECONDARY_ATTACK)
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.

pawn Code:
new vid = GetPlayerVehicleID(playerid);
Creates a new variable which checks if player's vehicleID.

pawn Code:
if(vid == 449)
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.

pawn Code:
new Float:x, Float:y, Float:z;
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!

pawn Code:
GetPlayerPos(playerid, x, y, z);
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.

pawn Code:
SetPlayerPos(playerid, x+1, y, z);
Sets player position, with the current x, y and z. Player's x coord will be setted (+1).

pawn Code:
SetCameraBehindPlayer(playerid);
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.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)