| 11-11-2007, 09:04 PM | #1 |
Ok the following is a complete system for houses. I built this system only a little while ago. However it seems to cause additional lag in-game. Also since I've started building this system, the game has completely froze both times I played. Also the time it freezes doesn't seem to be very consistent. Can anyone point out some ways to streamline this system? I'm pretty sure its leakless so far. JASS:globals //Remove this section during copy trigger gg_trg_SYS_Full unit gg_unit_n009_0106 unit gg_unit_n009_0107 rect gg_rct_HUS_2_Prop rect gg_rct_HUS_1_Prop trigger gg_trg_RunWayGate //Keep the rest trigger GKnockback trigger GCheckCheck trigger GBuildTrack trigger GLeave group udg_CheckGroup boolean array udg_HAsBOught endglobals function MHredo takes unit original returns unit local real PosX = GetUnitX(original) local real PosY = GetUnitY(original) local player Owner = GetOwningPlayer(original) local real facing = GetUnitFacing(original) local integer utype = GetUnitTypeId(original) call RemoveUnit(original) return CreateUnit(Owner, utype, PosX, PosY, facing) endfunction function IsUnitInRect takes unit u, rect r returns boolean local region reg = CreateRegion() local boolean b call RegionAddRect( reg, r ) set b = IsUnitInRegion( reg, u ) call RemoveRegion( reg ) set reg = null return b endfunction function INITHOUSE takes unit Realtor, rect landplot returns nothing call AttachObject(Realtor, "Plot", landplot) call AttachBoolean(Realtor, "Sold", false) call AttachInt(Realtor, "Owner", 12) call TriggerRegisterLeaveRectSimple(GKnockback, landplot) endfunction function DestroyBuilder takes unit Builder returns nothing call AttachReal(Builder, "Xlc", 0) call AttachReal(Builder, "Ylc", 0) call AttachObject(Builder, "Realtor", null) call GroupRemoveUnit(udg_CheckGroup, Builder) call RemoveUnit(Builder) endfunction function CreateBuilder takes unit Realtor, player Owner returns nothing local rect Plot = GetAttachedRect(Realtor, "Plot") local real Gx = GetRectCenterX(Plot) local real Gy = GetRectCenterY(Plot) local unit totuni = CreateUnit(Owner,'u008', Gx, Gy, 120) call AttachReal(totuni, "Xlc", Gx) call AttachReal(totuni, "Ylc", Gy) call AttachObject(totuni, "Realtor", Realtor) call AttachObject(Realtor, "Builder", totuni) call GroupAddUnit(udg_CheckGroup, totuni) set totuni = null set Plot = null endfunction function CheckForDestroy takes nothing returns boolean if GetUnitAbilityLevel(GetFilterUnit(),'A024') == 0 then return false endif return true endfunction function RemoveHouse takes nothing returns nothing local unit u = GetEnumUnit() local integer ma = R2I(I2R(GetUnitPointValue(u)) * .8) local integer ka = GetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD) + ma call SetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD, ka) call KillUnit(u) call DisplayTimedTextToPlayer(GetOwningPlayer(u),0,0,60,"|c0000F4F4You get " + I2S(ma) + " for selling a " + GetObjectName(GetUnitTypeId(u)) + "|r") call RemoveUnit(u) set u = null endfunction function Trig_SYS_Full_Actions takes nothing returns nothing local unit Morg = GetSellingUnit() local rect Plot = GetAttachedRect(Morg, "Plot") local boolean IsSold = GetAttachedBoolean(Morg, "Sold") local player Meor = GetOwningPlayer(GetBuyingUnit()) local integer Ityped = GetItemTypeId(GetSoldItem()) if (Ityped =='I00A') or (Ityped == 'I009') then if IsSold then call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900Someone has already bought this land, try a different location") else if udg_HAsBOught[GetPlayerId(Meor)] then call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You can only own one property at a time") else call CreateBuilder(Morg, Meor) call AttachBoolean(Morg, "Sold", true) call AttachInt(Morg, "Owner", GetPlayerId(Meor)) set udg_HAsBOught[GetPlayerId(Meor)] = true call AttachObject(Meor, "xRealtor", Morg) call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You have bought a plot of land, you can now use the builder to build a house.") endif endif call TriggerSleepAction(.29) call RemoveItem(GetSoldItem()) else if Ityped == 'I00B' then if Meor == Player(GetAttachedInt(Morg,"Owner")) then set udg_HAsBOught[GetPlayerId(Meor)] = false call AttachObject(Meor, "xRealtor", null) call AttachBoolean(Morg, "Sold", false) call DestroyBuilder(GetAttachedUnit(Morg, "Builder")) call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You have now sold all your land.") call SetPlayerState(Meor, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Meor, PLAYER_STATE_RESOURCE_GOLD) + 400) call ForGroup( GetUnitsOfPlayerMatching(Player(0), Condition(function CheckForDestroy)), function RemoveHouse ) else call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You do not own this land, so you can not sell it.") endif call TriggerSleepAction(.29) call RemoveItem(GetSoldItem()) endif endif set Plot = null set Morg = null endfunction function RestPost takes nothing returns nothing local unit u = GetTriggerUnit() local real Spotx = GetAttachedReal(u, "Xlc") local real Spoty = GetAttachedReal(u, "Ylc") call SetUnitX(u, Spotx) call SetUnitY(u, Spoty) call IssueImmediateOrder(u, "stop") set u = null endfunction function CheckPost takes nothing returns boolean if IsUnitInGroup(GetTriggerUnit(),udg_CheckGroup) then return true endif return false endfunction function CheckLoc takes nothing returns nothing local unit u = GetEnumUnit() local unit Mok = GetAttachedUnit(u,"Realtor") local rect Mak = GetAttachedRect(Mok, "Plot") local real Spotx = GetAttachedReal(u, "Xlc") local real Spoty = GetAttachedReal(u, "Ylc") if IsUnitInRect(u,Mak) == false then call SetUnitX(u, Spotx) call SetUnitY(u, Spoty) call IssueImmediateOrder(u, "stop") endif set u = null set Mok = null set Mak = null endfunction function CheckThem takes nothing returns nothing call ForGroup(udg_CheckGroup, function CheckLoc) endfunction //=========================================================================== function InitTrig_SYS_Full takes nothing returns nothing local integer int= 12 set gg_trg_SYS_Full = CreateTrigger( ) set GKnockback = CreateTrigger() set GCheckCheck = CreateTrigger() //NotAlly call TriggerAddAction(GCheckCheck, function CheckThem) call TriggerRegisterTimerEvent(GCheckCheck, 2, true) call TriggerAddCondition( GKnockback, Condition( function CheckPost ) ) call TriggerAddAction( GKnockback, function RestPost ) call TriggerRegisterAnyUnitEventBJ( gg_trg_SYS_Full, EVENT_PLAYER_UNIT_SELL_ITEM ) call TriggerAddAction( gg_trg_SYS_Full, function Trig_SYS_Full_Actions ) loop exitwhen int == 0 set udg_HAsBOught[int]=false set int = int - 1 endloop set udg_CheckGroup = CreateGroup() call INITHOUSE(gg_unit_n009_0107 , gg_rct_HUS_2_Prop) call INITHOUSE(gg_unit_n009_0106 , gg_rct_HUS_1_Prop) //call INITHOUSE(gg_unit_n009_0013 , gg_rct_HUS_3_Prop) //call INITHOUSE(gg_unit_n009_0111 , gg_rct_HUS_4_Prop) //call INITHOUSE(gg_unit_n009_0108 , gg_rct_HUS_5_Prop) //call INITHOUSE(gg_unit_n009_0112 , gg_rct_HUS_6_Prop) endfunction |
| 11-12-2007, 05:20 AM | #2 |
Use structs instead of attached variables. |
| 11-12-2007, 05:19 PM | #3 |
I'm lagging a bit behind when it comes to structs. Could you give me an example? I'm sure I'll be able to extrapolate from there. |
| 11-14-2007, 06:48 AM | #4 |
Sorry for the double post, but this is a rather large development. I went and learned structs. (took about 20 min.) Very useful, yet I can't quite get this to work. The function 'INITHOUSE' seems to be registering the wrong landplots with the wrong Realtors. Why? JASS:struct SRealtorT rect plot boolean sold integer owner endstruct struct BPlayer rect plot unit realt real Setxb real Setyb unit builder endstruct globals //Keep the rest BPlayer array AllPB trigger GKnockback trigger GCheckCheck trigger GBuildTrack trigger GLeave group udg_CheckGroup boolean array udg_HAsBOught endglobals function INITHOUSE takes unit Realtor, rect landplot returns nothing local SRealtorT KA = SRealtorT.create() set KA.plot = landplot set KA.sold = false set KA.owner = 12 call AttachInt(Realtor, "Struct", KA) call SRealtorT.destroy(KA) call TriggerRegisterLeaveRectSimple(GKnockback, landplot) endfunction function DestroyBuilder takes unit Builder returns nothing call GroupRemoveUnit(udg_CheckGroup, Builder) call RemoveUnit(Builder) endfunction function CreateBuilder takes unit Realtor, player Owner, rect Plot returns nothing local real Gx = GetRectCenterX(Plot) local real Gy = GetRectCenterY(Plot) local unit totuni = CreateUnit(Owner,'u008', Gx, Gy, 120) set AllPB[GetPlayerId(Owner)].Setxb = Gx set AllPB[GetPlayerId(Owner)].Setyb = Gy set AllPB[GetPlayerId(Owner)].builder = totuni call GroupAddUnit(udg_CheckGroup, totuni) set totuni = null set Plot = null endfunction function CheckForDestroy takes nothing returns boolean if GetUnitAbilityLevel(GetFilterUnit(),'A024') == 0 then return false endif return true endfunction function RemoveHouse takes nothing returns nothing local unit u = GetEnumUnit() local integer ma = R2I(I2R(GetUnitPointValue(u)) * .8) local integer ka = GetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD) + ma call SetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD, ka) call KillUnit(u) call DisplayTimedTextToPlayer(GetOwningPlayer(u),0,0,60,"|c0000F4F4You get " + I2S(ma) + " for selling a " + GetObjectName(GetUnitTypeId(u)) + "|r") call RemoveUnit(u) set u = null endfunction function Trig_SYS_Full_Actions takes nothing returns nothing local unit Morg = GetSellingUnit() local SRealtorT Norm local player Meor = GetOwningPlayer(GetBuyingUnit()) local integer Ityped = GetItemTypeId(GetSoldItem()) if (Ityped =='I00A') or (Ityped == 'I009') then set Norm = SRealtorT( GetAttachedInt(Morg,"Struct")) if Norm.sold then call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900Someone has already bought this land, try a different location") else if udg_HAsBOught[GetPlayerId(Meor)] then call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You can only own one property at a time") else call CreateBuilder(Morg, Meor, Norm.plot) set Norm.sold = true set Norm.owner = GetPlayerId(Meor) set udg_HAsBOught[GetPlayerId(Meor)] = true set AllPB[GetPlayerId(Meor)].plot = Norm.plot set AllPB[GetPlayerId(Meor)].realt = Morg call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You have bought a plot of land, you can now use the builder to build a house.") endif endif call AttachInt(Morg, "Struct", Norm) call SRealtorT.destroy(Norm) call TriggerSleepAction(.29) call RemoveItem(GetSoldItem()) else if Ityped == 'I00B' then set Norm = SRealtorT( GetAttachedInt(Morg,"Struct")) if Meor == Player(Norm.owner) then set udg_HAsBOught[GetPlayerId(Meor)] = false call DestroyBuilder(AllPB[GetPlayerId(Meor)].builder) call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You have now sold all your land.") call SetPlayerState(Meor, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Meor, PLAYER_STATE_RESOURCE_GOLD) + 400) call ForGroup( GetUnitsOfPlayerMatching(Player(0), Condition(function CheckForDestroy)), function RemoveHouse ) else call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You do not own this land, so you can not sell it.") endif call AttachInt(Morg, "Struct", Norm) call SRealtorT.destroy(Norm) call TriggerSleepAction(.29) call RemoveItem(GetSoldItem()) endif endif set Morg = null endfunction function RestPost takes nothing returns nothing local unit u = GetTriggerUnit() local integer r = GetPlayerId(GetOwningPlayer(u)) call SetUnitX(u, AllPB[r].Setxb) call SetUnitY(u, AllPB[r].Setyb) call IssueImmediateOrder(u, "stop") set u = null endfunction function CheckPost takes nothing returns boolean if IsUnitInGroup(GetTriggerUnit(),udg_CheckGroup) then return true endif return false endfunction function CheckLoc takes nothing returns nothing local unit u = GetEnumUnit() local integer r = GetPlayerId(GetOwningPlayer(u)) if IsUnitInRect(u,AllPB[r].plot) == false then call SetUnitX(u, AllPB[r].Setxb) call SetUnitY(u, AllPB[r].Setyb) call IssueImmediateOrder(u, "stop") endif set u = null endfunction function CheckThem takes nothing returns nothing call ForGroup(udg_CheckGroup, function CheckLoc) endfunction //=========================================================================== function InitTrig_SYS_Full takes nothing returns nothing local integer int= 12 set gg_trg_SYS_Full = CreateTrigger( ) set GKnockback = CreateTrigger() set GCheckCheck = CreateTrigger() call TriggerAddAction(GCheckCheck, function CheckThem) call TriggerRegisterTimerEvent(GCheckCheck, 2, true) call TriggerAddCondition( GKnockback, Condition( function CheckPost ) ) call TriggerAddAction( GKnockback, function RestPost ) call TriggerRegisterAnyUnitEventBJ( gg_trg_SYS_Full, EVENT_PLAYER_UNIT_SELL_ITEM ) call TriggerAddAction( gg_trg_SYS_Full, function Trig_SYS_Full_Actions ) loop exitwhen int == 0 set udg_HAsBOught[int]=false set AllPB[int] = BPlayer.create() set int = int - 1 endloop set udg_CheckGroup = CreateGroup() call INITHOUSE(gg_unit_n009_0107 , gg_rct_HUS_2_Prop) call INITHOUSE(gg_unit_n009_0106 , gg_rct_HUS_1_Prop) call INITHOUSE(gg_unit_n009_0013 , gg_rct_HUS_3_Prop) call INITHOUSE(gg_unit_n009_0111 , gg_rct_HUS_4_Prop) call INITHOUSE(gg_unit_n009_0108 , gg_rct_HUS_5_Prop) call INITHOUSE(gg_unit_n009_0112 , gg_rct_HUS_6_Prop) endfunction |
| 11-14-2007, 06:56 AM | #5 |
Well, you're destroying the struct right after you allocate it: JASS://... set KA.owner = 12 call AttachInt(Realtor, "Struct", KA) call SRealtorT.destroy(KA) call TriggerRegisterLeaveRectSimple(GKnockback, landplot) //... I'm pretty sure you don't want to destroy it right then, else the Realtor will always be null because there's no struct to reference. |
| 11-14-2007, 01:42 PM | #6 |
Ok, thats what I needed. Let me go test it out. |
| 11-14-2007, 02:59 PM | #7 |
As far as I can see youre leaking one variable. If I understood everything correctly then you have to null every type of variable that extends variables of type handle ( including variable types that extend a variable type which extends handle variables). You also should destroy/remove groups forces locations and whatnot (but be careful: dont remove any variable that is required for gameplay, e.g. player or units, instead simply null them) Here's what I would use: JASS:struct SRealtorT rect plot boolean sold integer owner endstruct struct BPlayer rect plot unit realt real Setxb real Setyb unit builder endstruct globals //Keep the rest BPlayer array AllPB trigger GKnockback trigger GCheckCheck trigger GBuildTrack trigger GLeave group udg_CheckGroup boolean array udg_HAsBOught endglobals function INITHOUSE takes unit Realtor, rect landplot returns nothing local SRealtorT KA = SRealtorT.create() set KA.plot = landplot set KA.sold = false set KA.owner = 12 call AttachInt(Realtor, "Struct", KA) call SRealtorT.destroy(KA) call TriggerRegisterLeaveRectSimple(GKnockback, landplot) endfunction function DestroyBuilder takes unit Builder returns nothing call GroupRemoveUnit(udg_CheckGroup, Builder) call RemoveUnit(Builder) endfunction function CreateBuilder takes unit Realtor, player Owner, rect Plot returns nothing local real Gx = GetRectCenterX(Plot) local real Gy = GetRectCenterY(Plot) local unit totuni = CreateUnit(Owner,'u008', Gx, Gy, 120) set AllPB[GetPlayerId(Owner)].Setxb = Gx set AllPB[GetPlayerId(Owner)].Setyb = Gy set AllPB[GetPlayerId(Owner)].builder = totuni call GroupAddUnit(udg_CheckGroup, totuni) set totuni = null set Plot = null endfunction function CheckForDestroy takes nothing returns boolean return GetUnitAbilityLevel(GetFilterUnit(),'A024') == 0 endfunction function RemoveHouse takes nothing returns nothing local unit u = GetEnumUnit() local integer ma = R2I(I2R(GetUnitPointValue(u)) * .8) local integer ka = GetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD) + ma call SetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD, ka) call KillUnit(u) call DisplayTimedTextToPlayer(GetOwningPlayer(u),0,0,60,"|c0000F4F4You get " + I2S(ma) + " for selling a " + GetObjectName(GetUnitTypeId(u)) + "|r") call RemoveUnit(u) set u = null endfunction function Trig_SYS_Full_Actions takes nothing returns nothing local unit Morg = GetSellingUnit() local SRealtorT Norm local player Meor = GetOwningPlayer(GetBuyingUnit()) local integer Ityped = GetItemTypeId(GetSoldItem()) if (Ityped =='I00A') or (Ityped == 'I009') then set Norm = SRealtorT( GetAttachedInt(Morg,"Struct")) if Norm.sold then call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900Someone has already bought this land, try a different location") else if udg_HAsBOught[GetPlayerId(Meor)] then call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You can only own one property at a time") else call CreateBuilder(Morg, Meor, Norm.plot) set Norm.sold = true set Norm.owner = GetPlayerId(Meor) set udg_HAsBOught[GetPlayerId(Meor)] = true set AllPB[GetPlayerId(Meor)].plot = Norm.plot set AllPB[GetPlayerId(Meor)].realt = Morg call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You have bought a plot of land, you can now use the builder to build a house.") endif endif call AttachInt(Morg, "Struct", Norm) call SRealtorT.destroy(Norm) call TriggerSleepAction(.29) call RemoveItem(GetSoldItem()) else if Ityped == 'I00B' then set Norm = SRealtorT( GetAttachedInt(Morg,"Struct")) if Meor == Player(Norm.owner) then set udg_HAsBOught[GetPlayerId(Meor)] = false call DestroyBuilder(AllPB[GetPlayerId(Meor)].builder) call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You have now sold all your land.") call SetPlayerState(Meor, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Meor, PLAYER_STATE_RESOURCE_GOLD) + 400) call ForGroup( GetUnitsOfPlayerMatching(Player(0), Condition(function CheckForDestroy)), function RemoveHouse ) else call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You do not own this land, so you can not sell it.") endif call AttachInt(Morg, "Struct", Norm) call SRealtorT.destroy(Norm) call TriggerSleepAction(.29) call RemoveItem(GetSoldItem()) endif endif set Morg = null set Meor = null endfunction function RestPost takes nothing returns nothing local unit u = GetTriggerUnit() local integer r = GetPlayerId(GetOwningPlayer(u)) call SetUnitX(u, AllPB[r].Setxb) call SetUnitY(u, AllPB[r].Setyb) call IssueImmediateOrder(u, "stop") set u = null endfunction function CheckPost takes nothing returns boolean return IsUnitInGroup(GetTriggerUnit(),udg_CheckGroup) endfunction function CheckLoc takes nothing returns nothing local unit u = GetEnumUnit() local integer r = GetPlayerId(GetOwningPlayer(u)) if IsUnitInRect(u,AllPB[r].plot) == false then call SetUnitX(u, AllPB[r].Setxb) call SetUnitY(u, AllPB[r].Setyb) call IssueImmediateOrder(u, "stop") endif set u = null endfunction function CheckThem takes nothing returns nothing call ForGroup(udg_CheckGroup, function CheckLoc) endfunction //=========================================================================== function InitTrig_SYS_Full takes nothing returns nothing local integer int= 12 set gg_trg_SYS_Full = CreateTrigger( ) set GKnockback = CreateTrigger() set GCheckCheck = CreateTrigger() call TriggerAddAction(GCheckCheck, function CheckThem) call TriggerRegisterTimerEvent(GCheckCheck, 2, true) call TriggerAddCondition( GKnockback, Condition( function CheckPost ) ) call TriggerAddAction( GKnockback, function RestPost ) call TriggerRegisterAnyUnitEventBJ( gg_trg_SYS_Full, EVENT_PLAYER_UNIT_SELL_ITEM ) call TriggerAddAction( gg_trg_SYS_Full, function Trig_SYS_Full_Actions ) loop exitwhen int == 0 set udg_HAsBOught[int]=false set AllPB[int] = BPlayer.create() set int = int - 1 endloop set udg_CheckGroup = CreateGroup() call INITHOUSE(gg_unit_n009_0107 , gg_rct_HUS_2_Prop) call INITHOUSE(gg_unit_n009_0106 , gg_rct_HUS_1_Prop) call INITHOUSE(gg_unit_n009_0013 , gg_rct_HUS_3_Prop) call INITHOUSE(gg_unit_n009_0111 , gg_rct_HUS_4_Prop) call INITHOUSE(gg_unit_n009_0108 , gg_rct_HUS_5_Prop) call INITHOUSE(gg_unit_n009_0112 , gg_rct_HUS_6_Prop) endfunction Deaod EDIT: Im sorry bomber, if I disgraced you. It was my fault. I first went through you first code-example, but then took your second one and posted about that one. Your first one leaked one variable more though plus it was at the very beginning and I didn't read through the complete code. JASS:globals //Remove this section during copy trigger gg_trg_SYS_Full unit gg_unit_n009_0106 unit gg_unit_n009_0107 rect gg_rct_HUS_2_Prop rect gg_rct_HUS_1_Prop trigger gg_trg_RunWayGate //Keep the rest trigger GKnockback trigger GCheckCheck trigger GBuildTrack trigger GLeave group udg_CheckGroup boolean array udg_HAsBOught endglobals function MHredo takes unit original returns unit local real PosX = GetUnitX(original) local real PosY = GetUnitY(original) local player Owner = GetOwningPlayer(original) local real facing = GetUnitFacing(original) local integer utype = GetUnitTypeId(original) call RemoveUnit(original) return CreateUnit(Owner, utype, PosX, PosY, facing) endfunction function IsUnitInRect takes unit u, rect r returns boolean local region reg = CreateRegion() local boolean b call RegionAddRect( reg, r ) set b = IsUnitInRegion( reg, u ) call RemoveRegion( reg ) set reg = null return b endfunction function INITHOUSE takes unit Realtor, rect landplot returns nothing call AttachObject(Realtor, "Plot", landplot) call AttachBoolean(Realtor, "Sold", false) call AttachInt(Realtor, "Owner", 12) call TriggerRegisterLeaveRectSimple(GKnockback, landplot) endfunction function DestroyBuilder takes unit Builder returns nothing call AttachReal(Builder, "Xlc", 0) call AttachReal(Builder, "Ylc", 0) call AttachObject(Builder, "Realtor", null) call GroupRemoveUnit(udg_CheckGroup, Builder) call RemoveUnit(Builder) endfunction function CreateBuilder takes unit Realtor, player Owner returns nothing local rect Plot = GetAttachedRect(Realtor, "Plot") local real Gx = GetRectCenterX(Plot) local real Gy = GetRectCenterY(Plot) local unit totuni = CreateUnit(Owner,'u008', Gx, Gy, 120) call AttachReal(totuni, "Xlc", Gx) call AttachReal(totuni, "Ylc", Gy) call AttachObject(totuni, "Realtor", Realtor) call AttachObject(Realtor, "Builder", totuni) call GroupAddUnit(udg_CheckGroup, totuni) set totuni = null set Plot = null endfunction function CheckForDestroy takes nothing returns boolean return GetUnitAbilityLevel(GetFilterUnit(),'A024') == 0 endfunction function RemoveHouse takes nothing returns nothing local unit u = GetEnumUnit() local integer ma = R2I(I2R(GetUnitPointValue(u)) * .8) local integer ka = GetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD) + ma call SetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD, ka) call KillUnit(u) call DisplayTimedTextToPlayer(GetOwningPlayer(u),0,0,60,"|c0000F4F4You get " + I2S(ma) + " for selling a " + GetObjectName(GetUnitTypeId(u)) + "|r") call RemoveUnit(u) set u = null endfunction function Trig_SYS_Full_Actions takes nothing returns nothing local unit Morg = GetSellingUnit() local rect Plot = GetAttachedRect(Morg, "Plot") local boolean IsSold = GetAttachedBoolean(Morg, "Sold") local player Meor = GetOwningPlayer(GetBuyingUnit()) local integer Ityped = GetItemTypeId(GetSoldItem()) if (Ityped =='I00A') or (Ityped == 'I009') then if IsSold then call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900Someone has already bought this land, try a different location") else if udg_HAsBOught[GetPlayerId(Meor)] then call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You can only own one property at a time") else call CreateBuilder(Morg, Meor) call AttachBoolean(Morg, "Sold", true) call AttachInt(Morg, "Owner", GetPlayerId(Meor)) set udg_HAsBOught[GetPlayerId(Meor)] = true call AttachObject(Meor, "xRealtor", Morg) call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You have bought a plot of land, you can now use the builder to build a house.") endif endif call TriggerSleepAction(.29) call RemoveItem(GetSoldItem()) else if Ityped == 'I00B' then if Meor == Player(GetAttachedInt(Morg,"Owner")) then set udg_HAsBOught[GetPlayerId(Meor)] = false call AttachObject(Meor, "xRealtor", null) call AttachBoolean(Morg, "Sold", false) call DestroyBuilder(GetAttachedUnit(Morg, "Builder")) call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You have now sold all your land.") call SetPlayerState(Meor, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Meor, PLAYER_STATE_RESOURCE_GOLD) + 400) call ForGroup( GetUnitsOfPlayerMatching(Player(0), Condition(function CheckForDestroy)), function RemoveHouse ) else call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You do not own this land, so you can not sell it.") endif call TriggerSleepAction(.29) call RemoveItem(GetSoldItem()) endif endif set Plot = null set Morg = null endfunction function RestPost takes nothing returns nothing local unit u = GetTriggerUnit() local real Spotx = GetAttachedReal(u, "Xlc") local real Spoty = GetAttachedReal(u, "Ylc") call SetUnitX(u, Spotx) call SetUnitY(u, Spoty) call IssueImmediateOrder(u, "stop") set u = null endfunction function CheckPost takes nothing returns boolean return IsUnitInGroup(GetTriggerUnit(),udg_CheckGroup) endfunction function CheckLoc takes nothing returns nothing local unit u = GetEnumUnit() local unit Mok = GetAttachedUnit(u,"Realtor") local rect Mak = GetAttachedRect(Mok, "Plot") local real Spotx = GetAttachedReal(u, "Xlc") local real Spoty = GetAttachedReal(u, "Ylc") if IsUnitInRect(u,Mak) == false then call SetUnitX(u, Spotx) call SetUnitY(u, Spoty) call IssueImmediateOrder(u, "stop") endif set u = null set Mok = null set Mak = null endfunction function CheckThem takes nothing returns nothing call ForGroup(udg_CheckGroup, function CheckLoc) endfunction //=========================================================================== function InitTrig_SYS_Full takes nothing returns nothing local integer int= 12 set gg_trg_SYS_Full = CreateTrigger( ) set GKnockback = CreateTrigger() set GCheckCheck = CreateTrigger() //NotAlly call TriggerAddAction(GCheckCheck, function CheckThem) call TriggerRegisterTimerEvent(GCheckCheck, 2, true) call TriggerAddCondition( GKnockback, Condition( function CheckPost ) ) call TriggerAddAction( GKnockback, function RestPost ) call TriggerRegisterAnyUnitEventBJ( gg_trg_SYS_Full, EVENT_PLAYER_UNIT_SELL_ITEM ) call TriggerAddAction( gg_trg_SYS_Full, function Trig_SYS_Full_Actions ) loop exitwhen int == 0 set udg_HAsBOught[int]=false set int = int - 1 endloop set udg_CheckGroup = CreateGroup() call INITHOUSE(gg_unit_n009_0107 , gg_rct_HUS_2_Prop) call INITHOUSE(gg_unit_n009_0106 , gg_rct_HUS_1_Prop) //call INITHOUSE(gg_unit_n009_0013 , gg_rct_HUS_3_Prop) //call INITHOUSE(gg_unit_n009_0111 , gg_rct_HUS_4_Prop) //call INITHOUSE(gg_unit_n009_0108 , gg_rct_HUS_5_Prop) //call INITHOUSE(gg_unit_n009_0112 , gg_rct_HUS_6_Prop) endfunction By the way: did you notice I changed some other functions? Hope, you aren't mad at me. Deaod |
| 11-14-2007, 04:41 PM | #8 |
Lol disgraced? Hahaha. You make it sound like I had a reputation. Everyone needs a bit of constructive criticism. Yes I did see your other changes, I already added them. Thank you for your help. It worked. |
| 11-15-2007, 02:55 AM | #9 |
*Sorry again for the double post* I'm having quite a serious problem. I need to be sure that this system can not be in anyway the cause of this problem. I watched the memory of the game. It seemed to hike up when I bought a house. Worse it continued to grow about 12kb every 1/4 of a second, until I quit. (Ended at 300kb memory usage for wc3) Thats one hell of a memory leak. Most recently updated code: JASS:struct SRealtorT rect plot boolean sold integer owner endstruct struct BPlayer rect plot unit realt real Setxb real Setyb unit builder endstruct globals //Remove this section during copy trigger gg_trg_SYS_Full unit gg_unit_n009_0106 unit gg_unit_n009_0107 rect gg_rct_HUS_2_Prop rect gg_rct_HUS_1_Prop trigger gg_trg_RunWayGate //Keep the rest BPlayer array AllPB trigger GKnockback trigger GCheckCheck trigger GBuildTrack trigger GLeave group udg_CheckGroup boolean array udg_HAsBOught endglobals function INITHOUSE takes unit Realtor, rect landplot returns nothing local SRealtorT KA = SRealtorT.create() set KA.plot = landplot set KA.sold = false set KA.owner = 12 call AttachInt(Realtor, "Struct", KA) //call SRealtorT.destroy(KA) call TriggerRegisterLeaveRectSimple(GKnockback, landplot) endfunction function MHredo takes unit original returns unit local real PosX = GetUnitX(original) local real PosY = GetUnitY(original) local player Owner = GetOwningPlayer(original) local real facing = GetUnitFacing(original) local integer utype = GetUnitTypeId(original) call RemoveUnit(original) return CreateUnit(Owner, utype, PosX, PosY, facing) endfunction function IsUnitInRect takes unit u, rect r returns boolean local region reg = CreateRegion() local boolean b call RegionAddRect( reg, r ) set b = IsUnitInRegion( reg, u ) call RemoveRegion( reg ) set reg = null return b endfunction function DestroyBuilder takes unit Builder returns nothing call GroupRemoveUnit(udg_CheckGroup, Builder) call RemoveUnit(Builder) endfunction function CreateBuilder takes unit Realtor, player Owner, rect Plot returns nothing local real Gx = GetRectCenterX(Plot) local real Gy = GetRectCenterY(Plot) local unit totuni = CreateUnit(Owner,'u008', Gx, Gy, 120) set AllPB[GetPlayerId(Owner)].Setxb = Gx set AllPB[GetPlayerId(Owner)].Setyb = Gy set AllPB[GetPlayerId(Owner)].builder = totuni call GroupAddUnit(udg_CheckGroup, totuni) set totuni = null set Plot = null endfunction function CheckForDestroy takes nothing returns boolean return (GetUnitAbilityLevel(GetFilterUnit(),'A024') == 0) endfunction function RemoveHouse takes nothing returns nothing local unit u = GetEnumUnit() local integer ma = R2I(I2R(GetUnitPointValue(u)) * .8) local integer ka = GetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD) + ma call SetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD, ka) call KillUnit(u) call DisplayTimedTextToPlayer(GetOwningPlayer(u),0,0,60,"|c0000F4F4You get " + I2S(ma) + " for selling a " + GetObjectName(GetUnitTypeId(u)) + "|r") call RemoveUnit(u) set u = null endfunction function Trig_SYS_Full_Actions takes nothing returns nothing local unit Morg = GetSellingUnit() local SRealtorT Norm local player Meor = GetOwningPlayer(GetBuyingUnit()) local integer Ityped = GetItemTypeId(GetSoldItem()) if (Ityped =='I00A') or (Ityped == 'I009') then set Norm = SRealtorT( GetAttachedInt(Morg,"Struct")) if Norm.sold then call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900Someone has already bought this land, try a different location") else if udg_HAsBOught[GetPlayerId(Meor)] then call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You can only own one property at a time") else call CreateBuilder(Morg, Meor, Norm.plot) set Norm.sold = true set Norm.owner = GetPlayerId(Meor) set udg_HAsBOught[GetPlayerId(Meor)] = true set AllPB[GetPlayerId(Meor)].plot = Norm.plot set AllPB[GetPlayerId(Meor)].realt = Morg call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You have bought a plot of land, you can now use the builder to build a house.") endif endif call AttachInt(Morg, "Struct", Norm) // call SRealtorT.destroy(Norm) call TriggerSleepAction(.29) call RemoveItem(GetSoldItem()) else if Ityped == 'I00B' then set Norm = SRealtorT( GetAttachedInt(Morg,"Struct")) if Meor == Player(Norm.owner) then set udg_HAsBOught[GetPlayerId(Meor)] = false call DestroyBuilder(AllPB[GetPlayerId(Meor)].builder) call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You have now sold all your land.") call SetPlayerState(Meor, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Meor, PLAYER_STATE_RESOURCE_GOLD) + 400) call ForGroup( GetUnitsOfPlayerMatching(Player(0), Condition(function CheckForDestroy)), function RemoveHouse ) else call DisplayTextToForce(GetForceOfPlayer(Meor),"|c00F27900You do not own this land, so you can not sell it.") endif call AttachInt(Morg, "Struct", Norm) // call SRealtorT.destroy(Norm) call TriggerSleepAction(.29) call RemoveItem(GetSoldItem()) endif endif set Morg = null set Meor = null endfunction function RestPost takes nothing returns nothing return (IsUnitInGroup(GetTriggerUnit(),udg_CheckGroup)) endfunction function CheckPost takes nothing returns boolean return(IsUnitInGroup(GetTriggerUnit(),udg_CheckGroup)) endfunction function CheckLoc takes nothing returns nothing local unit u = GetEnumUnit() local integer r = GetPlayerId(GetOwningPlayer(u)) if IsUnitInRect(u,AllPB[r].plot) == false then call SetUnitX(u, AllPB[r].Setxb) call SetUnitY(u, AllPB[r].Setyb) call IssueImmediateOrder(u, "stop") endif set u = null endfunction function CheckThem takes nothing returns nothing call ForGroup(udg_CheckGroup, function CheckLoc) endfunction //=========================================================================== function InitTrig_SYS_Full takes nothing returns nothing local integer int= 11 set gg_trg_SYS_Full = CreateTrigger( ) set GKnockback = CreateTrigger() set GCheckCheck = CreateTrigger() //NotAlly call TriggerAddAction(GCheckCheck, function CheckThem) call TriggerRegisterTimerEvent(GCheckCheck, 2, true) call TriggerAddCondition( GKnockback, Condition( function CheckPost ) ) call TriggerAddAction( GKnockback, function RestPost ) call TriggerRegisterAnyUnitEventBJ( gg_trg_SYS_Full, EVENT_PLAYER_UNIT_SELL_ITEM ) call TriggerAddAction( gg_trg_SYS_Full, function Trig_SYS_Full_Actions ) loop exitwhen int == 0 set udg_HAsBOught[int]=false set AllPB[int] = BPlayer.create() set int = int - 1 endloop set udg_CheckGroup = CreateGroup() call INITHOUSE(gg_unit_n009_0107 , gg_rct_HUS_2_Prop) call INITHOUSE(gg_unit_n009_0106 , gg_rct_HUS_1_Prop) //call INITHOUSE(gg_unit_n009_0013 , gg_rct_HUS_3_Prop) //call INITHOUSE(gg_unit_n009_0111 , gg_rct_HUS_4_Prop) //call INITHOUSE(gg_unit_n009_0108 , gg_rct_HUS_5_Prop) //call INITHOUSE(gg_unit_n009_0112 , gg_rct_HUS_6_Prop) endfunction |
