How to use attachrid to activate npc OnTime events

Content and general development discussion, including quest scripts and server code. TMW Classic is a project comprising the Legacy tmwAthena server & the designated improved engine server based on evolHercules.


Forum rules

This forum houses many years of development, tracing back to some of the earliest posts that exist on the board.

Its current use is for the continued development of the server and game it has always served: TMW Classic.

Post Reply
nmaligec
Warrior
Warrior
Posts: 253
Joined: 08 Apr 2010, 01:55

How to use attachrid to activate npc OnTime events

Post by nmaligec »

Just wondering how to set an appropriate character id to the npc invoking OnTime events. As stated in a scripting manual:
attachrid(<account ID>)

Quite a bit of commands want a RID to work, since they wouldn't know where to send information otherwise. And in quite a few cases the script gets invoked with a RID of zero (like through OnTime special labels). If an NPC script needs this, it can attach a specified character's id to itself. by calling the 'attachrid' function.
1. Which character ID should I use???
2. How long is it attached for?
3. How to be sure the player doesn't log out and set RID back to 0?
4. Where/how do I attach it in the npc script so that it lets the OnTime labels function without player interaction?

I just want the timer events to activate area effects like mapwarp or announce.
User avatar
Freeyorp101
Archivist Prime
Archivist Prime
Posts: 766
Joined: 04 Nov 2008, 09:17
Location: New Zealand

Re: How to use attachrid to activate npc OnTime events

Post by Freeyorp101 »

nmaligec wrote:1. Which character ID should I use???
2. How long is it attached for?
3. How to be sure the player doesn't log out and set RID back to 0?
4. Where/how do I attach it in the npc script so that it lets the OnTime labels function without player interaction?
1. Use the value returned by getcharid
2. Until detachrid is called or until the end of current script execution, whichever comes first
3. Use the attachrid return value to handle error cases
4. Insufficient information, please elaborate
nmaligec wrote:I just want the timer events to activate area effects like mapwarp or announce.
The former does not require an rid attached, the latter does if and only if 0x0f is set with the flag (which you probably aren't, judging by your needs) - but you can also use the areaannounce and mapannounce functions, which never do. If you don't see a script_rid2sid call in the relevant function in script.c, it doesn't need an attached rid.


---Freeyorp
(09:58:17) < tux9th> Freeyorp: your sig on the forums is kind of outdated
nmaligec
Warrior
Warrior
Posts: 253
Joined: 08 Apr 2010, 01:55

Re: How to use attachrid to activate npc OnTime events

Post by nmaligec »

About part 4, I didn't understand how On Event labels were being called. I had some script errors which prevented the mapwarp from working, so I thought the OnTimer event was not being executed. I found the errors, and now its working correctly.

Answers to 1-3 helped a lot, though now I realize I don't have a case where I need to use attachrid.

If anyone can help with the following:

I need a way to get pc coordinates. I tried the getmapxy command but found that it wasn't implemented in tA.

Q1: Is there currently any script command that will return x and y coordinates of a player?

Q2: Where should I look in the source to find the predefined OnxxxxEvent labels? I did a file search and nothing came up.

Q3: Also are the OnPCLoginEvent and LogoutEvent implemented?

I tried to use them but nothing got triggered. All I had was a npctalk message and end command under each label to see if it was triggered. Maybe I am using them incorrectly?? I just want to be able to warp players to a quest starting point when they log out.

Q4: What is the best way to handle a player who logs out of a quest map that relies on globally timed events for progression? If they log back in when the timer has ended, the quest will potentially be glitched.
User avatar
Freeyorp101
Archivist Prime
Archivist Prime
Posts: 766
Joined: 04 Nov 2008, 09:17
Location: New Zealand

Re: How to use attachrid to activate npc OnTime events

Post by Freeyorp101 »

nmaligec wrote:Q1: Is there currently any script command that will return x and y coordinates of a player?
No, but depending on your needs you can use isin/isat if you want to check within/at specific bounds, or use area triggered npcs.

nmaligec wrote:Q2: Where should I look in the source to find the predefined OnxxxxEvent labels? I did a file search and nothing came up.
There is no central place for these. For instance, OnPCKilledEvent and OnPCKillEvent are in pc.c, OnCharIfInit and OnInterIfInit are in chrif.c, OnAgitInit is in guild.c, OnInit is in npc.c (OnTimer* is also handled here, but in a rather different way)

nmaligec wrote:Q3: Also are the OnPCLoginEvent and LogoutEvent implemented?
No, neither are.

nmaligec wrote:Q4: What is the best way to handle a player who logs out of a quest map that relies on globally timed events for progression? If they log back in when the timer has ended, the quest will potentially be glitched.
You'll need to be more specific, but you'll probably want to add the nosave flag to the map such that the player cannot return to the map after logging out (for instance, Candor)


---Freeyorp
(09:58:17) < tux9th> Freeyorp: your sig on the forums is kind of outdated
nmaligec
Warrior
Warrior
Posts: 253
Joined: 08 Apr 2010, 01:55

Re: How to use attachrid to activate npc OnTime events

Post by nmaligec »

Freeyorp: Thank you so much! The nosave mapflag is exactly what I need. I tested it out and although the first time I logged in I was still saved in the map, when I re-logged I was sent to the starting loc I set on the flag.

This was soooo much easier than the way I thought of doing it with the OnEvents. Thanks again, you are a sanity saver!

On a side note, I saw that there is a cap of 96 permanent character variables. Are there any other variable caps/limitations that I should be careful of?

Are the scope variables designated with .@ implemented? If they are how long are they stored in memory after the end of the scope? Are they immediately garbage cleaned, or do they take up memory until the servers are restarted?

I would like to use a variable that is only used within its scope an no where else, such as to store intermediate calculations. What is the most efficient variable type to use? Or do people not care? Most scripts that I saw used temporary character variables for everything.
User avatar
Freeyorp101
Archivist Prime
Archivist Prime
Posts: 766
Joined: 04 Nov 2008, 09:17
Location: New Zealand

Re: How to use attachrid to activate npc OnTime events

Post by Freeyorp101 »

Without knowing the details of what you are doing, I cannot say what other limitations are relevant.

.@, or anything involving ., are not available. $@ are most efficient, but generally @ variables are used when an rid is attached, and $@ otherwise.


---Freeyorp
(09:58:17) < tux9th> Freeyorp: your sig on the forums is kind of outdated
nmaligec
Warrior
Warrior
Posts: 253
Joined: 08 Apr 2010, 01:55

Re: How to use attachrid to activate npc OnTime events

Post by nmaligec »

Freeyorp101 wrote: generally @ variables are used when an rid is attached, and $@ otherwise.
---Freeyorp
I'll stick with that as a guideline, and only use a permanent character variable to store a bunch of quest finished bit flags. I don't think I will ever need to set a global permanent.
Post Reply