SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 17/05/2015, 10:52 PM   #1
Dokins
Banned
 
Join Date: Jun 2010
Posts: 1,648
Reputation: 53
Default About TogglePlayerSpectating/OnPlayerSpawn/Logging in.

Hi there,

I'm aware that TogglePlayerSpectating calls OnPlayerSpawn, it's causing me a bit of a headache working out what I can do here, because it seems to be getting my health wrong and knocking me unconscious in the game.

I'm using it to remove the *SPAWN* button, I'm using TogglePlayerSpectating(playerid, 1) on OnPlayerConnect and trying to remove it when spawning the player.

As TogglePlayerSpectating calls OnPlayerSpawn and I'm using SpawnPlayer, I'm getting confused, and again, it's causing the character to get the wrong health or the sorts. I'm not sure why.

KNOCKOUT SYSTEM UNDER ONPLAYERUPDATE.
pawn Code:
new Float:health;
    GetPlayerHealth(playerid,health);

    if(LoggedIn[playerid] == 1 && health <= 40 && KnockedOut[playerid] == 0)
    {
        KnockedOut[playerid] = 1;
        ApplyAnimation(playerid, "CRACK", "crckdeth2", 4.0, 1, 0, 0, 0, 0,1);
        TextDrawShowForPlayer(playerid,BFText);

        new string[128];
        format(string, sizeof(string), "* %s has lost consciousness due to their injuries *", GetNameEx(playerid));
        ProxDetector(30.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
    }
LOGIN DIALOG.
pawn Code:
if(dialogid == DIALOG_LOGIN)
    {
        if(response == 0)
        {
            Kick(playerid);
        }
        else
        {
            new query[512], password[256];
            new buf[129];
            WP_Hash(buf, sizeof(buf), inputtext);
            format(query, sizeof(query), "SELECT `Password` FROM `accounts` WHERE id = %d", PlayerSQLID[playerid]);
            mysql_query(query);
            mysql_store_result();
            mysql_fetch_row(password);
            mysql_free_result();
            new string[300];
            format(string, sizeof(string), "Welcome to %s\n\nYou entered a wrong password, please try again:", HOSTNAME);
            if(isnull(inputtext))return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Please retry your password", string, "Login", "Leave");
            if(strcmp(password, buf, false) == 0)
            {
                SetPlayerHealth(playerid, 100);
                LoggedIn[playerid] = 1;
                LoadAccount(playerid);
                new skin = GetPlayerSkinEx(playerid);
                SetSpawnInfo(playerid, 0, skin,-2802.0896,1183.8734,20.2734,170.2243, 0,0,0,0,0,0);
                PlayerBanned[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "Banned", "accounts");

                SpawnPlayer(playerid);
                SetCameraBehindPlayer(playerid);

                GivePlayerWeaponEx(playerid);
                AutoSaveTimer[playerid] = SetTimerEx("WeaponSaveTimer", 60000, true,"i", playerid);
                Streamer_Update(playerid);
                new playerip[16];
                for(new h = 0; h < MAX_HOUSES; h++)
                {
                    if(HouseOwner[h] == PlayerSQLID[playerid] && BreachedOff[h] == 1)
                    {
                        format(string, sizeof(string), ""COL_RED"ALERT"COL_WHITE": Your owned property, %s, detected a perimeter breach when you were offline.", HouseName[h]);
                        SendClientMessage(playerid, COLOUR_WHITE, string);
                        BreachedOff[h] = 0;
                        MySQL_SetInteger(h, "BreachedOff", 0, "houses");
                       
                    }
                }
                   

                format(query, sizeof(query), "SELECT * FROM `bans` WHERE `ip` = '%s'", playerip);
                mysql_query(query);
                mysql_store_result();

                if(WasDead[playerid] == 1)
                {
                    new string2[128];
                    format(string2, sizeof(string2), "You have been automatically admin jailed for 60 minutes, Reason: logging to avoid death.");
                    SendClientMessage(playerid, COLOUR_LIGHTBLUE, string2);
                   
                    format(string2, sizeof(string2), "[Auto-Jail]%s has been admin jailed [Reason: Logging to avoid death.]", GetNameEx(playerid));
                    SendClientMessageToAll(COLOUR_LIGHTBLUE, string2);

                    AdminJail[playerid] += 60;
                    SetPlayerPos(playerid, 264.58, 77.38, 1001.04);
                    SetPlayerInterior(playerid, 6);
                    SetPlayerVirtualWorld(playerid, 0);
                    MySQL_SetInteger(PlayerSQLID[playerid], "AdminJail",AdminJail[playerid], "accounts");
                    MySQL_SetInteger(PlayerSQLID[playerid], "WasDead", 0, "accounts");

                   
                    WasDead[playerid] = 0;
                }

                if(AdminJail[playerid] >= 1)
                {
                    new string2[128];
                    format(string2, sizeof(string2), "You have %d minute(s) left in Admin Jail.", AdminJail[playerid]);
                    SendClientMessage(playerid, COLOUR_GREY, string2);

                    SetPlayerPos(playerid, 264.58, 77.38, 1001.04);
                    SetPlayerInterior(playerid, 6);
                    SetPlayerVirtualWorld(playerid, 0);
                }
                if(Jail[playerid] >= 1)
                {
                    SetPlayerPos(playerid, 319.5663,311.9558,999.1484);
                    SetPlayerInterior(playerid, 5);
                    SetPlayerVirtualWorld(playerid, 0);
                   
                    new string2[128];
                    format(string2, sizeof(string2), "You still have %d minute(s) of jail time to serve.", Jail[playerid]);
                    SendClientMessage(playerid, COLOUR_GREY, string2);
                }

                new param1[64], param2[64];
                if(Faction[playerid] == 0) {
                    param1 = "Civilian (0)";
                    param2 = "N/A";
                }
                else {
                    strcpy(param1, FactionName[Faction[playerid]], sizeof(param1));
                    switch(FRank[playerid]) { // strcpy(dest, source, length);
                        case 1: strcpy(param2, FactionRank1[Faction[playerid]], sizeof(param2));
                        case 2: strcpy(param2, FactionRank2[Faction[playerid]], sizeof(param2));
                        case 3: strcpy(param2, FactionRank3[Faction[playerid]], sizeof(param2));
                        case 4: strcpy(param2, FactionRank4[Faction[playerid]], sizeof(param2));
                        case 5: strcpy(param2, FactionRank5[Faction[playerid]], sizeof(param2));
                        case 6: strcpy(param2, FactionRank6[Faction[playerid]], sizeof(param2));
                        case 7: strcpy(param2, FactionRank7[Faction[playerid]], sizeof(param2));
                        }
                    }
                format(string, sizeof(string), "Welcome back to San Fierro Roleplay, %s. Level: %d | Money: $%s | Admin Level: %d | Donator Level %d |", GetNameEx(playerid), PlayerLevel[playerid],AddCommas(PlayerMoney[playerid]), AdminLevel[playerid], Donator[playerid]);
                SendClientMessage(playerid, 0xFFD99FFF, string);
                format(string, sizeof(string), "Faction Name: %s | Faction Rank: %s (%d) | Rank Pay: $%s |", param1, param2, FRank[playerid], AddCommas(GetRankPay(playerid)));
                SendClientMessage(playerid, 0xFFD99FFF, string);
                format(string, sizeof(string), "Misc: Total Time Played (minutes): %d | Total House Break Ins: %d | Total Vehicle Break Ins: %d | Total Hotwires %d | Kills %d | Deaths %d |", TotalTime[playerid], TotalHouseBI[playerid], TotalVehBI[playerid], TotalHotwires[playerid], PlayerKills[playerid], PlayerDeaths[playerid]);
                SendClientMessage(playerid,0xFFD99FFF, string);
                format(string, sizeof(string), "Skills: Thief Level: %d | Crafting Level: %d", ThiefLevel[playerid], CraftingLevel[playerid]);
                SendClientMessage(playerid,0xFFD99FFF, string);


            }
            else
            {
                format(string, sizeof(string), "Welcome to %s\n\nYou entered a wrong password, please try again:", HOSTNAME);
                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Please retry your password", string, "Login", "Leave");
            }
        }
    }

Could someone tell me where I should use TogglePlayerSpectating(playerid, 0) and it should not affect that system?

I'm assuming it should be under the dialog.

Thanks,
Grant.
Dokins is offline   Reply With Quote
Old 18/05/2015, 10:26 AM   #2
Dokins
Banned
 
Join Date: Jun 2010
Posts: 1,648
Reputation: 53
Default Re: About TogglePlayerSpectating/OnPlayerSpawn/Logging in.

Still unresolved.
Dokins is offline   Reply With Quote
Old 18/05/2015, 12:30 PM   #3
aCloudy
Big Clucker
 
Join Date: Apr 2014
Posts: 188
Reputation: 2
Default Re: About TogglePlayerSpectating/OnPlayerSpawn/Logging in.

Quote:
Originally Posted by Dokins View Post
Still unresolved.
Okay, I noticed that you are using "TogglePlayerSpectating(playerid, 1);" on "OnPlayerSpawn", But "OnPlayerSpawn" is used for SpawnPlayer function or when you click the Spawn button.
You must put "TogglePlayerSpectating(playerid, 1);" under OnPlayerConnect.
Then, At the register/login dialog response, Add "TogglePlayerSpectating(playerid, 0);" to display the "Spawn" button for the player.

There is another way, If you don't want to hide the Spawn button, You can simply disable it:
Code:
public OnPlayerRequestClass(playerid, classid)
{
	if(LoggedIn[playerid] != 1)
	{
		return 0;
	}
	return 1;
}
MODIFICATION: It is wrong to put TogglePlayerSpectating under "OnPlayerRequestClass", Because the function that gets called when you die after clicking F4 is OnPlayerRequestClass.
So, Add TogglePlayerSpectating(playerid, 1) under OnPlayerConnect ONLY!
aCloudy is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TogglePlayerSpectating Sarra Scripting Help 1 21/08/2014 03:12 PM
TogglePlayerSpectating() Dreamerzzz Русский/Russian 3 18/08/2014 09:17 PM
[HELP] toggleplayerspectating Luca12 Scripting Help 7 31/01/2014 11:30 PM
TogglePlayerSpectating - What can I do? dcmd_crash Help Archive 1 09/05/2010 09:45 AM


All times are GMT. The time now is 07:16 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.