PDA

View Full Version : Help with garage system!


iNkyz
25/06/2018, 07:08 PM
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(c) == vehid)
{
SetPlayerInterior(c, 0);
SetPlayerVirtualWorld(c, 0);
loadWorld(c);
}
}
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;
}

grymtn
25/06/2018, 09:59 PM
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.

iNkyz
26/06/2018, 03:10 AM
How, im just starting in scripting.

div
26/06/2018, 03:18 AM
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..

iNkyz
26/06/2018, 08:12 PM
Do i add that?

grymtn
26/06/2018, 08:36 PM
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.

iNkyz
26/06/2018, 09:05 PM
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.

iNkyz
27/06/2018, 12:50 AM
Pls heeeeeeelp!

Sew_Sumi
27/06/2018, 01:31 AM
24 hour bumps only, as per forum rules.

Verc
27/06/2018, 03:44 AM
Learn how code works first..

div
27/06/2018, 04:12 AM
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.

GTLS
27/06/2018, 08:39 AM
Show the enter command.

iNkyz
27/06/2018, 10:58 AM
You don't enter pressing enter you enter pressing "Y". But in what part of the script do i add it?

Verc
27/06/2018, 11:35 AM
You really should learn from the basics..

iNkyz
27/06/2018, 07:33 PM
Im trying to!

Sew_Sumi
27/06/2018, 09:12 PM
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.

iNkyz
28/06/2018, 09:33 PM
Bump

Sew_Sumi
29/06/2018, 12:54 AM
Bump

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.

iNkyz
29/06/2018, 01:25 AM
OnPlayerKeyStateChange(playerid, newkeys, oldkeys);

Sew_Sumi
29/06/2018, 01:59 AM
No...

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

Like this...

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
/*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(EMSBox, 1010);
SetVehicleHealth(EMSBox, 10000);
}

}
/*if((oldkeys & KEY_JUMP) &&!(newkeys & KEY_JUMP))
{
SendClientMessage(playerid, -1, "Jump pressed");
}
*/