Sistema de casas(propriedades)
3 participantes
Página 1 de 1
Sistema de casas(propriedades)
Bem estive com vontade de postar esse script a um tempo atras,mas como vários player me perguntaram como era,entao resolvi posta-lo aqui no fórum:
Adicione isto em Functions.nut:
function LoadProps()
{
local q = QuerySQL( pdb, "SELECT * FROM Properties" ), i = 0;
while( GetSQLColumnData( q, 0 ) )
{
local
PX= GetSQLColumnData( q, 1 ),
PY = GetSQLColumnData( q, 2 ),
PZ = GetSQLColumnData( q, 3 );
CreatePickup( 407, Vector( PX.tofloat(), PY.tofloat(), PZ.tofloat() ) );
GetSQLNextRow( q );
i++;
}
print( "Propriedades carregadas - " + i );
}
function random(start, finish)
{
local t = ((rand() % (finish - start)) + start);
return t;
}
Adicione isto em Main.nut:
function onScriptLoad()
{
pdb <- ConnectSQL("props.sqlite");
if (pdb) print("Properties Database loaded Successfully");
::QuerySQL( pdb, "CREATE TABLE IF NOT EXISTS Properties ( Name TEXT, PX FLOAT, PY FLOAT, PZ FLOAT, Owner VARCHAR(32), Sharer VARCHAR(32), Price NUMERIC, PropertyID INT)" );
LoadProps();
print("Sistema de propriedades carregada");
}
function onPickupPickedUp( player, pickup )
{
if(pickup.Model == 407)
{
local id = pickup.ID+1, q = QuerySQL(pdb,"SELECT * FROM Properties WHERE PropertyID='"+id+"'");
if (GetSQLColumnData(q,0) !=null)
{
local name = GetSQLColumnData(q, 0), owner = GetSQLColumnData(q, 4), sharer = GetSQLColumnData(q, 5), price = GetSQLColumnData(q, 6);
MessagePlayer("ID: ["+id+"] Propriedade: ["+name+"] Preco: ["+price+"] Dono: ["+owner+"] Compartilhada com: ["+sharer+"]",player);
}
else return;
FreeSQLQuery(q);
pickup.RespawnTime = 5000;
}
}
function onPlayerCommand( player, cmd, text )
else if ( cmd == "createprop" || cmd == "criarcasa" )
{
player.Cash +=0;
if( level == 4 ) MessagePlayer( "Voce nao tem acesso a esse comando", player );
else if ( !text ) MessagePlayer( ">> Use /" + cmd + " <Preco> <Nome da casa>", player );
else
{
local
prc = GetTok(text," ",1),
pname = GetTok( text, " ", 2, NumTok( text, " " ) );
if ( !pname || !prc ) MessagePlayer( ">> Use /" + cmd + " <Preco> <Nome da casa>", player );
else
{
if ( GetSQLColumnData(QuerySQL(pdb, "SELECT Name FROM Properties WHERE Name='"+escapeSQLString(pname)+"'"),0) ) MessagePlayer( "Esta propriedade ja existe", player );
else if(!IsNum(prc)) MessagePlayer(" Preco Invalido", player );
else
{
CreatePickup( 407, Vector( player.Pos.x.tofloat(), player.Pos.y.tofloat(), player.Pos.z.tofloat() ) );
local proID = GetSQLColumnData(QuerySQL(pdb,"SELECT COUNT( * ) FROM Properties"),0)+1;
QuerySQL( pdb, "INSERT INTO Properties ( Name, PX, PY, PZ, Owner, Sharer, Price, PropertyID ) VALUES ( '"+pname+"', '" + player.Pos.x.tofloat() + "', '" + player.Pos.y.tofloat() + "', '" + player.Pos.z.tofloat() + "', 'Vice-City', 'None', '"+prc+"', '"+proID+"')" );
Message(player.Name+": Propriedade salva na database");
}
}
}
}
else if ( cmd == "buyprop" || cmd == "comprarcasa" )
{
if(!text) MessagePlayer(" Use /" + cmd + " <ID da casa>", player );
else if (!IsNum(text)) MessagePlayer(" ID Nao identificado", player );
else if ( text.tointeger() < 1 || text.tointeger() > GetPickupCount())MessagePlayer(" ID da casa invalido, Total existentes sao "+GetPickupCount(), player );
else
{
local prop = QuerySQL(pdb,"SELECT * FROM Properties WHERE PropertyID='"+escapeSQLString(text)+"'");
if ( GetSQLColumnData(prop, 4) !="Vice-City") MessagePlayer(" Essa casa nao esta a venda", player );
else if ( player.Cash < GetSQLColumnData(prop, 6)) MessagePlayer(" Saldo insuficiente", player );
else{
QuerySQL(pdb, "UPDATE Properties SET Owner='"+player.Name+"' WHERE PropertyID='"+escapeSQLString(text)+"'");
player.Cash -= GetSQLColumnData(prop, 6);
MessagePlayer("Parabens, Voce comprou esta casa",player);
}
FreeSQLQuery(prop);
}
}
else if ( cmd == "sellprop" || cmd == "vendercasa" )
{
if(!text) MessagePlayer(" Use /" + cmd + " <ID da casa>", player );
else if (!IsNum(text)) MessagePlayer(" ID da casa invalido", player );
else if ( text.tointeger() < 1 || text.tointeger() > GetPickupCount()) MessagePlayer(" ID da casa invalido, Total existentes sao "+GetPickupCount(), player );
else
{
local prop = QuerySQL(pdb,"SELECT * FROM Properties WHERE PropertyID='"+escapeSQLString(text)+"'");
if ( GetSQLColumnData(prop, 4) !=player.Name) MessagePlayer(">> Erro - Voce nao e dono dessa casa", player );
else{
QuerySQL(pdb, "UPDATE Properties SET Owner='Vice-City' WHERE PropertyID='"+escapeSQLString(text)+"'");
player.Cash += GetSQLColumnData(prop, 6);
MessagePlayer("Parabens,Voce vendeu esta casa",player);
}
FreeSQLQuery(prop);
}
}
else if ( cmd == "myprops" || cmd == "minhascasas" )
{
local q = QuerySQL( pdb, "SELECT * FROM Properties WHERE Owner='"+escapeSQLString(player.Name)+"'" ), i = 1;
if( !q ) MessagePlayer("Voce nao tem nenhuma casa",player);
else{
while( GetSQLColumnData( q, 4 ) == player.Name)
{
MessagePlayer(" Minhas casas: ID: "+GetSQLColumnData( q, 7 )+", Nome: "+GetSQLColumnData(q,0),player);
GetSQLNextRow( q );
i++;
}
}
FreeSQLQuery(q);
}
else if ( cmd == "mysharedprops" || cmd == "minhascasascompart" )
{
local q = QuerySQL( pdb, "SELECT * FROM Properties WHERE Sharer='"+escapeSQLString(player.Name)+"'" ), i = 1;
if( !q ) MessagePlayer("Voce nao tem casas compartilhadas",player);
else{
while( GetSQLColumnData( q, 5 ) == player.Name)
{
MessagePlayer("Minhas casas compartilhadas: ID "+GetSQLColumnData( q, 7 )+", Nome: "+GetSQLColumnData(q,0),player);
GetSQLNextRow( q );
i++;
}
}
FreeSQLQuery(q);
}
else if ( cmd == "shareprop" || cmd == "compartcasa" )
{
if ( Checar( player, null ) ) return 0;
else if(!text) MessagePlayer(" Use /" + cmd + " <ID da casa> <ID/Nome do jogador>", player );
else
{
local id = GetTok(text, " ",1), plr = GetPlayer(GetTok(text, " ",2));
if (!IsNum(id)) MessagePlayer(" ID Invalido ", player );
else if( !plr) MessagePlayer(" Jogador Desconhecido", player );
else if ( id.tointeger() < 1 || id.tointeger() > GetPickupCount()) MessagePlayer("ID da casa invalido, Total de casas existentes sao "+GetPickupCount(), player );
else
{
local prop = QuerySQL(pdb,"SELECT * FROM Properties WHERE PropertyID='"+escapeSQLString(id)+"'");
if ( GetSQLColumnData(prop, 4) !=player.Name) MessagePlayer("Voce nao e dono desta casa", player );
else{
QuerySQL(pdb, "UPDATE Properties SET Sharer='"+plr+"' WHERE PropertyID='"+escapeSQLString(id)+"'");
MessagePlayer("Parabens, Voce compartilhou sua casa com "+plr.Name,player);
MessagePlayer(player.Name+" compartilhou uma casa com voce",plr);
}
FreeSQLQuery(prop);
}
}
}
else if ( cmd == "unshareprop" || cmd == "descompartcasa" )
{
else if(!text) S_MSG(" Use /" + cmd + " <ID da casa>", player );
else if (!IsNum(text)) MessagePlayer("ID invalido", player );
else if ( text.tointeger() < 1 || text.tointeger() > GetPickupCount()) MessagePlayer(">> ID da casa invalido, Total de casas existentes sao "+GetPickupCount(), player );
else
{
local prop = QuerySQL(pdb,"SELECT * FROM Properties WHERE PropertyID='"+escapeSQLString(text)+"'");
if ( GetSQLColumnData(prop, 4) !=player.Name) MessagePlayer("Voce nao e dono desta casa", player );
else{
QuerySQL(pdb, "UPDATE Properties SET Sharer='None' WHERE PropertyID='"+escapeSQLString(text)+"'");
MessagePlayer("Parabens,voce descompartilhou uma casa",player);
}
FreeSQLQuery(prop);
}
}
Apos a abertura do servidor ele ira criar a database chamada : props.sqlite, la ira salvar as casas
Siga todos os passos e boa sorte
Adicione isto em Functions.nut:
function LoadProps()
{
local q = QuerySQL( pdb, "SELECT * FROM Properties" ), i = 0;
while( GetSQLColumnData( q, 0 ) )
{
local
PX= GetSQLColumnData( q, 1 ),
PY = GetSQLColumnData( q, 2 ),
PZ = GetSQLColumnData( q, 3 );
CreatePickup( 407, Vector( PX.tofloat(), PY.tofloat(), PZ.tofloat() ) );
GetSQLNextRow( q );
i++;
}
print( "Propriedades carregadas - " + i );
}
function random(start, finish)
{
local t = ((rand() % (finish - start)) + start);
return t;
}
Adicione isto em Main.nut:
function onScriptLoad()
{
pdb <- ConnectSQL("props.sqlite");
if (pdb) print("Properties Database loaded Successfully");
::QuerySQL( pdb, "CREATE TABLE IF NOT EXISTS Properties ( Name TEXT, PX FLOAT, PY FLOAT, PZ FLOAT, Owner VARCHAR(32), Sharer VARCHAR(32), Price NUMERIC, PropertyID INT)" );
LoadProps();
print("Sistema de propriedades carregada");
}
function onPickupPickedUp( player, pickup )
{
if(pickup.Model == 407)
{
local id = pickup.ID+1, q = QuerySQL(pdb,"SELECT * FROM Properties WHERE PropertyID='"+id+"'");
if (GetSQLColumnData(q,0) !=null)
{
local name = GetSQLColumnData(q, 0), owner = GetSQLColumnData(q, 4), sharer = GetSQLColumnData(q, 5), price = GetSQLColumnData(q, 6);
MessagePlayer("ID: ["+id+"] Propriedade: ["+name+"] Preco: ["+price+"] Dono: ["+owner+"] Compartilhada com: ["+sharer+"]",player);
}
else return;
FreeSQLQuery(q);
pickup.RespawnTime = 5000;
}
}
function onPlayerCommand( player, cmd, text )
else if ( cmd == "createprop" || cmd == "criarcasa" )
{
player.Cash +=0;
if( level == 4 ) MessagePlayer( "Voce nao tem acesso a esse comando", player );
else if ( !text ) MessagePlayer( ">> Use /" + cmd + " <Preco> <Nome da casa>", player );
else
{
local
prc = GetTok(text," ",1),
pname = GetTok( text, " ", 2, NumTok( text, " " ) );
if ( !pname || !prc ) MessagePlayer( ">> Use /" + cmd + " <Preco> <Nome da casa>", player );
else
{
if ( GetSQLColumnData(QuerySQL(pdb, "SELECT Name FROM Properties WHERE Name='"+escapeSQLString(pname)+"'"),0) ) MessagePlayer( "Esta propriedade ja existe", player );
else if(!IsNum(prc)) MessagePlayer(" Preco Invalido", player );
else
{
CreatePickup( 407, Vector( player.Pos.x.tofloat(), player.Pos.y.tofloat(), player.Pos.z.tofloat() ) );
local proID = GetSQLColumnData(QuerySQL(pdb,"SELECT COUNT( * ) FROM Properties"),0)+1;
QuerySQL( pdb, "INSERT INTO Properties ( Name, PX, PY, PZ, Owner, Sharer, Price, PropertyID ) VALUES ( '"+pname+"', '" + player.Pos.x.tofloat() + "', '" + player.Pos.y.tofloat() + "', '" + player.Pos.z.tofloat() + "', 'Vice-City', 'None', '"+prc+"', '"+proID+"')" );
Message(player.Name+": Propriedade salva na database");
}
}
}
}
else if ( cmd == "buyprop" || cmd == "comprarcasa" )
{
if(!text) MessagePlayer(" Use /" + cmd + " <ID da casa>", player );
else if (!IsNum(text)) MessagePlayer(" ID Nao identificado", player );
else if ( text.tointeger() < 1 || text.tointeger() > GetPickupCount())MessagePlayer(" ID da casa invalido, Total existentes sao "+GetPickupCount(), player );
else
{
local prop = QuerySQL(pdb,"SELECT * FROM Properties WHERE PropertyID='"+escapeSQLString(text)+"'");
if ( GetSQLColumnData(prop, 4) !="Vice-City") MessagePlayer(" Essa casa nao esta a venda", player );
else if ( player.Cash < GetSQLColumnData(prop, 6)) MessagePlayer(" Saldo insuficiente", player );
else{
QuerySQL(pdb, "UPDATE Properties SET Owner='"+player.Name+"' WHERE PropertyID='"+escapeSQLString(text)+"'");
player.Cash -= GetSQLColumnData(prop, 6);
MessagePlayer("Parabens, Voce comprou esta casa",player);
}
FreeSQLQuery(prop);
}
}
else if ( cmd == "sellprop" || cmd == "vendercasa" )
{
if(!text) MessagePlayer(" Use /" + cmd + " <ID da casa>", player );
else if (!IsNum(text)) MessagePlayer(" ID da casa invalido", player );
else if ( text.tointeger() < 1 || text.tointeger() > GetPickupCount()) MessagePlayer(" ID da casa invalido, Total existentes sao "+GetPickupCount(), player );
else
{
local prop = QuerySQL(pdb,"SELECT * FROM Properties WHERE PropertyID='"+escapeSQLString(text)+"'");
if ( GetSQLColumnData(prop, 4) !=player.Name) MessagePlayer(">> Erro - Voce nao e dono dessa casa", player );
else{
QuerySQL(pdb, "UPDATE Properties SET Owner='Vice-City' WHERE PropertyID='"+escapeSQLString(text)+"'");
player.Cash += GetSQLColumnData(prop, 6);
MessagePlayer("Parabens,Voce vendeu esta casa",player);
}
FreeSQLQuery(prop);
}
}
else if ( cmd == "myprops" || cmd == "minhascasas" )
{
local q = QuerySQL( pdb, "SELECT * FROM Properties WHERE Owner='"+escapeSQLString(player.Name)+"'" ), i = 1;
if( !q ) MessagePlayer("Voce nao tem nenhuma casa",player);
else{
while( GetSQLColumnData( q, 4 ) == player.Name)
{
MessagePlayer(" Minhas casas: ID: "+GetSQLColumnData( q, 7 )+", Nome: "+GetSQLColumnData(q,0),player);
GetSQLNextRow( q );
i++;
}
}
FreeSQLQuery(q);
}
else if ( cmd == "mysharedprops" || cmd == "minhascasascompart" )
{
local q = QuerySQL( pdb, "SELECT * FROM Properties WHERE Sharer='"+escapeSQLString(player.Name)+"'" ), i = 1;
if( !q ) MessagePlayer("Voce nao tem casas compartilhadas",player);
else{
while( GetSQLColumnData( q, 5 ) == player.Name)
{
MessagePlayer("Minhas casas compartilhadas: ID "+GetSQLColumnData( q, 7 )+", Nome: "+GetSQLColumnData(q,0),player);
GetSQLNextRow( q );
i++;
}
}
FreeSQLQuery(q);
}
else if ( cmd == "shareprop" || cmd == "compartcasa" )
{
if ( Checar( player, null ) ) return 0;
else if(!text) MessagePlayer(" Use /" + cmd + " <ID da casa> <ID/Nome do jogador>", player );
else
{
local id = GetTok(text, " ",1), plr = GetPlayer(GetTok(text, " ",2));
if (!IsNum(id)) MessagePlayer(" ID Invalido ", player );
else if( !plr) MessagePlayer(" Jogador Desconhecido", player );
else if ( id.tointeger() < 1 || id.tointeger() > GetPickupCount()) MessagePlayer("ID da casa invalido, Total de casas existentes sao "+GetPickupCount(), player );
else
{
local prop = QuerySQL(pdb,"SELECT * FROM Properties WHERE PropertyID='"+escapeSQLString(id)+"'");
if ( GetSQLColumnData(prop, 4) !=player.Name) MessagePlayer("Voce nao e dono desta casa", player );
else{
QuerySQL(pdb, "UPDATE Properties SET Sharer='"+plr+"' WHERE PropertyID='"+escapeSQLString(id)+"'");
MessagePlayer("Parabens, Voce compartilhou sua casa com "+plr.Name,player);
MessagePlayer(player.Name+" compartilhou uma casa com voce",plr);
}
FreeSQLQuery(prop);
}
}
}
else if ( cmd == "unshareprop" || cmd == "descompartcasa" )
{
else if(!text) S_MSG(" Use /" + cmd + " <ID da casa>", player );
else if (!IsNum(text)) MessagePlayer("ID invalido", player );
else if ( text.tointeger() < 1 || text.tointeger() > GetPickupCount()) MessagePlayer(">> ID da casa invalido, Total de casas existentes sao "+GetPickupCount(), player );
else
{
local prop = QuerySQL(pdb,"SELECT * FROM Properties WHERE PropertyID='"+escapeSQLString(text)+"'");
if ( GetSQLColumnData(prop, 4) !=player.Name) MessagePlayer("Voce nao e dono desta casa", player );
else{
QuerySQL(pdb, "UPDATE Properties SET Sharer='None' WHERE PropertyID='"+escapeSQLString(text)+"'");
MessagePlayer("Parabens,voce descompartilhou uma casa",player);
}
FreeSQLQuery(prop);
}
}
Apos a abertura do servidor ele ira criar a database chamada : props.sqlite, la ira salvar as casas
Siga todos os passos e boa sorte
Thomas BR- Mensagens : 17
Pontos : 25
Reputação : 0
Data de inscrição : 03/01/2016
Re: Sistema de casas(propriedades)
Alguém pode modificar as partes que carregam .sqlite para .db?
Caique- Mensagens : 21
Pontos : 35
Reputação : 0
Data de inscrição : 03/10/2015
Re: Sistema de casas(propriedades)
O script aqui não está funcionando, já modifiquei de sqlite e pdp pra db, más ainda sim não funciona.
Caique- Mensagens : 21
Pontos : 35
Reputação : 0
Data de inscrição : 03/10/2015
Tópicos semelhantes
» Sistema de Objetos v0.2 | Sistema de Portões v0.1
» Sistema de Corrida
» Sistema Multilang
» SISTEMA DE ROUBO
» Sistema de Casa
» Sistema de Corrida
» Sistema Multilang
» SISTEMA DE ROUBO
» Sistema de Casa
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos
|
|