Spawn Help
#1

Ok here is what i have in my script this is the first time im doing this lots of tutorials and shit. i finally got mysql working and getting logins but now i get this screen when i click spawn





What i ultimately wanted was something that checked if Mysql had position and if did spawn at that x,y,z if not spawn in one spot say pershing square.
and help with this would be awesome
Код:
//============================================================================//
//                                  Includes                                  //
//============================================================================//

#include <a_samp>
#include <zcmd>
#include <sscanf2>
#include <foreach>
#include <a_mysql>

//============================================================================//
//                                  Define s                                  //
//============================================================================//

#define SERVER_NAME     "Tron Freeroam"
#define SERVER_TIME     "12"
#define SERVER_GRAVITY  "0.00800"
#define SERVER_MAP      "Tron's World"
#define SERVER_WEBSITE  "www.yoursite.com"

#define SQL_HOST "******"
#define SQL_USER "Tron"
#define SQL_PASS "*****"
#define SQL_DB 	 "database"

#define Blue    "{003DF5}"
#define Red     "{FF0000}"
#define Green   "{66FF00}"
#define White   "{FFFFFF}"

#define DIALOG_REGISTER         100
#define DIALOG_LOGIN            101
#define DIALOG_POS              102


//============================================================================//
//                                  New's                                     //
//============================================================================//

enum pInfo
{
    pScore,
    pMoney,
    pLevel,
    pVIP,
    pKMA,
    pRank,
    pKills,
    pDeaths,
    pMuted,
    pJailed,
    pFrozen,
    pMutedTimes,
    pJailedTimes,
    pFrozenTimes,
    pBanned,
    pBannedBy[24],
    pLogins,
    pCookies,
    Float:pPosX,
    Float:pPosY,
    Float:pPosZ,
    Float:pPosA
}
new God[MAX_PLAYERS] = 0;
new PlayerInfo[MAX_PLAYERS][pInfo];
new MoneyGiven[MAX_PLAYERS];
new IsRegistered[MAX_PLAYERS];
new Logged[MAX_PLAYERS];
new JustLogged[MAX_PLAYERS];
new Text:Textdraw1;

//============================================================================//
//                                  Forwards                                  //
//============================================================================//

forward  	HideMessage1(playerid);

//============================================================================//
//                                  Main                                      //
//============================================================================//

main()
{
	print("\n----------------------------------");
	print("  Tron Freeroam\n");
	print("----------------------------------\n");
}


//============================================================================//
//                                  Publics                                   //
//============================================================================//
public OnGameModeInit()
{
	SetGameModeText("Tron Freeroam");
	ShowPlayerMarkers(1);
	ShowNameTags(1);
	AllowAdminTeleport(1);
	EnableStuntBonusForAll(0);
	Textdraw1 = TextDrawCreate(13.000000, 150.000000, "First Message");
	TextDrawBackgroundColor(Textdraw1, 255);
	TextDrawFont(Textdraw1, 1);
	TextDrawLetterSize(Textdraw1, 0.370000, 1.100000);
	TextDrawColor(Textdraw1, -1);
	TextDrawSetOutline(Textdraw1, 0);
	TextDrawSetProportional(Textdraw1, 1);
	TextDrawSetShadow(Textdraw1, 1);
	TextDrawUseBox(Textdraw1, 1);
	TextDrawBoxColor(Textdraw1, 255);
	TextDrawTextSize(Textdraw1, 278.000000, 36.000000);

	new stuff[128];

	format(stuff, 128, "hostname %s", SERVER_NAME);
	SendRconCommand(stuff);
	
	format(stuff, 128, "mapname %s", SERVER_MAP);
	SendRconCommand(stuff);

	format(stuff, 128, "worldtime %s", SERVER_WEBSITE);
	SendRconCommand(stuff);
	
	SetGameModeText("Trons Freeroam");
	

    //================================================================//
    //                              MySQL part                        //
    //================================================================//
    mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
    mysql_query("CREATE TABLE IF NOT EXISTS playerdata(user VARCHAR(24), password VARCHAR(40), score INT(20), money INT(20), level INT(20), vip INT(20), kma INT(20), rank INT(20), kills INT(20), deaths INT(20), muted INT(20), jailed INT(20), frozen INT(20), mutedtimes INT(20), jailedtimes INT(20), frozentimes INT(20), banned INT(20), bannedby VARCHAR(24), logins INT(20), posx INT(20), posy INT(20), posz INT(20), posa INT(20), IP VARCHAR(15) )");
    mysql_debug(1);
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    //================================================================//
    //                              MySQL part                        //
    //================================================================//
    if(!Logged[playerid])
    {
        if(!IsRegistered[playerid])
        {
            ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""Blue"Please register",""White"Welcome to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to register!\n\n"White"Please insert a password below:", "Register", "Cancel");
            return 0;
        }
        if(IsRegistered[playerid] == 1)
        {
            ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""Blue"Please log-in", ""White"Welcome back to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to log-in!\n\n"White"Please insert "Red"your"White" password below:", "Login", "Cancel");
            return 0;
        }
    }
    return 1;
}


