[Lua] House buying menu

User Tag List

Results 1 to 7 of 7
  1. #1
    P1raten's Avatar Banned
    Reputation
    500
    Join Date
    Mar 2008
    Posts
    1,323
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Lua] House buying

    Introduction:
    Here's a little script i made which allows the players to buy your desired gameobject. In my case i used a tent.

    Features:
    Players may only create 1 tent.
    Players are able to remove the tent.
    If players have removed the tent they are able to create it again.
    Players can make the tent bigger and smaller.

    Instructions:
    Put this code in a lua file and then place it in your scripts folder.
    Replace TENTID with your desired gameobject.
    Replace ITEMID with your desired item.

    The code:
    Code:
    local Tent = TENTID
    local x, y, z, o
    local tentSpawned = false
    local sizePlusOne = false
    local sizeMinusOne = false
    
    function Item_OnClick(Item, Event, player)
    	Item:GossipCreateMenu(100, player, 0)
    	Item:GossipMenuAddItem(0, "Spawn Tent", 1, 0)
    	Item:GossipMenuAddItem(0, "Remove tent", 2, 0)
    	Item:GossipMenuAdditem(0, "Make Tent Bigger", 3, 0)
    	Item:GossipMenuAdditem(0, "Make Tent Smaller", 4, 0)
    	Item:GossipMenuAddItem(0, "Nevermind", 5, 0)
    	Item:GossipSendMenu(player)
    end
    
    function OnSubMenu(Item, Event, player, id, intid, code)
    	local GetClosestTent = pUnit:GetGameObjectNearestCoords(x, y, z, Tent) --Making a variable for removing the tent.
    	x = player:GetX() --Getting the players X position.
    	y = player:GetY() --Getting the players Y position.
    	z = player:GetZ() --Getting the players Z position.
    	o = player:GetO() --Getting the players Orientation.
    	if (intid == 1) then
    		if (tentSpawned == false) then --Preventing players from spawning more than 1 tent.
    		player:SpawnGameObject(Tent, x, y, z, o, 0) --Spawn the tent
    		else
    		Item:GossipSendMenu(player)
    	end
    	
    	if (intid == 2) then
    			if GetClosestTent ~= nil then --If the tent is not nil.
    			GetClosestTent:Despawn(1,0) --Despawn
    			tentSpawned = false --Allowing players to spawn a tent again, since the other one is removed.
    			Item:GossipSendMenu(player)
    			end
    	end
    	
    	if (intid == 3) then
    		if (sizeMinusOne == true) then
    			local scale = GetClosestTent:GetScale()
    			GetClosestTent:SetScale(scale+1)
    			sizePlusOne = true
    		else
    		end
    	end
    	
    	if (intid == 4) then
    		if (sizePlusOne == true) then
    			local scale = GetClosestTent:GetScale()
    			GetClosestTent:SetScale(scale-1)
    			sizeMinusOne = true
    		else
    		end
    	end
    
    	if (intid == 5) then
    		Item:GossipSendMenu(player)
    	end
    	end
    end
    
    RegisterItemGossipEvent(ITEMID, 1, "Item_OnClick")
    RegisterItemGossipEvent(ITEMID, 2, "OnSubMenu")
    Last edited by P1raten; 05-13-2010 at 07:24 PM.

    [Lua] House buying
  2. #2
    dasde's Avatar Active Member
    Reputation
    48
    Join Date
    Nov 2007
    Posts
    176
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that is pretty neat

  3. #3
    P1raten's Avatar Banned
    Reputation
    500
    Join Date
    Mar 2008
    Posts
    1,323
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Updated.

    -Your now able to make the tent bigger and smaller.
    -If you've made the tent bigger one time then you cant make it bigger again unless you make it smaller and vice versa.

  4. #4
    Kitsuji's Avatar Active Member
    Reputation
    70
    Join Date
    Aug 2009
    Posts
    276
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Man p1raten, your a beast...

    EDIT:
    +rep

  5. #5
    stoneharry's Avatar Moderator Harry


    Reputation
    1618
    Join Date
    Sep 2007
    Posts
    4,564
    Thanks G/R
    151/150
    Trade Feedback
    0 (0%)
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Instead of defining 4 separate variables, just keep it as 1 variable:

    local x, y, z, o = pUnit:GetX(), pUnit:GetY(), pUnit:GetZ(), pUnit:GetO()

  6. #6
    Dynashock's Avatar Contributor

    Reputation
    176
    Join Date
    Nov 2007
    Posts
    203
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1. Players can still spawn as many tents as they want. Add 'tentSpawned = true' to option 1, to prevent this.
    2. Even if above would work, then only one player could spawn a tent and remove it, considering the variables you're using are the same for every player. Use a table to store the boolean value and use the player's guid or object 'tostring(player)' as a key to access the boolean value.
    3. ^ same goes for the scaling.
    4. Upon starting the script, the scaling options will never work, as it requires a certain boolean value to be true, which simply can't be true in the current context (as they're declared false at the start of the script).
    5. Scaling is unlimited. You never assign false to the boolean values 'sizePlusOne' and 'sizeMinusOne'.
    6. No need for an else statement if there is nothing next to it. (else end, just end suffices)
    7. Option 5 should be player:GossipComplete() instead.
    8. I suggest putting a player:GossipComplete() to every option OR a return to the main menu OR a player:GossipComplete() at the end of the script so it always ends after it's run its course. This is because when you spawn a tent now, the menu will remain, yet unclickable.
    9. Your 'if (intid == 1) then' scope spans over the entire function. You're missing an end at line 29 and have an end too much at line 59.
    10.
    Code:
    local GetClosestTent = pUnit:GetGameObjectNearestCoords(x, y, z, Tent) --Making a variable for removing the tent.
    Above doesn't work, pUnit does not exist in the given context.

    I think that's about all. The idea is interesting but I've seen it done before with a tent, although without the scaling. I'd like to see a more advanced approach to this, i.e. being able to spawn multiple tents, maybe a campfire included and so on. However, fix up the given issues first before you attempt it.

    Keep it up.
    Ignorance is bliss.

  7. #7
    P1raten's Avatar Banned
    Reputation
    500
    Join Date
    Mar 2008
    Posts
    1,323
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Dynashock View Post
    1. Players can still spawn as many tents as they want. Add 'tentSpawned = true' to option 1, to prevent this.
    2. Even if above would work, then only one player could spawn a tent and remove it, considering the variables you're using are the same for every player. Use a table to store the boolean value and use the player's guid or object 'tostring(player)' as a key to access the boolean value.
    3. ^ same goes for the scaling.
    4. Upon starting the script, the scaling options will never work, as it requires a certain boolean value to be true, which simply can't be true in the current context (as they're declared false at the start of the script).
    5. Scaling is unlimited. You never assign false to the boolean values 'sizePlusOne' and 'sizeMinusOne'.
    6. No need for an else statement if there is nothing next to it. (else end, just end suffices)
    7. Option 5 should be player:GossipComplete() instead.
    8. I suggest putting a player:GossipComplete() to every option OR a return to the main menu OR a player:GossipComplete() at the end of the script so it always ends after it's run its course. This is because when you spawn a tent now, the menu will remain, yet unclickable.
    9. Your 'if (intid == 1) then' scope spans over the entire function. You're missing an end at line 29 and have an end too much at line 59.
    10.
    Code:
    local GetClosestTent = pUnit:GetGameObjectNearestCoords(x, y, z, Tent) --Making a variable for removing the tent.
    Above doesn't work, pUnit does not exist in the given context.

    I think that's about all. The idea is interesting but I've seen it done before with a tent, although without the scaling. I'd like to see a more advanced approach to this, i.e. being able to spawn multiple tents, maybe a campfire included and so on. However, fix up the given issues first before you attempt it.

    Keep it up.
    Thank you, ill keep this in mind.

Similar Threads

  1. What players like to buy in the auction house?
    By PleaseHelpMe in forum Diablo 3 General
    Replies: 4
    Last Post: 09-17-2012, 08:00 AM
  2. [Release] Lua housing
    By Confucius in forum WoW EMU General Releases
    Replies: 0
    Last Post: 07-27-2009, 03:45 PM
  3. Lua Housing System help
    By Confucius in forum WoW EMU Questions & Requests
    Replies: 18
    Last Post: 07-24-2009, 07:47 AM
  4. Replies: 0
    Last Post: 12-23-2008, 07:30 AM
  5. How to buy/rent a house in Stormwind
    By Obama in forum Screenshot & Video Showoff
    Replies: 46
    Last Post: 10-11-2007, 02:06 PM
All times are GMT -5. The time now is 06:33 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search