Help with garage system!
#1

Hello, i have a garage system in my server but i don't know why its not locking, i do /lockgarage and it say's its locked but still anyone can enter! help!!!

Код:
enum __garageInfo
{
	garageID,
	Float:garageXYZ[4],
	Text3D:garageLabel,
	garageCP,
	bool:garageStatus,
	bool:garageLock,
	garageOwner
}

new Garage[MAX_GARAGE][__garageInfo];

stock createGarage(playerid)
{
	new Float:x, Float:y, Float:z, Float:angle, query[512];
	GetPlayerPos(playerid, x, y, z);
	GetPlayerFacingAngle(playerid, angle);
	for(new i = 0; i < MAX_GARAGE; i++)
	{
		if(!Garage[i][garageStatus])
		{
			mysql_format(koneksi, query, sizeof(query), "INSERT INTO `garage`(`x`, `y`, `z`, `angle`, `owner`, `lock`) VALUES ('%f', '%f', '%f', '%f', '-1', '0')", x, y, z, angle);
			mysql_tquery(koneksi, query, "OnGarageCreated", "ddffff", playerid, i, x , y, z, angle);
			break;
		}
	}
	return 1;
}

forward OnGarageCreated(playerid, id, Float:x, Float:y, Float:z, Float:a);
public OnGarageCreated(playerid, id, Float:x, Float:y, Float:z, Float:a)
{
	new msg[512];
	Garage[id][garageID] 		= cache_insert_id();
	Garage[id][garageXYZ][0]	= x;
	Garage[id][garageXYZ][1]	= y;
	Garage[id][garageXYZ][2]	= z;
	Garage[id][garageXYZ][3]	= a;
	format(msg, sizeof(msg), CHAT_RED"[GARAGE]\n"CHAT_WHITE"ID : "CHAT_YELLOW"%d"CHAT_WHITE"\nLocation : "CHAT_YELLOW"%s\n$500,000\n"CHAT_WHITE"/buygarage"CHAT_YELLOW" %d", Garage[id][garageID], GetXY2DZone(x, y), id);
	Garage[id][garageCP]		= CreateDynamicCP(x, y, z, 1.0, -1, -1);
	Garage[id][garageLabel]		= CreateDynamic3DTextLabel(msg, COLOR_WHITE, x, y, z + 0.5, 10.0);
	Garage[id][garageOwner]		= -1;
	Garage[id][garageLock]		= true;
	Garage[id][garageStatus]	= true;
	Info(playerid, "Garage succesfully created.");
	return 1;
}

COMMAND:creategarage(playerid, params[])
{
	if(!adminLevel(playerid, 5))
		return 0;
		
	createGarage(playerid);
	return 1;
}

COMMAND:buygarage(playerid, params[])
{
	new id;
	if(sscanf(params, "d", id))
	{
		Usage(playerid, "buygarage <garage id>");
	}
	else
	{
		if(IsPlayerInDynamicCP(playerid, Garage[id][garageCP]))
		{
			if(Player[playerid][playerMoney] >= 500000)
			{
				new msg[512];
				takeMoney(playerid, 500000);
				Garage[id][garageOwner]		= Player[playerid][pID];
				format(msg, sizeof(msg), CHAT_INFO"[PRESS Y TO ENTER]\n"CHAT_WHITE"ID : "CHAT_YELLOW"%d"CHAT_WHITE"\nLocation : "CHAT_YELLOW"%s\n"CHAT_WHITE"Owner :"CHAT_YELLOW" %s", Garage[id][garageID], GetXY2DZone(Garage[id][garageXYZ][0], Garage[id][garageXYZ][1]), GetName(playerid));
				DestroyDynamic3DTextLabel(Garage[id][garageLabel]);
				Garage[id][garageLabel]		= CreateDynamic3DTextLabel(msg, COLOR_WHITE, Garage[id][garageXYZ][0], Garage[id][garageXYZ][1], Garage[id][garageXYZ][2] + 0.5, 10.0);
				mysql_format(koneksi, msg, sizeof(msg), "UPDATE `garage` SET `owner` = '%d' where `id` = '%d'", Garage[id][garageOwner], Garage[id][garageID]);
				mysql_query(koneksi, msg, false);
			}
			else
			{
				if(Player[playerid][english])
					Server(playerid, "You didn't have enough money to buy garage.");
				else
					Server(playerid, "Kamu tidak punya cukup uang untuk membeli garasi.");
			}
		}
		else
		{
			if(Player[playerid][english])
				Server(playerid, "You must be in garage checkpoint to buy garage.");
			else
				Server(playerid, "Kamu harus di checkpoint untuk membeli garasi.");
		}
	}
	return 1;
}