public OnPlayerSpawn(playerid)
{
	
	
	SetPlayerPos(playerid, -973.6733, 1061.2589, 1345.6721);
	SetPlayerInterior(playerid, 0);
	SetPlayerFacingAngle(playerid, 85.6553);
	SendMessage(playerid, "~g~Info: ~w~Position loaded!");
	
	
    //================================================================//
    //                              MySQL part                        //
    //================================================================//
    if(MoneyGiven[playerid] != -1)
    {
        GivePlayerMoney(playerid, MoneyGiven[playerid]);
        MoneyGiven[playerid] = -1;
    }
    if(JustLogged[playerid] == 1)
    {
    	JustLogged[playerid] = 0;
	}
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    if(God[playerid] == 1)
    {
        God[playerid] = 0;
        return 1;
    }
	return 1;
}



public OnPlayerConnect(playerid)
{
    GameTextForPlayer(playerid,"~w~SA-MP: ~r~Tron Freeroam",15000,5);
    RemoveUnderScore(playerid);
    TextDrawHideForPlayer(playerid, Textdraw1);
    //================================================================//
    //                              MySQL part                        //
    //================================================================//
    MoneyGiven[playerid] = -1;
    JustLogged[playerid] = 0;
    new query[300], pname[24];
    GetPlayerName(playerid, pname, 24);
    format(query, sizeof(query), "SELECT IP FROM `playerdata` WHERE user = '%s' LIMIT 1", pname);
    mysql_query(query);
    mysql_store_result();
    new rows = mysql_num_rows();
    if(!rows)
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""Blue"Please register",""White"Welcome to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to register!\n\n"White"Please insert a password below:", "Register", "Cancel");
    }
    if(rows == 1)
    {
        new IP[2][15];
        mysql_fetch_field_row(IP[0],"IP");
        GetPlayerIp(playerid, IP[1], 15);
        if(strlen(IP[0]) != 0 && !strcmp(IP[0], IP[1], true))
        {
            MySQL_Login(playerid);
        }
        else if(!strlen(IP[0]) || strcmp(IP[0], IP[1], true))
        {
            ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""Blue"Please log-in", ""White"Welcome back to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to log-in!\n\n"White"Please insert "Red"your"White" password below:", "Login", "Cancel");
            IsRegistered[playerid] = 1;
        }
    }
    mysql_free_result();
    return 1;
}


public OnPlayerDisconnect(playerid, reason)
{
    //================================================================//
    //                              MySQL part                        //
    //================================================================//
    if(Logged[playerid] == 1)
    {
        new Float:x, Float:y, Float:z, Float:a;
        GetPlayerPos(playerid, x, y, z);
        GetPlayerFacingAngle(playerid, a);
        PlayerInfo[playerid][pPosX] = x;
        PlayerInfo[playerid][pPosY] = y;
        PlayerInfo[playerid][pPosZ] = z;
        PlayerInfo[playerid][pPosA] = a;
        new score = GetPlayerScore(playerid);
        new money = GetPlayerMoney(playerid);
        new query[350], pname[24];
        GetPlayerName(playerid, pname, 24);
        format(query, sizeof(query), "UPDATE playerdata SET score=%d, money=%d, level=%d, vip=%d, kma=%d, rank=%d, kills=%d, deaths=%d, muted=%d, jailed=%d, frozen=%d, mutedtimes=%d, jailedtimes=%d, frozentimes=%d, banned=%d, bannedby='%s', logins=%d, posx=%f, posy=%f, posz=%f, posa=%f  WHERE user='%s'",
		score,
		money,
		PlayerInfo[playerid][pLevel],
		PlayerInfo[playerid][pVIP],
		PlayerInfo[playerid][pKMA],
		PlayerInfo[playerid][pRank],
		PlayerInfo[playerid][pKills],
		PlayerInfo[playerid][pDeaths],
		PlayerInfo[playerid][pMuted],
		PlayerInfo[playerid][pJailed],
		PlayerInfo[playerid][pFrozen],
		PlayerInfo[playerid][pMutedTimes],
		PlayerInfo[playerid][pJailedTimes],
		PlayerInfo[playerid][pFrozenTimes],
		PlayerInfo[playerid][pBanned],
		PlayerInfo[playerid][pBannedBy],
		PlayerInfo[playerid][pLogins],
  		PlayerInfo[playerid][pPosX],
        PlayerInfo[playerid][pPosY],
        PlayerInfo[playerid][pPosZ],
        PlayerInfo[playerid][pPosA],
		pname);
        mysql_query(query);
    }
    return 1;
}


