Forum

> > CS2D > Scripts > House SysTem
Forums overviewCS2D overview Scripts overviewLog in to reply

English House SysTem

No replies
To the start Previous 1 Next To the start

old House SysTem

Mr_God
User Off Offline

Quote
Dear us
this script made by starkkz

yesterday , i tested this script with my friends
but have some errors
+     when i created a house , i went to buy it
but my friends could open it but he wasn't owner of this house !
+     when they leave , house is empty but people cant buy it !
here code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
PropertyRegistry = {}

function PropertyExists(name)
     return PropertyRegistry[name] ~= nil
end

function PropertyOwned(name)
     if PropertyExists(name) then
          return PropertyRegistry[name].owner > 0
     end
end

function BuyProperty(playerid,name)
     if PropertyExists(name) then
          if rp_money[playerid] >= PropertyRegistry[name].price then
               if not PropertyOwned(name) then
                    if player(playerid,"usgn") > 0 then
                         rp_money[playerid] = rp_money[playerid] - PropertyRegistry[name].price
                         PropertyRegistry[name].owner = player(playerid, "usgn")
                    else
                         -- PLAYER IS NOT REGISTERED
                    end
               else
                    -- PROPERTY ALREADY BOUGHT
               end
          else
               -- NOT ENOUGH MONEY
          end
     else
          -- PROPERTY DOESN'T EXIST
     end
end

function PropertyAtPos(x,y)
     for name, prop in pairs(PropertyRegistry) do
          if x >= prop.areaStartX and y >= prop.areaStartY and x <= prop.areaEndX and y <= prop.areaEndY then
               return name
          end
     end
end

addhook("trigger","onTrigger")
function onTrigger(name)
     if LockedEntity[name] then
          LockedEntity[name] = false
          return 1
     end
end

LockedEntity = {}
addhook("use","onUse")
function onUse(id,event,data,x,y)
     if event == 100 then
          local property_name = PropertyAtPos(x, y)
          if PropertyExists(property_name) then
               if PropertyRegistry[property_name].owner == player(id, "usgn") then
                    -- Triggered by owner, proceed normally
               else
                    -- Not triggered by owner, lock the trigger name
                    LockedEntity[entity(x, y, "name")] = true
                    
                    -- Do buy action
                    menu(id, "Buy property ["..property_name.."],Yes|-$"..PropertyRegistry[property_name].price..",No")
               end
          end
     end
end

addhook("menu","onMenu")
function onMenu(id,title,selection)
     if string.sub(title, 1, 12) == "Buy Property" then
          local property_name = string.sub(title, 15, string.len(title)-1)
          if string.len(property_name) > 0 and selection == 1 then
               BuyProperty(id, property_name)
          end
     end
end

function MakeProperty(name)
     return function (area)
          return function (triggers)
               return function (price)
                    PropertyRegistry[name] = {
                         areaStartX = area[1],
                         areaStartY = area[2],
                         areaEndX = area[3],
                         areaEndY = area[4],
                         triggers = triggers,
                         price = price[1],
                         
                         -- USGN owner
                         owner = 0,
                    }
               end
          end
     end
end

-- EXAMPLE
MakeProperty"House1"{15,20,30,35}{"door1","door2","door3"}{1500}
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview