Exiting Tram without having problem -
JaKe Elite - 07.06.2013
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.
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.
Re: Exiting Tram without having problem -
Guest123 - 07.06.2013
nice tut
Re: Exiting Tram without having problem -
JaKe Elite - 07.06.2013
thanks
Re: Exiting Tram without having problem -
Sulps - 07.06.2013
Very Very Usefull
![Cheesy](images/smilies/biggrin.png)
And Briefly Explained
Now that's what i call a Tutorial
Re: Exiting Tram without having problem -
Tingesport - 07.06.2013
Useful & Simple, awesome Jake!
Re: Exiting Tram without having problem -
cotyzor - 07.06.2013
Nice tutorial, simple, but nice!
Re: Exiting Tram without having problem -
Henkie - 11.06.2013
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.
Re: Exiting Tram without having problem -
Lordzy - 11.06.2013
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.
AW: Exiting Tram without having problem -
HurtLocker - 11.06.2013
Henkie has got a point. Concerning the script, very usefull.
Re: Exiting Tram without having problem -
JaKe Elite - 12.06.2013
Thanks for feedback
Re: Exiting Tram without having problem -
Henkie - 12.06.2013
Quote:
Originally Posted by _Jake_
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!
Re: Exiting Tram without having problem -
JaKe Elite - 12.06.2013
it's working for me. well did you test it??
Re: Exiting Tram without having problem -
DeathKing - 12.06.2013
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
Re: Exiting Tram without having problem -
Pasa - 12.06.2013
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.
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)
Re: Exiting Tram without having problem -
BGTrucker - 10.06.2014
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.
Re: Exiting Tram without having problem -
BGTrucker - 10.06.2014
damn,sorry for double post