public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{

	//================================================================//
    //                              MySQL part                        //
    //================================================================//
    if(dialogid == DIALOG_REGISTER)
    {
        if(response)
        {
            if(!strlen(inputtext) || strlen(inputtext) > 100)
            {
            	SendMessage(playerid, "~r~Error: ~w~You must insert a password between 1-100 characters!");
                ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""Blue"Please register",""White"Welcome to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to register!\n\n"White"Please insert a password below:", "Register", "Cancel");
            }
            else if(strlen(inputtext) > 0 && strlen(inputtext) < 100)
            {
                new escpass[100];
                mysql_real_escape_string(inputtext, escpass);
                MySQL_Register(playerid, escpass);
            }
        }
        if(!response)
        {
        		SendMessage(playerid, "~r~Error: ~w~You must register before logging in!");
                ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""Blue"Please register",""White"Welcome to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to register!\n\n"White"Please insert a password below:", "Register", "Cancel");
        }
    }
    if(dialogid == DIALOG_LOGIN)
    {
        if(!response)
        {
                SendMessage(playerid, "~r~Error: ~w~You must login before you spawn!");
                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""Blue"Please log-in", ""White"Welcome back to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to log-in!\n\n"White"Please insert "Red"your"White" password below:", "Login", "Cancel");
        }
        if(response)
        {
            new query[200], pname[24], escapepass[100];
            GetPlayerName(playerid, pname, 24);
            mysql_real_escape_string(inputtext, escapepass);
            format(query, sizeof(query), "SELECT `user` FROM playerdata WHERE user = '%s' AND password = SHA1('%s')", pname, escapepass);
            mysql_query(query);
            mysql_store_result();
            new numrows = mysql_num_rows();
            if(numrows == 1) MySQL_Login(playerid);
            if(!numrows)
            {
                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""Blue"Please log-in", ""White"Welcome back to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to log-in!\n\n"White"Please insert "Red"your"White" password below:", "Login", "Cancel");
                SendMessage(playerid, "~r~Error: ~w~Incorrect password!");
            }
            mysql_free_result();
        }
    }
    return 1;
}


//============================================================================//
//                                  Player Commands                           //
//============================================================================//

CMD:savepossition(playerid, params[])
{
	new Float:x, Float:y, Float:z, Float:a;
 	GetPlayerPos(playerid, x, y, z);
 	GetPlayerFacingAngle(playerid, a);
 	PlayerInfo[playerid][pPosX] = x;
 	PlayerInfo[playerid][pPosY] = y;
 	PlayerInfo[playerid][pPosZ] = z;
 	PlayerInfo[playerid][pPosA] = a;
 	SendMessage(playerid, "~g~Info: ~w~Possition saved!");
 	return 1;
}

CMD:sp(playerid, params[])
{
	return cmd_savepossition(playerid, params);
}

CMD:loadpossition(playerid, params[])
{
	SetPlayerPos(playerid, PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ]);
	SetPlayerFacingAngle(playerid, PlayerInfo[playerid][pPosA]);
	SendMessage(playerid, "~g~Info: ~w~Position loaded!");
	return 1;
}

CMD:lp(playerid, params[])
{
	return cmd_loadpossition(playerid, params);
}

CMD:kill(playerid, params[])
{
	SetPlayerHealth(playerid, 0.0);
	return 1;
}

CMD:help(playerid, params[])
{
    SendClientMessage(playerid, 0xFFFF00AA, "HELP: /help, /skin, /kill, /radio");
	return 1;
}

CMD:god(playerid, params[])
{
    if (God[playerid] == 1)
        {
            SendClientMessage(playerid, 0xFF0000FF, "You have disabled god mode.");
		    SetPlayerHealth(playerid, 100);
            SetPlayerArmour(playerid, 100);
            God[playerid] = 0;
            return 1;
        }
        else if(God[playerid] == 0)
        {
            SendClientMessage(playerid, 0x33AA33AA, "You have enabled god mode.");
			God[playerid] = 1;
            SetPlayerArmour(playerid, 9999999);
            SetPlayerHealth(playerid, 9999999);
            return 1;
        }
    return 1;
}

CMD:radio(playerid, params[])
{
		SendClientMessage(playerid, 0xFFFF00AA, "Radio: /radiorap, /radiohg, /radiodnb, /radiojazz");
		return 1;
}
CMD:radiohg(playerid, params[])
{
    PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=98600");
	return 1;
}