COMMAND:exitgarage(playerid, params[])
{
	if(Player[playerid][lastGarage] == -1)
	{
		Server(playerid, "You're not inside garage.");
	}
	else
	{
		new i = Player[playerid][lastGarage];
		if(IsPlayerInAnyVehicle(playerid))
		{
			if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
			{
				new vehid = GetPlayerVehicleID(playerid);
				SetVehicleVirtualWorld(vehid, 0);
				LinkVehicleToInterior(vehid, 0);
				SetPlayerInterior(playerid, 0);
				SetPlayerVirtualWorld(playerid, 0);
				foreach(new c : Player)
				{
					if(c == playerid || !IsPlayerInAnyVehicle(playerid)) continue;
					
					if(GetPlayerVehicleID© == vehid)
					{			
						SetPlayerInterior(c, 0);
						SetPlayerVirtualWorld(c, 0);
						loadWorld©;
					}
				}
				SetVehiclePos(vehid, Garage[i][garageXYZ][0], Garage[i][garageXYZ][1], Garage[i][garageXYZ][2] + 0.5);
				loadWorld(playerid);
			}
		}
		else
		{
			SetPlayerInterior(playerid, 0);
			SetPlayerVirtualWorld(playerid, 0);
			SetPlayerPos(playerid, Garage[i][garageXYZ][0], Garage[i][garageXYZ][1], Garage[i][garageXYZ][2] + 0.5);
			loadWorld(playerid);
		}
	}
	return 1;
}

COMMAND:sellgarage(playerid, params[])
{
	if(Player[playerid][lastGarage] == -1)
	{
		Server(playerid, "You're not inside garage.");
	}
	else
	{
		new i = Player[playerid][lastGarage];
		if(Garage[i][garageOwner] == Player[playerid][pID])
		{
			ShowPlayerDialog(playerid, DIALOG_SELLGARAGE, DIALOG_STYLE_MSGBOX, "Sell Garage", "Are you sure you want to sell this garage for $1,000,000.", "Yes", "No");
		}
		else
		{
			Server(playerid, "You're not owner of this garage.");
		}
	}
	return 1;
}

COMMAND:lockgarage(playerid, params[])
{
	if(Player[playerid][lastGarage] == -1)
	{
		Server(playerid, "You're not inside garage.");
	}
	else
	{
		new i = Player[playerid][lastGarage];
		if(Garage[i][garageOwner] == Player[playerid][pID])
		{
			new msg[256];
			if(!Garage[i][garageLock])
			{
				Garage[i][garageLock] = true;
				mysql_format(koneksi, msg, sizeof(msg), "UPDATE `garage` SET `lock` = '1' where `id` = '%d'", Garage[i][garageID]);
				mysql_query(koneksi, msg, false);
				Info(playerid, "This garage is "CHAT_YELLOW"locked"CHAT_WHITE".");
			}
			else
			{
				Garage[i][garageLock] = false;
				mysql_format(koneksi, msg, sizeof(msg), "UPDATE `garage` SET `lock` = '0' where `id` = '%d'", Garage[i][garageID]);
				mysql_query(koneksi, msg, false);
				Info(playerid, "This garage is "CHAT_RED"unlocked"CHAT_WHITE".");
			}
		}
		else
		{
			Server(playerid, "You're not owner of this garage.");
		}
	}
	return 1;
}

stock loadGarage()
{
	new query[50], Cache:garagecache;
	mysql_format(koneksi, query, sizeof(query), "SELECT * FROM `garage`");
	garagecache = mysql_query(koneksi, query, true);
	new rows = cache_num_rows(koneksi);
	if(rows > 0)
	{
		for(new z =0; z < rows; z++)
		{
			cache_set_active(garagecache);
			for(new i = 0; i < MAX_GARAGE; i++)
			{
				if(Garage[i][garageStatus]) continue;
				
				new msg[512];
				Garage[i][garageID] 	= cache_get_field_content_int(z, "id");
				Garage[i][garageXYZ][0]	= cache_get_field_content_float(z, "x");
				Garage[i][garageXYZ][1]	= cache_get_field_content_float(z, "y");
				Garage[i][garageXYZ][2]	= cache_get_field_content_float(z, "z");
				Garage[i][garageXYZ][3]	= cache_get_field_content_float(z, "angle");
				Garage[i][garageOwner]	= cache_get_field_content_int(z, "owner");
				if(cache_get_field_content_int(z, "lock") == 0)
					Garage[i][garageLock]	= false;
				else
					Garage[i][garageLock]	= true;
				if(Garage[i][garageOwner] == -1)
					format(msg, sizeof(msg), CHAT_RED"[GARAGE]\n"CHAT_WHITE"ID : "CHAT_YELLOW"%d"CHAT_WHITE"\nLocation : "CHAT_YELLOW"%s\n$500,000\n"CHAT_WHITE"/buygarage"CHAT_YELLOW" %d", Garage[i][garageID], GetXY2DZone(Garage[i][garageXYZ][0], Garage[i][garageXYZ][1]), i);
				else
					format(msg, sizeof(msg), CHAT_INFO"[PRESS Y TO ENTER]\n"CHAT_WHITE"ID : "CHAT_YELLOW"%d"CHAT_WHITE"\nLocation : "CHAT_YELLOW"%s\n"CHAT_WHITE"Owner :"CHAT_YELLOW" %s", Garage[i][garageID], GetXY2DZone(Garage[i][garageXYZ][0], Garage[i][garageXYZ][1]), findName(Garage[i][garageOwner]));
				Garage[i][garageCP]		= CreateDynamicCP(Garage[i][garageXYZ][0], Garage[i][garageXYZ][1], Garage[i][garageXYZ][2], 1.0, -1, -1);
				Garage[i][garageLabel]	= CreateDynamic3DTextLabel(msg, COLOR_WHITE, Garage[i][garageXYZ][0], Garage[i][garageXYZ][1], Garage[i][garageXYZ][2] + 0.5, 10.0);				
				Garage[i][garageStatus]	= true;
				break;
			}
			garagecache = cache_save();
		}
	}
	return 1;
}
Reply
#2

