Spectate pos -
mrsamp - 01.08.2012
When I stop to spectate I respawn. I want to spawn where I was when I started to spectate. Understand? :P
And if I'm in a vehicle I want back to that vehicle. :P I have no idea how to make it :P Thanks for help!
Spec and Specoff CMDS.
Код:
YCMD:spec(playerid, params[], help)
{
#pragma unused help
if(P_Data[playerid][pAdmin] < 2) return SCM(playerid, COLOR_RED, "You need to be admin level 2 to use this!");
new
pplayerid,Float:Pos[3],string[128];
if(sscanf(params, "u", pplayerid)) return SCM(playerid, COLOR_RED, "Usage: /spec [Player ID/Player Name]");
if(pplayerid == IPI) return SCM(playerid, COLOR_RED, "Wrong playerid!");
foreach(Player, i) {
if(P_Data[i][pAdmin] > 0) {
format(string,sizeof(string),"%s is spectating: %s ",GetName(playerid),GetName(pplayerid));
SCM(i,-1,string);}}
GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
SetPVarFloat(playerid,"XPos",Pos[0]);
SetPVarFloat(playerid,"YPos",Pos[1]);
SetPVarFloat(playerid,"ZPos",Pos[2]);
SetPVarInt(playerid,"Interior",GetPlayerInterior(playerid));
SetPVarInt(playerid,"VW",GetPlayerVirtualWorld(playerid));
P_Data[playerid][pSpecating] = 1;
format(string,sizeof(string),"~g~Name: ~w~%s ~g~Score: ~w~%d ~g~Money: ~w~%d",GetName(pplayerid),GetPlayerScore(pplayerid),GetPlayerMoney(pplayerid));
TextDrawSetString(Spec1[playerid],string);
TextDrawShowForPlayer(playerid,Spec1[playerid]);
TextDrawShowForPlayer(playerid,Spec0[playerid]);
if ( !IsPlayerInAnyVehicle(pplayerid) ) {
TogglePlayerSpectating(playerid, 1);
PlayerSpectatePlayer(playerid, pplayerid);
SetPlayerInterior(playerid,GetPlayerInterior(pplayerid));
SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(pplayerid));
return 1; }
else {
TogglePlayerSpectating(playerid, 1);
PlayerSpectateVehicle(playerid, GetPlayerVehicleID(pplayerid));
SetPlayerInterior(playerid,GetPlayerInterior(pplayerid));
SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(pplayerid)); }
return 1;
}
YCMD:specoff(playerid, params[], help)
{
#pragma unused help
#pragma unused params
if(P_Data[playerid][pAdmin] < 2) return SCM(playerid, COLOR_RED, "You need to be admin level 2 to use this!");
if(P_Data[playerid][pSpecating] == 0)return SCM(playerid, COLOR_RED, "You don't specate nobody!");
TogglePlayerSpectating(playerid, 0);
SetPlayerPos(playerid,GetPVarFloat(playerid,"XPos"),GetPVarFloat(playerid,"YPos"),GetPVarFloat(playerid,"ZPos"));
SetPlayerInterior(playerid,GetPVarInt(playerid,"Interior"));
SetPlayerVirtualWorld(playerid, GetPVarInt(playerid,"VW"));
SetPVarFloat(playerid,"XPos",999);
SetPVarFloat(playerid,"YPos",999);
SetPVarFloat(playerid,"ZPos",999);
SetPVarInt(playerid,"Interior",0);
SetPVarInt(playerid,"VW",0);
P_Data[playerid][pSpecating] = 0;
TextDrawHideForPlayer(playerid,Spec1[playerid]);
TextDrawHideForPlayer(playerid,Spec0[playerid]);
return 1;
}
Re: Spectate pos -
DeathOnaStick - 01.08.2012
You actually did it correctly. You used PVars to store the x-,y- and z-position of the player when he starts to spectate. In my opinion your code should work, but I would simply do it like that:
pawn Код:
YCMD:spec(playerid, params[], help)
{
#pragma unused help
if(P_Data[playerid][pAdmin] < 2) return SCM(playerid, COLOR_RED, "You need to be admin level 2 to use this!");
new
pplayerid,Float:Pos[3],string[128];
if(sscanf(params, "u", pplayerid)) return SCM(playerid, COLOR_RED, "Usage: /spec [Player ID/Player Name]");
if(pplayerid == IPI) return SCM(playerid, COLOR_RED, "Wrong playerid!");
foreach(Player, i) {
if(P_Data[i][pAdmin] > 0) {
format(string,sizeof(string),"%s is spectating: %s ",GetName(playerid),GetName(pplayerid));
SCM(i,-1,string);}}
GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
SetPVarFloat(playerid,"XPos",Pos[0]);
SetPVarFloat(playerid,"YPos",Pos[1]);
SetPVarFloat(playerid,"ZPos",Pos[2]);
SetPVarInt(playerid,"Interior",GetPlayerInterior(playerid));
SetPVarInt(playerid,"VW",GetPlayerVirtualWorld(playerid));
P_Data[playerid][pSpecating] = 1;
format(string,sizeof(string),"~g~Name: ~w~%s ~g~Score: ~w~%d ~g~Money: ~w~%d",GetName(pplayerid),GetPlayerScore(pplayerid),GetPlayerMoney(pplayerid));
TextDrawSetString(Spec1[playerid],string);
TextDrawShowForPlayer(playerid,Spec1[playerid]);
TextDrawShowForPlayer(playerid,Spec0[playerid]);
if ( !IsPlayerInAnyVehicle(pplayerid) ) {
TogglePlayerSpectating(playerid, 1);
PlayerSpectatePlayer(playerid, pplayerid);
SetPlayerInterior(playerid,GetPlayerInterior(pplayerid));
SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(pplayerid));
return 1; }
else {
TogglePlayerSpectating(playerid, 1);
PlayerSpectateVehicle(playerid, GetPlayerVehicleID(pplayerid));
SetPlayerInterior(playerid,GetPlayerInterior(pplayerid));
SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(pplayerid)); }
return 1;
}
YCMD:specoff(playerid, params[], help)
{
#pragma unused help
#pragma unused params
if(P_Data[playerid][pAdmin] < 2) return SCM(playerid, COLOR_RED, "You need to be admin level 2 to use this!");
if(P_Data[playerid][pSpecating] == 0)return SCM(playerid, COLOR_RED, "You don't spectate nobody!");
TogglePlayerSpectating(playerid, 0);
SetPlayerInterior(playerid,GetPVarInt(playerid,"Interior"));
SetPlayerVirtualWorld(playerid, GetPVarInt(playerid,"VW"));
P_Data[playerid][pSpecating] = 0;
TextDrawHideForPlayer(playerid,Spec1[playerid]);
TextDrawHideForPlayer(playerid,Spec0[playerid]);
SpawnPlayer(playerid); // I think this function exists (???)
SetPlayerPos(playerid,GetPVarFloat(playerid,"XPos"),GetPVarFloat(playerid,"YPos"),GetPVarFloat(playerid,"ZPos"));
return 1;
}
I deleted the stuff that sets the PVars to 999, because they seem useless to me here. If you need them for other parts of the script feel free to add that again. Probably more important is that SetPlayerPos is in the end and that I added SpawnPlayer to be sure that the player has spawned (although he also has to have spawned by TogglePlayerSpectating). Try that out, might possibly work.
Re: Spectate pos -
mrsamp - 02.08.2012
It didn't work. I'm still respawning when I stop spectate.
Re: Spectate pos -
DeathOnaStick - 02.08.2012
It would not be the perfect sollution, but you could also set a timer to set the players position.
A better sollution would be if there was a callback that is called when the player respawns after spectating (Probably OnPlayerSpawn? You need to test that). Then you add a PVarInt, call it something like "p_spectating". When /spec is called, you set p_spectating to 1, when /specoff is called you
dont do anything with it.
Then, when that callback is called, you need to check that PVar, whether it's 1 or 0. If it's 1 you make that SetPos stuff, if it's not, then you just proceed normally.
This will probably work.
Re: Spectate pos -
mrsamp - 02.08.2012
I'll try to fix it when I have some time over for that CMD. :P
But I don't think I'll make it. :P
Re: Spectate pos -
[MM]RoXoR[FS] - 02.08.2012
Try this
pawn Код:
YCMD:spec(playerid, params[], help)
{
#pragma unused help
if(P_Data[playerid][pAdmin] < 2) return SCM(playerid, COLOR_RED, "You need to be admin level 2 to use this!");
new pplayerid,Float:Pos[3],string[128];
if(sscanf(params, "u", pplayerid)) return SCM(playerid, COLOR_RED, "Usage: /spec [Player ID/Player Name]");
if(pplayerid == IPI) return SCM(playerid, COLOR_RED, "Wrong playerid!");
foreach(Player, i) {
if(P_Data[i][pAdmin] > 0) {
format(string,sizeof(string),"%s is spectating: %s ",GetName(playerid),GetName(pplayerid));
SCM(i,-1,string);}}
GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
SetPVarFloat(playerid,"XPos",Pos[0]);
SetPVarFloat(playerid,"YPos",Pos[1]);
SetPVarFloat(playerid,"ZPos",Pos[2]);
/* Getting vehicle of playerid*/
if(IsPlayerInAnyVehicle(playerid)) {
SetPVarInt(playerid,"vID",GetPlayerVehicleID(playerid));
SetPVarInt(playerid,"sID",GetPlayerVehicleSeat(playerid));}
else SetPVarInt(playerid,"vID",-1);
/*Done for /sped*/
SetPVarInt(playerid,"Interior",GetPlayerInterior(playerid));
SetPVarInt(playerid,"VW",GetPlayerVirtualWorld(playerid));
P_Data[playerid][pSpecating] = 1;
format(string,sizeof(string),"~g~Name: ~w~%s ~g~Score: ~w~%d ~g~Money: ~w~%d",GetName(pplayerid),GetPlayerScore(pplayerid),GetPlayerMoney(pplayerid));
TextDrawSetString(Spec1[playerid],string);
TextDrawShowForPlayer(playerid,Spec1[playerid]);
TextDrawShowForPlayer(playerid,Spec0[playerid]);
if ( !IsPlayerInAnyVehicle(pplayerid) ) {
TogglePlayerSpectating(playerid, 1);
PlayerSpectatePlayer(playerid, pplayerid);
SetPlayerInterior(playerid,GetPlayerInterior(pplayerid));
SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(pplayerid));
return 1; }
else {
TogglePlayerSpectating(playerid, 1);
PlayerSpectateVehicle(playerid, GetPlayerVehicleID(pplayerid));
SetPlayerInterior(playerid,GetPlayerInterior(pplayerid));
SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(pplayerid)); }
return 1;
}
YCMD:specoff(playerid, params[], help)
{
#pragma unused help
#pragma unused params
if(P_Data[playerid][pAdmin] < 2) return SCM(playerid, COLOR_RED, "You need to be admin level 2 to use this!");
if(P_Data[playerid][pSpecating] == 0)return SCM(playerid, COLOR_RED, "You don't specate nobody!");
TogglePlayerSpectating(playerid, 0);
SetPlayerInterior(playerid,GetPVarInt(playerid,"Interior"));
SetPlayerVirtualWorld(playerid, GetPVarInt(playerid,"VW"));
SetPlayerPos(playerid,GetPVarFloat(playerid,"XPos"),GetPVarFloat(playerid,"YPos"),GetPVarFloat(playerid,"ZPos"));
if(GetPVarInt(playerid,"vID")!= -1)
{
PutPlayerInVehicle(playerid,GetPVarInt(playerid,"vID"),GetPVarInt(playerid,"sID"));
}
SetPVarFloat(playerid,"XPos",999);
SetPVarFloat(playerid,"YPos",999);
SetPVarFloat(playerid,"ZPos",999);
SetPVarInt(playerid,"Interior",0);
SetPVarInt(playerid,"VW",0);
P_Data[playerid][pSpecating] = 0;
TextDrawHideForPlayer(playerid,Spec1[playerid]);
TextDrawHideForPlayer(playerid,Spec0[playerid]);
return 1;
}
Re: Spectate pos -
mrsamp - 02.08.2012
Nope. :S I'm still re-spawning.
Re: Spectate pos -
[MM]RoXoR[FS] - 02.08.2012
try using SetSpawnInfo(playerid,GetPVarFloat(.....);
Re: Spectate pos -
mrsamp - 02.08.2012
How?
Re: Spectate pos -
DeathOnaStick - 02.08.2012
pawn Код:
YCMD:spec(playerid, params[], help)
{
#pragma unused help
if(P_Data[playerid][pAdmin] < 2) return SCM(playerid, COLOR_RED, "You need to be admin level 2 to use this!");
new
pplayerid,Float:Pos[3],string[128];
if(sscanf(params, "u", pplayerid)) return SCM(playerid, COLOR_RED, "Usage: /spec [Player ID/Player Name]");
if(pplayerid == IPI) return SCM(playerid, COLOR_RED, "Wrong playerid!");
foreach(Player, i) {
if(P_Data[i][pAdmin] > 0) {
format(string,sizeof(string),"%s is spectating: %s ",GetName(playerid),GetName(pplayerid));
SCM(i,-1,string);}}
GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
SetPVarFloat(playerid,"XPos",Pos[0]);
SetPVarFloat(playerid,"YPos",Pos[1]);
SetPVarFloat(playerid,"ZPos",Pos[2]);
SetPVarInt(playerid,"Interior",GetPlayerInterior(playerid));
SetPVarInt(playerid,"VW",GetPlayerVirtualWorld(playerid));
P_Data[playerid][pSpecating] = 1;
format(string,sizeof(string),"~g~Name: ~w~%s ~g~Score: ~w~%d ~g~Money: ~w~%d",GetName(pplayerid),GetPlayerScore(pplayerid),GetPlayerMoney(pplayerid));
TextDrawSetString(Spec1[playerid],string);
TextDrawShowForPlayer(playerid,Spec1[playerid]);
TextDrawShowForPlayer(playerid,Spec0[playerid]);
if ( !IsPlayerInAnyVehicle(pplayerid) ) {
TogglePlayerSpectating(playerid, 1);
PlayerSpectatePlayer(playerid, pplayerid);
SetPlayerInterior(playerid,GetPlayerInterior(pplayerid));
SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(pplayerid));
return 1; }
else {
TogglePlayerSpectating(playerid, 1);
SetPVarInt(playerid, "p_spectating", 1);
PlayerSpectateVehicle(playerid, GetPlayerVehicleID(pplayerid));
SetPlayerInterior(playerid,GetPlayerInterior(pplayerid));
SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(pplayerid)); }
return 1;
}
YCMD:specoff(playerid, params[], help)
{
#pragma unused help
#pragma unused params
if(P_Data[playerid][pAdmin] < 2) return SCM(playerid, COLOR_RED, "You need to be admin level 2 to use this!");
if(P_Data[playerid][pSpecating] == 0)return SCM(playerid, COLOR_RED, "You don't spectate nobody!");
SetPlayerInterior(playerid,GetPVarInt(playerid,"Interior"));
SetPlayerVirtualWorld(playerid, GetPVarInt(playerid,"VW"));
P_Data[playerid][pSpecating] = 0;
TextDrawHideForPlayer(playerid,Spec1[playerid]);
TextDrawHideForPlayer(playerid,Spec0[playerid]);
TogglePlayerSpectating(playerid, 0);
return 1;
}
public OnPlayerSpawn(playerid){
if(GetPVarInt(playerid, "p_spectating")){
SetPlayerPos(playerid,GetPVarFloat(playerid,"XPos"),GetPVarFloat(playerid,"YPos"),GetPVarFloat(playerid,"ZPos"));
SetPVarInt(playerid, "p_spectating", 0);
return 1;
}
return 1;
}
Try this, it should work (couldn't test though, because I'm on vacation atm).