//============================================================================//
//                                  Admin Commands                            //
//============================================================================//



//============================================================================//
//                                  Stocks /  Publics                         //
//============================================================================//

public HideMessage1(playerid)
{
	TextDrawHideForPlayer(playerid, Textdraw1);
	return 1;
}

stock RemoveUnderScore(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    for(new i = 0; i < MAX_PLAYER_NAME; i++)
    {
        if(name[i] == '_') name[i] = ' ';
    }
    return name;
}

stock SendMessage(playerid, message[])
{
	TextDrawHideForPlayer(playerid, Textdraw1);
	TextDrawSetString(Textdraw1, message);
	TextDrawShowForPlayer(playerid, Textdraw1);
	SetTimer("HideMessage1", 5000, false);
	return 1;
}



stock ErrorMessage(playerid, message[])
{
	new string[128];
	format(string, sizeof string, ""Red"[Error] "White"%s", message);
	SendClientMessage(playerid, -1, string);
	return 1;
}

stock MySQL_Register(playerid, passwordstring[])
{
    new query[350], pname[24], IP[15];
    new Bannedby[20];
    format(Bannedby, 20, "Not Banned");
    GetPlayerName(playerid, pname, 24);
    GetPlayerIp(playerid, IP, 15);
    format(query, sizeof(query), "INSERT INTO playerdata (user, password, score, money, level, vip, kma, rank, kills, deaths, muted, jailed, frozen, mutedtimes, jailedtimes, frozentimes, banned, bannedby, logins, posx, posy, posz, posa, IP) VALUES('%s', SHA1('%s'), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '%s', 0, 0, 0, 0, 0, '%s')", pname, passwordstring, Bannedby, IP);
    mysql_query(query);
    SendMessage(playerid, "~g~Info: ~w~You have been registered on this server!");
    Logged[playerid] = 1;
    return 1;
}

stock MySQL_Login(playerid)
{
    new query[350], pname[24], savingstring[20];
    GetPlayerName(playerid, pname, 24);
    format(query, sizeof(query), "SELECT score, money, level, vip, kma, rank, kills, deaths, muted, jailed, frozen, mutedtimes, jailedtimes, frozentimes, banned, bannedby, logins, posx, posy, posz, posa FROM playerdata WHERE user = '%s'", pname);
    mysql_query(query);
    mysql_store_result();
    while(mysql_fetch_row_format(query,"|"))
    {
        mysql_fetch_field_row(savingstring, "score"); SetPlayerScore(playerid, strval(savingstring));
        mysql_fetch_field_row(savingstring, "money"); MoneyGiven[playerid] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "level"); PlayerInfo[playerid][pLevel] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "vip"); PlayerInfo[playerid][pVIP] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "kma"); PlayerInfo[playerid][pKMA] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "rank"); PlayerInfo[playerid][pRank] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "kills"); PlayerInfo[playerid][pKills] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "deaths"); PlayerInfo[playerid][pDeaths] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "muted"); PlayerInfo[playerid][pMuted] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "jailed"); PlayerInfo[playerid][pJailed] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "frozen"); PlayerInfo[playerid][pFrozen] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "mutedtimes"); PlayerInfo[playerid][pMutedTimes] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "jailedtimes"); PlayerInfo[playerid][pJailedTimes] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "frozentimes"); PlayerInfo[playerid][pFrozenTimes] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "banned"); PlayerInfo[playerid][pBanned] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "bannedby"); PlayerInfo[playerid][pBannedBy] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "logins"); PlayerInfo[playerid][pLogins] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "posx"); PlayerInfo[playerid][pPosX] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "posy"); PlayerInfo[playerid][pPosY] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "posz"); PlayerInfo[playerid][pPosZ] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "posa"); PlayerInfo[playerid][pPosA] = strval(savingstring);
    }
    mysql_free_result();
    JustLogged[playerid] = 1;
    Logged[playerid] = 1;
    PlayerInfo[playerid][pLogins]++;
    SendMessage(playerid, "~g~Info: ~w~You have been logged-in!");
    return 1;
}

stock GetName(playerid)
{
	new pname[24];
	GetPlayerName(playerid, pname, 24);
	return pname;
}
Reply
#2

This normally happens when you haven't got any AddPlayerClass lines in your OnGameModeInit. Add some.

https://sampwiki.blast.hk/wiki/AddPlayerClass
Reply
#3

dude thanks i think my brain is host from setting up mysql i was pulling hair out over that
Reply
#4

AddPlayerClass is needed, and once you log in, instead of SpawnPlayer(playerid) use SetSpawnInfo.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)