Help with my dynamic housing!
#1

pawn Code:
//==============================================================================
//==============================================================================
//======            =======            =============            ================
//==========   ============   ======================   =========================
//==========   ============   ======================   =========================
//==========   ============        =================        ====================
//==========   ============   ======================   =========================
//==========   ============   ======================   =========================
//==========   ============            =============               =============
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//******************************************************************************
//                 *TDynamic House System*
//******************************************************************************
//Hello SA-MP members. As you all know I am Tee. This Dynamic House system was
//made by me because I wanted an easier way to create House on my server than
//to save the positions, create checkpoints, and edit it all in the script.
//I decided to make this filterscript and it worked so I wanted you all to have
//it. Here it is.
//I don't really know what to call it so I named it,"TDynamic House System".
//Please do not take credit for it.

//                      |------Creadits:----|
//                      |  Zeex - Zcmd      |
//                      |  Darco - Dini     |
//                      |  Y_Less - Sscanf2 |
//                      |    Tee - The FS   |
//                    Incognito- Streamer plugin.
//                      |-------------------|

//                          *****ADVERTISMENT*****
//------------------------------------------------------------------------------
//                        Majestic - Gaming Roleplay
//                            213.5.176.158:7781
//------------------------------------------------------------------------------


#include <a_samp>
#include <zcmd>
#include <sscanf>
#include <dini>
#include <streamer>


#define PAYDAY_TIME 1800000
#define MAX_HOUSES 100000
#define NO_OWNER "INVALID_PLAYER_ID"
#define CASE_SENSETIVE  true
#define White 0xFFFFFFFF
#define Yellow 0xFFFF00FF
#define Grey 0xC0C0C0FF
#define Red 0xFF0000AA
#define Green 0x45E01FFF

new hCPid[32];
new String[200];
new file[128];
new Name[MAX_PLAYER_NAME];
new Float:X,Float:Y,Float:Z;
new Label[128];
new interior1;
new houseid;
enum House
{
    hCP,
    Text3D:hLabel,
    hCost,
    hinterior,
    hName[128],
}
new HouseInfo[MAX_HOUSES][House];
forward Payday();

public OnFilterScriptInit()
{
    print("___________________________");
    print("--Dynamic House Loaded--");
    print("      --Made by: Tee--     ");
    print("___________________________");
    LoadHouses();
    return 1;
}

public OnFilterScriptExit()
{
    UnloadHouses();
    return 1;
}

public OnPlayerEnterDynamichCP(playerid, checkpointid)
{
    for(new i = 0;i<MAX_HOUSES;i++)
    {
        if(checkpointid == HouseInfo[i][hCP])
        {
            hCPid[playerid] = i;
            format(file,sizeof(file),"House/%i.ini",i);
            if(dini_Int(file, "HasOwner") == 0)
            {
                ShowPlayerDialog(playerid,219,DIALOG_STYLE_MSGBOX,"Buy House","Do you want to buy this Houses?\n If Yes then click on the option Yes","Buy","Cancel");
            }
        }
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 219)
    {
        if(response == 1)
        {
            format(file,sizeof(file),"House/%i.ini",hCPid[playerid]);
            if(dini_Int(file,"Cost") > GetPlayerMoney(playerid))return SendClientMessage(playerid,Red,"You do not have enough cash to buy this house.");
            GivePlayerMoney(playerid, -dini_Int(file,"Cost"));
            GetPlayerName(playerid,Name,sizeof(Name));
            dini_Set(file, "Owner",Name);
            dini_IntSet(file, "OwnedHouse",1);
            dini_IntSet(file, "HasOwner",1);
            format(Label, sizeof(Label), "House Name: %s\nOwner: %s\nCost: $%i",dini_Get(file, "Name"),dini_Get(file, "Owner"),dini_Int(file, "Cost"));
            Update3DTextLabelText(HouseInfo[hCPid[playerid]][hLabel],White,Label);
            format(String,sizeof(String),"You have successfully purchased the house.",dini_Get(file, "Name"));
            SendClientMessage(playerid,Green,String);
        }
        if(response == 0)
        {
            SendClientMessage(playerid,Yellow,"You chose not to buy this house.");
        }
    }
    if(dialogid == 220)
    {
        if(response == 1)
        {
            GetPlayerName(playerid,Name,sizeof(Name));
            format(file,sizeof(file),"House/%i.ini",GetPlayerHouseID(playerid));
            format(Label, sizeof(Label), "House Name: %s\nOwner: No Owner\nCost: $%i\ninterior: $%i",dini_Get(file, "Name"),dini_Int(file, "Cost"));
            Update3DTextLabelText(HouseInfo[hCPid[playerid]][hLabel],White,Label);
            dini_Set(String, "Owner","No Owner");
            dini_IntSet(file, "Cost",dini_Int(file, "Cost"));
            dini_IntSet(file, "interior",dini_Int(file, "interior"));
            dini_IntSet(file, "OwnedHouse",0);
            dini_IntSet(file, "HasOwner",0);
            GivePlayerMoney(playerid,dini_Int(file, "Cost")/4);
            SendClientMessage(playerid,Green,"You have sold your house and recieved 50% percent of the price.");
        }
    }
    return 1;
}

