[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
#2

nice tut
Reply
#3

thanks
Reply
#4

Very Very Usefull
And Briefly Explained
Now that's what i call a Tutorial
Reply
#5

Useful & Simple, awesome Jake!
Reply
#6

Nice tutorial, simple, but nice!
Reply
#7

Did you test this script? I think it won't work since you're checking for the vehicle id and not the vehicle model id.
Reply
#8

You've explained very well. Though, it would be more better if 'OnPlayerStateChange' is being called in this situation and then freezing (TogglePlayerControllable) and unfreezing quickly to prevent the stuck. Setting the camera behind is also a better idea, but I'd choose cam setting and toggling player's control because SetPlayerPos looks like some changes has been happened.
Reply
#9

Henkie has got a point. Concerning the script, very usefull.
Reply
#10

Thanks for feedback
Reply
#11

Quote:
Originally Posted by _Jake_
View Post
Thanks for feedback
Then use my feedback and fix the problem. If you want to help people with tutorials, your tutorials should be correct and working!
Reply
#12

it's working for me. well did you test it??
Reply
#13

this can be optimized better......... but i don't think this would work either... why not use OnPlayerExitVehicle
then get its vehicle id after that get its position then set player pos....... +1 on x or y not sure but i think this is better or this is better i don't know
Reply
#14

i have just 1 thing to say and that is why to check every vehicle id when you can check the vehicle model

Quote:
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.

fix:


Code:
new vid = GetPlayerVehicleID(playerid);
if(GetVehicleModel(vid) ==  449)
Reply
#15

Sorry for bumping the topic but I just found an easier way to exit the tram without having the camera problem.Here is the code which has to be added to OnPlayerStateChange callback:
pawn Code:
if(oldstate == PLAYER_STATE_DRIVER || PLAYER_STATE_PASSENGER) if(GetVehicleModel(vid) == 449) SetCameraBehindPlayer(playerid);
Also I noticed another bug with trains,and especially Freight(the cargo train): when exiting a cargo train,the player gets stuck inside the train.I'll be thankful if someone comes up with a fix.
Reply
#16

damn,sorry for double post
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)