Jump to content
  • 0

Map Rental NPC without reset after server reboot data base


BTNX

Question


  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  55
  • Reputation:   3
  • Joined:  04/02/12
  • Last Seen:  

Situation:

I'm trying to implement a Guild Base rental system where guild members can rent a map for 31 days....

The problem is, we have server maintenance every week.

 

Concept:

Once a guild member rents a map, he/she and the rest of his guild mates will have access to the map... If the member leaves the guild, he/she will no longer be able to access the map.  After the 31 days expire, all members of the guild will no longer have access to the map until they renew their rent.

 

Is there a way to do this without creating a new database just to store information?

 

Possible solutions that I already thought of:

-Hard code the script on the NPC and map

-I need the rental process to be automated, almost like the guild castles... Only without the use of databse.

 

-Use rental items.

-The map/NPC  cant distinguish between guilds by using rental items.

 

-Global permanent variable or any type of variable.

-I'm trying to use this right now... It's melting my brain T_T

Edited by Entrophy
Link to comment
Share on other sites

9 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  55
  • Reputation:   3
  • Joined:  04/02/12
  • Last Seen:  

Can anyone at least explain how gettimetick(2) works? The wiki page doesn't explain much, I have a feeling that I can use this for this project.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

I would suggest using a separate database; they're not that difficult to create, consume less resources, and are guaranteed to be persistent to server shutdowns.

Concept:

  • Create a database with columns for guild, time, and (if applicable) map name.
  • Have an NPC (or function) query the database to check if the user's guild is the owner prior to warping.  I'd include code to delete expired entries here, as well.
  • If there is no owner, ask if the player wants to rent; if yes, and all conditions are met (cost, re-check ownership, etc.), insert an entry into the database (guild, current time + 1 month, map).
  • (optional) Use an OnPCLoadMapEvent trigger to remove unwanted players from the map.

'gettimetick(2)' retrieves the system time in UNIX epoch time (in seconds).  Not really applicable for this unless you want to use UNIX time instead of a DATETIME data type.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  55
  • Reputation:   3
  • Joined:  04/02/12
  • Last Seen:  

^thanks for the reply. I've been using mapreg since I don't really need a lot of space for the data and mapreg is readily available.

As for gettimetick, that's the only way I can add days safy/easily

I was thinking of :

set $map_rent_expire$, gettimetick(2) + (number of days);

Then check expiration by using:

if ($rentexpire$ < gettimetick(2))

set $renter_guild_name$, "";

goto map_not_available:

but I'm not sure if that's the proper way of using that command.

Anyway, is there any other command that I can use to pull current date record expiration date

and add days to current day.

My older version was messy: I used gettime(7/6/5) to get year month and day then add the necessary days manually...

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

Oh, if you're only using a single map then mapreg will suffice.  (We like to avoid mapreg when using lots of variables because all permanent global variables auto-save in regular intervals.)

 

You're using the variable correctly - just note that gettimetick(2) is in seconds, not days, and that you shouldn't be storing it as a string.

A sample:

	if (gettimetick(2) < $rentexpire) {
		mes (($renter_guild)?getguildname($renter_guild):"No guild")+" currently owns the map.";
		if ($renter_guild && getcharid(2) == $renter_guild) {
			mes "Would you like to warp there?";
			next;
			if(select("Yes!:No.") == 1)
				warp "map",x,y;
			close;
		}
		close;
	} else {
		mes "Ownership by the "+getguildname($renter_guild)+" has expired.";
		if (!getcharid(2)) {
			mes "You must be part of a guild to rent this map.";
			close;
		}
		mes "Do you want to rent this map?";
		next;
		if(select("Yes!:No") == 2) {
			mes "See you later.";
			close;
		}
		//your requirements
		if (gettimetick(2) < $rentexpire) {
			mes "Sorry, but another guild has rented this map.";
			close;
		}
		set $renter_guild, getcharid(2);
		set $rentexpire, gettimetick(2) + 2678400;
		mes "Map rented successfully to the "+getguildname($renter_guild)+" guild for 31 days.";
		mes "Enjoy!";
		close;
	}
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  55
  • Reputation:   3
  • Joined:  04/02/12
  • Last Seen:  

Well, actually 20 maps.  

So, I'd be using it for:

 

1)Guild owner of map

2)Rental expiration of said map

x20

 

So that would be 40 lines in mapreg which will also be auto-deleted once the rent expire.

 

 

 

(We like to avoid mapreg when using lots of variables because all permanent global variables auto-save in regular intervals.)

I don't understand this part.
 

you shouldn't be storing it as a string.


What's wrong if I store it as a string? it a big deal?  The reason I'm doing that is because I'm also going to add the option to buy the map... Making it permanent... Then I'd use:

set $map_rent_expire$, "permanent"; 

 

and I wanted to put all related variables in one database.  

 

Is that going to be a problem?

 

Also, another thing... I cant figure out how to use OnPCLoadMapEvent

 

I've been using OnTouch on player's savepoint.  I'm also planning to use it to check for expired rent:

 

OnTouch:

if ($rentexpire$ < gettimetick(2)) {
set $renter_guild_name$, "";
  savepoint "prontera",156,133;
  warp "prontera",156,133;
}
  end;
Edited by Entrophy
Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  55
  • Reputation:   3
  • Joined:  04/02/12
  • Last Seen:  

^ Nice

 

That looks really complex and intimidating... Let me decipher that scrip and figure out if that's what I need... Thx 

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

I don't understand this part.

Every variable in `mapreg` is directly available, as you've noticed. They server gets them from the database when it boots, stores them in RAM, and periodically queries them all back into the database (or else you'd lose all your data on a reboot). Having a large number of variables (e.g. thousands) may cause your server to lag. You can read more here: http://www.eathena.ws/board/index.php?s=9d7dbd4ba43d6eed7e2903043c4a97b7&showtopic=181741&view=findpost&p=1478950

What's wrong if I store it as a string? it a big deal? The reason I'm doing that is because I'm also going to add the option to buy the map... Making it permanent...

It's fine to store strings as strings, but you were storing integers as strings. That'll either give you errors or be a waste of processing (as the server will try to convert it to an integer anyway).

Also, another thing... I cant figure out how to use OnPCLoadMapEvent

Read about it in trunk/doc/script_commands.txt. You need to set the mapflag "mf_loadevent" on the map in order for the label to trigger.
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  55
  • Reputation:   3
  • Joined:  04/02/12
  • Last Seen:  

@Euphy

 

OK, I see,  I'm only adding 40 to mapreg so I shouldn't notice the difference, right?

Every time a new guild rents a base, the variable just gets over written.

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...