// This command is used to create the House.
COMMAND:createhouse(playerid, params[])
{
    new houseid,cost,interior,name[128];
    if(!IsPlayerAdmin(playerid))return 0;
    if(sscanf(params,"iiis",houseid,cost,interior,name))return SendClientMessage(playerid, 0xFF0000AA, "Usage: /createhouse [houseid] [cost] [interior] [name]");
    format(file,sizeof(file),"House/%i.ini",houseid);
    if(houseid < 0)return SendClientMessage(playerid,Red,"House IDs cannot be less than 0.");
    if(dini_Exists(String))return SendClientMessage(playerid,Red,"That house ID is already in use.");
    HouseInfo[houseid][hName] = name;
    HouseInfo[houseid][hCost] = cost;
    HouseInfo[houseid][interior] = interior;
    GetPlayerPos(playerid, X, Y, Z);
    dini_Create(file);
    dini_Set(file, "Name", name);
    dini_Set(file, "Owner","No Owner");
    dini_IntSet(file, "Cost",cost);
    dini_IntSet(file, "interior",interior);
    dini_FloatSet(file, "HouseX", X);
    dini_FloatSet(file, "HouseY", Y);
    dini_FloatSet(file, "HouseZ", Z);
    dini_IntSet(file, "World",GetPlayerVirtualWorld(playerid));
    dini_IntSet(file, "interior",GetPlayerInterior(playerid));
    dini_IntSet(file, "OwnedHouse",0);
    dini_IntSet(file, "HasOwner",0);
    HouseInfo[houseid][hCP] = CreateDynamicCP(X,Y,Z,1.0,GetPlayerVirtualWorld(playerid),GetPlayerInterior(playerid),-1,50.0);
    format(Label, sizeof(Label), "House Name: %s\nOwner: No Owner\nCost: $%i", name,cost);
    HouseInfo[houseid][hLabel] = Create3DTextLabel(Label,White,X,Y,Z,100.0,GetPlayerVirtualWorld(playerid),1);
    format(String,sizeof(String),"HouseCreated. Name: %s | House Cost: $%i | House interior: $%i | Owner: No Owner",name,cost,interior);
    SendClientMessage(playerid,Green,String);
    return 1;
}

CMD:buyhouse(playerid,params[])
{
for(new i = 0;i<MAX_HOUSES;i++)
{
if(!IsPlayerInRangeOfPoint(playerid,3.0,HouseInfo[i][hCP],HouseInfo[i][hCP],HouseInfo[i][hCP]))
{
format(file,sizeof(file),"House/%i.ini",hCPid[playerid]);
if(GetPlayerHouseID(playerid) > -1)return SendClientMessage(playerid,Red,"You already own a house.");
if(dini_Int(file,"Cost") > GetPlayerMoney(playerid))return SendClientMessage(playerid,Red,"You do not have enough cash to buy this house.");
GivePlayerMoney(playerid, -dini_Int(file,"Cost"));
GetPlayerName(playerid,Name,sizeof(Name));
dini_Set(file, "Owner",Name);
dini_IntSet(file, "OwnedHouse",1);
dini_IntSet(file, "HasOwner",1);
format(Label, sizeof(Label), "House Name: %s\nOwner: %s",dini_Get(file, "Name"),dini_Get(file, "Owner"));
Update3DTextLabelText(HouseInfo[hCPid[playerid]][hLabel],White,Label);
format(String,sizeof(String),"You have successfully purchased the %s.",dini_Get(file, "Name"));
SendClientMessage(playerid,Green,String);
}
}
return 1;
}

//This command is used to delete a House.
COMMAND:deletehouse(playerid, params[])
{
    new houseid;
    if(!IsPlayerAdmin(playerid)) return 0;
    if(sscanf(params, "i", houseid)) return SendClientMessage(playerid,0xC0C0C0FF,"Usage: /deletehouse [houseid]");
    format(file,sizeof(file),"House/%i.ini",houseid);
    if(!dini_Exists(file))return SendClientMessage(playerid,Red,"That house id does not exists.");
    format(String,sizeof(String),"You have successfully deleted a house. ID: %i.",houseid);
    SendClientMessage(playerid,Yellow,String);
    DestroyDynamicCP(HouseInfo[houseid][hCP]);
    Delete3DTextLabel(HouseInfo[houseid][hLabel]);
    dini_Remove(file);
    return 1;
}

//This command is used to sell a House (only owners can use it).
COMMAND:sellhouse(playerid, params[])
{
    if(GetPlayerHouseID(playerid) == -1)return SendClientMessage(playerid,Red,"You do not own a house.");
    ShowPlayerDialog(playerid,220,DIALOG_STYLE_MSGBOX,"Sell House","Do you want to sell your house?","Sell","Cancel");
    return 1;
}