You tried checking if garage is locked in your enter command? Your enter command is not shown here. According to this loadgarage stock you need to do your checks inside OnPlayerKeyStateChange.
Reply
#3

How, im just starting in scripting.
Reply
#4

Under OnPlayerKeyStateUpdate

When a player presses enter key
Код:
if(Garage[i][garageLock] == 1)
return SendClientMessage(playerid, -1, "{C9C9C9}[SERVER]{FFFFFF} You cannot access the garage as it has been locked by it's owner.");
Read the codes, understand, if you are unable to, you're welcome to ask for an explaination

Make sure you change the codes to the variables you used..
Reply
#5

Do i add that?
Reply
#6

Clearly you are using a ready gamemode along with a garage filterscript that you are trying to get it work along. This will be too classic to say but never ever jump in to gamemodes to gamemodes before learning what is used for what by making one of your own first.

I could start up a server just by simply grabbing a godfather edit but im developing my own slowly, one piece at a time. Slow but effective.

For your question, yes you do add that but you don't directly add that you need to loop through garages and if the player is at a garage door you need to check if its locked. The code that div shared is just a piece of that loop.
Reply
#7

The Gamemode already had that garage function, its not a filterscript, its an include file, i wan't to fix it since like i said its not locking i wan't to see how to do it so i can script my own, i really don't know anything about scripting, i just could fix some bugs myself by looking around. I just wan't someone to tell me where and how to add it so it works, as i said im new to this.
Reply
#8

Pls heeeeeeelp!
Reply
#9

24 hour bumps only, as per forum rules.
Reply
#10

Learn how code works first..
Reply
#11

Quote:
Originally Posted by div
Посмотреть сообщение
Under OnPlayerKeyStateUpdate

When a player presses enter key
Код:
if(Garage[i][garageLock] == 1)
return SendClientMessage(playerid, -1, "{C9C9C9}[SERVER]{FFFFFF} You cannot access the garage as it has been locked by it's owner.");
Read the codes, understand, if you are unable to, you're welcome to ask for an explaination

Make sure you change the codes to the variables you used..
Use this code if you dont want anyone to access the garage if it's locked.


Ignore others if they discourage you, I'm a noob, still trying to make my own gamemode :P



And, you need to check if the guy pressing enter is the owner..


Don't know which MySQL plugin you're using.. so first get the OWNER'S name from the field, if the guy pressing enter is the owner of that, allow him to enter, and then an "ELSE" statement, and then my code further.
Reply
#12

Show the enter command.
Reply
#13

You don't enter pressing enter you enter pressing "Y". But in what part of the script do i add it?
Reply
#14

You really should learn from the basics..
Reply
#15

Im trying to!
Reply
#16

Respond to GTLS. The others almost shouldn't be posting.

div, while well intentioned, and eager to help you, needs to have a little more patience, and look at the wider picture, before posting up code changes.

Copy-Paste code, without explanation, or actual questioning of the fault in other areas, makes other issues not get seen, and can quite often compound the initial issue, due to simply fixing a 'symptom' rather than the actual source of it.
Reply
#17

Bump
Reply
#18

Quote:
Originally Posted by iNkyz
Посмотреть сообщение
Bump
Quote:
Originally Posted by GTLS
Посмотреть сообщение
Show the enter command.
Again, respond to GTLS who is asking for the section of code that is under OnPlayerKeyStateChange where the key gets checked in regards to the enter 'code'. From where it's checking if the Y key got pressed.
Reply
#19

Код:
 OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
Reply
#20

No...

Under that callback, there'll be a check look for the newkeys of Y, and you need that segment of code...

Like this...

PHP код:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    
/*if((newkeys & KEY_FIRE)&&!(oldkeys & KEY_FIRE))
    {
        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER && GetPlayerVehicleID(playerid)==EMSBox)
        {
        }
    }*/
    
if((oldkeys KEY_FIRE)&&!(newkeys KEY_FIRE))//Holding fire lets nitro run, and releasing it turns it off, and sets the vehicle HP.
    
{
        if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER && GetPlayerVehicleID(playerid)==EMSBox)
        {
            
AddVehicleComponent(EMSBox1010);
            
SetVehicleHealth(EMSBox10000);
        }
    }
    
/*if((oldkeys & KEY_JUMP) &&!(newkeys & KEY_JUMP))
    {
        SendClientMessage(playerid, -1, "Jump pressed");
    }
    */ 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)