Help with spectation
#1

Hi all. Need help with spectation. Command works ok, but when I wana stop spectation, system returns me to bad position ( system have to return me to my last positon, but returns to my login positon, where I loged last time ). Why?

Код:
CMD:spec(playerid,params[])
{
	if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING) return StopSpec(playerid);
	new id;
        if(sscanf(params, "u", id)) return SendError(playerid,"Use: /spec [ID]");
	new mess[80 + MAX_PLAYER_NAME];
 	SpectatingIS(playerid);
	SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(id));
	SetPlayerInterior(playerid, GetPlayerInterior(id));
	TogglePlayerSpectating(playerid, true);
	if(IsPlayerInAnyVehicle(id)) PlayerSpectateVehicle(playerid, GetPlayerVehicleID(id));
	else PlayerSpectatePlayer(playerid, id);
	return 1;
}
Код:
stock SpectatingIS(playerid)
{
        statec[playerid] = true;
	GetPlayerPos(playerid, krd[playerid][0], krd[playerid][1], krd[playerid][2]);
	pInfo[playerid][world] = GetPlayerVirtualWorld(playerid);
	for(new slot = 0; slot < 13; slot ++) GetPlayerWeaponData(playerid,slot,weaps[playerid]
        [slot],amunition[playerid][slot]);
	pInfo[playerid][interior] = GetPlayerInterior(playerid);
	return 1;
}
Код:
stock StopSpec(playerid)
{
        statec[playerid] = true;
        SetPlayerPos(playerid, krd[playerid][0], krd[playerid][1], krd[playerid][2]);
        SetPlayerVirtualWorld(playerid, pInfo[playerid][world]);
	SetPlayerInterior(playerid,pInfo[playerid][interior]);
	TogglePlayerSpectating(playerid,false);
	if(pInfo[playerid][ant] == false) TogglePlayerControllable(playerid,true);
	for(new slot=0; slot < 13; slot++) GivePlayerWeaponEx(playerid,weaps[playerid][slot], amunition[playerid]
        [slot]);
	return 1;
}
Reply
#2

PHP код:
SetPlayerPos(playeridkrd[playerid][0], krd[playerid][1], krd[playerid][2]); 
Have you tried that?
Reply
#3

Quote:
Originally Posted by aoky
Посмотреть сообщение
PHP код:
SetPlayerPos(playeridkrd[playerid][0], krd[playerid][1], krd[playerid][2]); 
Have you tried that?
Yes. When I wrote in forum, I did mistake. Actually, I use this line, but the same bug... : /
Reply
#4

Because you set the player position before you toogle of his/her spectating.

Код:
stock StopSpec(playerid)
{
        statec[playerid] = true;
        SetSpawnInfo(playerid, 0, skin, krd[playerid][0], krd[playerid][1], krd[playerid][2], 0.0, 0, 0, 0, 0, 0, 0);
	TogglePlayerSpectating(playerid,false);
	SetPlayerVirtualWorld(playerid, pInfo[playerid][world]);
	SetPlayerInterior(playerid,pInfo[playerid][interior]);
	if(pInfo[playerid][ant] == false) TogglePlayerControllable(playerid,true);
	for(new slot=0; slot < 13; slot++) GivePlayerWeaponEx(playerid,weaps[playerid][slot], amunition[playerid]
        [slot]);
	return 1;
}
I don't know whether you use team, or not, and don't know your name of skin variable, but you can change it. Only I have done I added the SetSpawnInfo function before the TogglePlayerSpectating, and swaped some code. It has to work.
Reply
#5

try this

PHP код:
new FloatPlayerPosX[MAX_PLAYERS], FloatPlayerPosY[MAX_PLAYERS], Float:PlayerPosZ[MAX_PLAYERS];//AT top
CMD:spec(playerid,params[])
{
    new 
Float:xFloat:yFloat:z;
    if(
GetPlayerState(playerid) == PLAYER_STATE_SPECTATING) return StopSpec(playerid);
    new 
id;
    if(
sscanf(params"u"id)) return SendError(playerid,"Use: /spec [ID]");
    new 
mess[80 MAX_PLAYER_NAME];
    
GetPlayerPos(playeridxyz);
    
SpectatingIS(playerid);
    
PlayerPosX[playerid] = x;
    
PlayerPosY[playerid] = y;
    
PlayerPosZ[playerid] = z;
    
SetPlayerVirtualWorld(playeridGetPlayerVirtualWorld(id));
    
SetPlayerInterior(playeridGetPlayerInterior(id));
    
TogglePlayerSpectating(playeridtrue);
    if(
IsPlayerInAnyVehicle(id)) PlayerSpectateVehicle(playeridGetPlayerVehicleID(id));
    else 
PlayerSpectatePlayer(playeridid);
    return 
1;
}
stock StopSpec(playerid)
{
    
statec[playerid] = true;
    
SetPlayerPos(playeridPlayerPosX[playerid], PlayerPosY[playerid], PlayerPosZ[playerid]);
    
SetPlayerVirtualWorld(playeridpInfo[playerid][world]);
    
SetPlayerInterior(playerid,pInfo[playerid][interior]);
    
TogglePlayerSpectating(playerid,false);
    if(
pInfo[playerid][ant] == falseTogglePlayerControllable(playerid,true);
    for(new 
slot=0slot 13slot++) GivePlayerWeaponEx(playerid,weaps[playerid][slot], amunition[playerid][slot]);
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)