//This function gets the owner of a specific House.
stock GetBusOwner(housesid)
{
    new owner[MAX_PLAYER_NAME];
    format(owner, MAX_PLAYER_NAME, NO_OWNER);
    format(String, sizeof(String), "House/%i.ini", housesid);
    if(dini_Exists(String))
    {
        format(owner, MAX_PLAYER_NAME, "%s", dini_Get(String, "Owner"));
        return owner;
    }
    return owner;
}

//This function gets a House ID (it also tells if a player owns a House or not).
stock GetPlayerHouseID(playerid)
{
    for(new i = 0;i<MAX_HOUSES;i++)
    {
        format(String,sizeof(String),"House/%i.ini",i);
        if(dini_Exists(String))
        {
            GetPlayerName(playerid,Name,sizeof(Name));
            if(strcmp(Name,dini_Get(String,"Owner"),false) == 0)
            {
                return i;
            }
        }
    }
    return -1;
}

//This command removes a player from owning a House.
COMMAND:dehouse(playerid, params[])
{
    new id;
    if(!IsPlayerAdmin(playerid))return 0;
    if(sscanf(params,"u", id))return SendClientMessage(playerid, 0xFF0000AA, "Usage: /dehouse [id]");
    if(GetPlayerHouseID(id) == -1)return SendClientMessage(playerid,Red,"That player does not own a house.");
    format(String,sizeof(String),"House/%i.ini",GetPlayerHouseID(id));
    format(Label, sizeof(Label), "House Name: %s\nOwner: No Owner\nCost: $%i",dini_Get(String, "Name"),dini_Int(String, "Cost"));
    Update3DTextLabelText(HouseInfo[GetPlayerHouseID(id)][hLabel],White,Label);
    dini_Set(String, "Owner","No Owner");
    dini_IntSet(String, "Cost",dini_Int(String, "Cost"));
    dini_IntSet(String, "interior",dini_Int(String, "interior"));
    dini_IntSet(String, "OwnedBus",0);
    dini_IntSet(String, "HasOwner",0);
    GivePlayerMoney(id,dini_Int(String, "Cost")/4);
    format(String, sizeof(String), "You have removed %s as the owner of his/her house.",Name);
    SendClientMessage(playerid,Red, String);
    return 1;
}

//This function loads every House.
stock LoadHouses()
{
    new count = 0;
    for(new i=0; i<MAX_HOUSES; i++)
    {
        format(String,sizeof(String),"House/%i.ini",i);
        if(dini_Exists(String))
        {
            HouseInfo[i][hCP] = CreateDynamicCP(dini_Float(String, "BusX"),dini_Float(String, "BusY"),dini_Float(String, "BusZ"),1.0,dini_Int(String, "World"),dini_Int(String, "interior"),-1,100.0);
            if(!strcmp(GetBusOwner(i), NO_OWNER, CASE_SENSETIVE))
            {
                format(Label, sizeof(Label), "House Name: %s\nOwner: No Owner\nCost: $%i\ninterior: $%i",dini_Get(String, "Name"),dini_Int(String, "Cost"),dini_Int(String, "interior"));
                HouseInfo[i][hLabel] = Create3DTextLabel(Label,White,dini_Float(String, "BusX"),dini_Float(String, "BusY"),dini_Float(String, "BusZ")+1,100.0,0,1);
            }
            if(strcmp(GetBusOwner(i), NO_OWNER, CASE_SENSETIVE))
            {
                format(Label, sizeof(Label), "House Name: %s\nOwner: %s\nCost: $%i\ninterior: $%i",dini_Get(String, "Name"), dini_Get(String, "Owner"),dini_Int(String, "Cost"),dini_Int(String, "interior"));
                HouseInfo[i][hLabel] = Create3DTextLabel(Label,White,dini_Float(String, "BusX"),dini_Float(String, "BusY"),dini_Float(String, "BusZ")+1,100.0,0,1);
            }
            count++;
        }
    }
    return printf("Total Housees Loaded: %i",count);
}

//This function gets the last bused House ID.
stock GetLastHouseID()
{
    new count = 0;
    for(new i=0; i<MAX_HOUSES; i++)
    {
        format(String,sizeof(String),"House/%i.ini",i);
        {
            count++;
        }
    }
    return count;
}

//This function unloads every House.
stock UnloadHouses()
{
    for(new i=0; i<MAX_HOUSES; i++)
    {
        Delete3DTextLabel(HouseInfo[i][hLabel]);
        DestroyDynamicCP(HouseInfo[i][hCP]);
    }
    return 1;
}
Actually, it all works but it has 3 things bugged.
I don't know what i did wrong in the script for that it cause 3 bugs ig..

1st Bug: The everything saves in the dini file without interior
2nd Bug: The houses saves in the folder successfully but they dont load when i close server and open it.
3rd Bug: when i buy the house it spams in chat "You've purchase the .", it doesnt stop spamming

If you know how to fix these bugs which are caused in the script, then pleaze fix it and give it to me then,.
Thanks
Regards,
RyanPetersons
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)