Game Development Community

Database system thingy

by Nathan Cox · in General Discussion · 06/04/2008 (10:22 am) · 4 replies

I want to make a housing system ingame that works like this:

You buy a house and you set a password for it. The house is then randomly place in the sky (so far above the terrain that no player can see it) and that is their house. When they wish to enter their house a command shall be set: enterHouse(%houseNum, %password); With me so far? I want it so that the player teleports to where their house is if the password matches. How would i go about doing this?

#1
06/07/2008 (3:34 am)
Any ideas?
#2
06/07/2008 (8:09 am)
First, you'll need some sort of placement code. Create a function that makes a new interior shape, possibly at request of the client, and puts it in a random position far over the ground. Next, take the ID of your interior shape and store it.

$House::Password[%houseNum] = %password;

Assuming %obj is the Id, and the password is in the "create" function.

You also might want to make a list of spawnpoint offsets for all of the available houses. It would take the type of interior and compare it to a string. It would get the offset from the root of the interior and place a spawn point, so the player doesn't spawn in a wall or something. Could look like this:

$House::Spawnpoint[house2] = "0 2 0.5";

So you create a spawn point at the interior's position, but do a VectorAdd of the spawnpoint offset. It would also be a good idea to store the id of the spawnpoint as well.

$House::SpawnId[%houseNum] = %spawn;

Your enterHouse function might look something like this:

function enterHouse(%client,%houseNum,%password)
{
  if(%password == $House::Password[%houseNum])
 {
   %client.player.setTransform($House::SpawnId[%houseNum].getTransform);
 }
}

That should be enough to get you started.
#3
06/11/2008 (8:57 am)
How do i store the ID of objects and stuff? How do i spawn an interior?
#4
06/13/2008 (11:44 am)
Ok, here is the script so far, can anyone spot anything wrong with it?

//Housing system prototype

$CharDetail::Gold = %client.Gold;

package newHouse
{
	new interiorInstance(%houseNum)
	{
		shapeFile = "base/data/interiors/vectrexis/houseA.dts";
		position = $Pref::Server::HousePosition[%houseNum];
	}
}

function enterHouse(%client, %houseNum, %password)
{
	if(%password = $Pref::Server::HousePassword[%houseNum])
	{
		%client.setTransform($Pref::Server::HousePosition[%houseNum]);
		onChatMessage("\c2You entered the "@$Pref::Server::HouseName[%houseNum]@" house successfully!!");
	} else {
		onChatMessage("\c3Wrong password!!");
	}
}

function buyHouse(%name, %pass, %houseNum)
{
	if(%client.Gold < 10000)
	{
		onChatMessage("Not enough Money!");
	} else {
		if($CharDetail::OwnHouse = 0)
		{
			%client.Gold -= 10000;
			$Pref::Server::HouseName[%houseNum] = %name;
			$Pref::Server::HousePassword[%houseNum] = %pass;
			$CharDetail::OwnHouse = 1;
			newHousePos();
			activatePackage(newHouse);
		} else {
			onChatMessage("You already own a house!");
		}
	}
}

function newHousePos()
{
	%number = $Pref::Server::NumHouse;
	%lastPos = $Pref::Server::HousePosition[%number];
	%lastX = (getWord(%lastPos,0));
	%lastY = (getWord(%lastPos,1));
	%lastZ = (getWord(%lastPos,2));
	%finalZ = (%lastZ += 25);
	%finalPos = ""@%lastX@" "@%lastY@" "@finalZ@"";
	$Pref::Server::HousePosition[%number] = %finalPos;
}

I'm currently working on a way to store the house's position.