Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Database NPCs (https://forums.graalonline.com/forums/showthread.php?t=64991)

MegaMasterX90875 03-27-2006 05:11 PM

Database NPCs
 
I'm trying to construct an apartment complex, but I need to have a way to save owners account names, wether or not the room is locked, and rent/ownership. In other words:
1) Owner's Account Name
2) Is room Locked (Yes/No)
3) Is room owned/rented

there are about 18 rooms in the apartment.
If anyone can help me, I'd really appreciate it.

Yen 03-27-2006 09:45 PM

First, you'll want to initialize the rooms.
You could either use an array, such as this.rooms, or you could use a list of strings such as this.room1, this.room2, this.room3

Personally, I'd use a list of arrays.
this.room1 = {owneraccount,islocked,isowned};
this.room2 = {owneraccount,islocked,isowned};

For example.. this.room14 = {"Yen",0,0};
The owner is me, Yen.
The room is unlocked.
I don't own the room.
I could then access each piece of data with this.room14[#]
this.room14[0] is the owner, this.room14[1] is whether it's locked, this.room14[2] is whether it's owned or not.

You'll be using makevar() a lot.
i.e. makevar("this.room" @ room)[0]

napo_p2p 03-28-2006 12:44 AM

Quote:

Originally Posted by Yen
You'll be using makevar() a lot.
i.e. makevar("this.room" @ room)[0]

I pretty much agree with everything Yen is saying, but I don't like to use makevar too much.

This should work fine: this.("room" @ room)

Projectshifter 03-28-2006 02:39 AM

Quote:

Originally Posted by napo_p2p
I pretty much agree with everything Yen is saying, but I don't like to use makevar too much.

You should learn to ;) I <3 makevar. Dynamic variable names are a pain in a lot of languages, especially when you're dealing with dynamic multi-level arrays :O

I commented earlier but my computer crashed (hence why I stopped using windows years ago, it was a mistake to boot it!), if you have attempted this and come out with some problems we'd be glad to help out, but if you're just looking for someone to do it for you then you're in the wrong forum.

napo_p2p 03-28-2006 07:11 AM

Quote:

Originally Posted by Projectshifter
You should learn to ;) I <3 makevar.

I know how, but I just don't like to.

I just like: this.room(@ room) better. I don't think it really matters. I guess it's just a preference thing.

MegaMasterX90875 03-28-2006 03:43 PM

I was told NOT to use serverside flags for the 3 things I need. I think I know why, I'd hate opening RC and seeing like 300 flags. Is the information saved using the script saved serverside? Can it be called and seen by other players?

Projectshifter 03-28-2006 08:14 PM

Quote:

Originally Posted by MegaMasterX90875
I was told NOT to use serverside flags for the 3 things I need. I think I know why, I'd hate opening RC and seeing like 300 flags. Is the information saved using the script saved serverside? Can it be called and seen by other players?

Using serverside flags as opposed to clientside flags? There is nothing wrong with assigning it an id number and then storing the data in a database NPC if you so choose, but even if you store it just as local strings on that NPC it needs to be serverside. I'm curious, who told you to store it serverside was bad?

napo_p2p 03-28-2006 08:52 PM

Quote:

Originally Posted by Projectshifter
Using serverside flags as opposed to clientside flags? There is nothing wrong with assigning it an id number and then storing the data in a database NPC if you so choose, but even if you store it just as local strings on that NPC it needs to be serverside. I'm curious, who told you to store it serverside was bad?

I think he means using server. and serverr. flags. I try to avoid using those if a database will work.

Projectshifter 03-28-2006 09:39 PM

Quote:

Originally Posted by napo_p2p
I think he means using server. and serverr. flags. I try to avoid using those if a database will work.

So basically you never use them? lol

napo_p2p 03-29-2006 01:25 AM

Quote:

Originally Posted by Projectshifter
So basically you never use them? lol

Basically :P. Sometimes, though, there is the need for a serverr. flag.

Projectshifter 03-29-2006 01:29 AM

Quote:

Originally Posted by napo_p2p
Basically :P. Sometimes, though, there is the need for a serverr. flag.

Lies, all lies. I <3 my database NPCs, you'll never take them away, you'll never be able to replace them.

napo_p2p 03-29-2006 03:48 AM

Quote:

Originally Posted by Projectshifter
I <3 my database NPCs, you'll never take them away, you'll never be able to replace them.

The Force is strong in this one.

MegaMasterX90875 04-04-2006 02:55 PM

Eh, serverr. flags have their uses.... but still I'm trying to migrate to GS2, but it's not going very good,..... So, I'll keep GS1 until I earn some skills in GS2.

jake13jake 04-06-2006 01:51 AM

Well I would suggest creating a variably named variable that contains an array of information.

this.(@complexName@roomName) = {bool locked?,owner,tenant,rent,rentCollected)

you may want the following public functions:
addRoom(complexName,roomName)
deleteRoom(complexName,roomName)

toggleLock(complexName,roomName)
setOwner(complexName,roomName)
setTenant(complexName,roomName)
setRent(complexName,roomName)

isLocked(complexName,roomName)
getOwner(complexName,roomName)
getTenant(complexName,roomName)
getRent(complexName,roomName)

collectRent(complexName,roomName)
payRent(complexName,roomName)

ApothiX 04-06-2006 02:25 PM

Why are you guys all using dynamic-named variables as opposed to a 3-Dimensional array?

this.apartments[this.apartments.size()].add({owner, locked, other crap, ...});

is how I would do it, then you access it like: this.apartments[apartmentid][0]; to get the owner.

napo_p2p 04-06-2006 11:24 PM

Quote:

Originally Posted by ApothiX
Why are you guys all using dynamic-named variables as opposed to a 3-Dimensional array?

I tend to stay away from 3D arrays because they tend to get really long, and updating them via RC can cut them off.

At least for now, anyways.

jake13jake 04-07-2006 01:44 AM

Quote:

Originally Posted by ApothiX
Why are you guys all using dynamic-named variables as opposed to a 3-Dimensional array?

this.apartments[this.apartments.size()].add({owner, locked, other crap, ...});

is how I would do it, then you access it like: this.apartments[apartmentid][0]; to get the owner.


Quote:

Originally Posted by napo_p2p
I tend to stay away from 3D arrays because they tend to get really long, and updating them via RC can cut them off.

At least for now, anyways.

Problems with 3-dimensional arrays:
1. the standard object functions don't update the string value outputs for mult-dimensional arrays (unless Stefan's fixed that since February).
2. what nappy said.

I mean, because of #1, I used 2 pairs of parallel arrays for my rank system on Classic. However, with 3000+ accounts a month entering the server, it lags the hell out of me when I open the script's flags. I get around this by simply downloading the text file from the NPC folder.

The thing that you have to be careful the most about when you use dynamic variable names is that they don't have spaces in them. You could probably get around this (for programming ease of use) by replacing the spaces with underscores or simply trimming the strings that make up the dynamic variable.

Projectshifter 04-07-2006 03:15 AM

Quote:

Originally Posted by ApothiX
Why are you guys all using dynamic-named variables as opposed to a 3-Dimensional array?

Multi-level arrays, but it really doesn't make a difference if you'ure using multilevel arrays or using dynamically named arrays. The problem is that they can get confusing if you try and manually edit them and they are complicated. It's more a matter of personal preference though. At least in GScript you can kind of see them, in any other language they're all but impossible to manually read without running loops or complicated checks to print them out :(


All times are GMT +2. The time now is 06:02 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.