I've been trying to make my own version of a bank. What I've got so far is pastebinned here:
http://paste.neurohack.com/view/YUmuQ/
It basically works, except for the event that generates interest on the account. Right now, I've got the interest event tied to the ID card I'm using to track the balance, but there doesn't seem to be a way to make it a recurring event. I tried making it part of the bank station, and that worked fine until the player's ship left the system, which caused the event to stop firing. Is there a way to make a recurring event that fires regardless of which system the player is in, without making a custom playership for the task?
Lets discuss events
- alterecco
- Fleet Officer
- Posts: 1658
- Joined: Wed Jan 14, 2009 3:08 am
- Location: Previously enslaved by the Iocrym
Only by way of a choice of workarounds:
1) You make two stations, one a virtual station, that only has one event on it, namely <OnPlayerEnteredSystem>, the other your regular event station. In <OnPlayerEnteredSystem> you check if the system already has one of your event stations, and if not you place the event station and start it's recurring event
2) Add an event handler to the playership and start a recurring timer on it. The downside is that event handlers can be removed by other scripts (event stations could be as well, but that is less likely imo)
3) Add an overlay to the playership and use it's OnUpdate. Downside is that your event runs every 30 ticks, which may be too fast or too slow, depending on your mod. Also, other mods may remove it, but it is less likely
4) Add a virtual item to the playership and use it's OnUpdate. Like above, but might be preferable in some situations.
On general, all four workarounds work... I tend to use the first one the most since it gives me most flexibility, but some people dislike it for it's relative complexity. To alleviate that I have included a paste of a very simple setup
You can see in the OnCreate that a recurring event is being started. There you have control over the interval between the events. Also, remember to change the 'some-variable-change-me! variable :) Name it something relevant, like 'bankers-present
I hope you have success with the above, if not just post your issues.
1) You make two stations, one a virtual station, that only has one event on it, namely <OnPlayerEnteredSystem>, the other your regular event station. In <OnPlayerEnteredSystem> you check if the system already has one of your event stations, and if not you place the event station and start it's recurring event
2) Add an event handler to the playership and start a recurring timer on it. The downside is that event handlers can be removed by other scripts (event stations could be as well, but that is less likely imo)
3) Add an overlay to the playership and use it's OnUpdate. Downside is that your event runs every 30 ticks, which may be too fast or too slow, depending on your mod. Also, other mods may remove it, but it is less likely
4) Add a virtual item to the playership and use it's OnUpdate. Like above, but might be preferable in some situations.
On general, all four workarounds work... I tend to use the first one the most since it gives me most flexibility, but some people dislike it for it's relative complexity. To alleviate that I have included a paste of a very simple setup
Code: Select all
<StationType UNID="&stGlobalStation;"
virtual="true"
>
<Events>
<OnGlobalPlayerEnteredSystem>
(block nil
(if (not (sysGetData 'some-variable-change-me!)) (block nil
(sysCreateStation &stEventStation; (sysVectorPolarOffset nil 0 1000000))
(sysSetData 'some-variable-change-me! true)
))
)
</OnGlobalPlayerEnteredSystem>
</Events>
</StationType>
<StationType UNID="&stSystemLogStation;"
backgroundObject= "true"
timeStopImmune= "true"
unique= "inSystem"
>
<Image imageID="&rsDebris1;" imageX="0" imageY="0" imageWidth="1" imageHeight="1"/>
<Events>
<RecurringEvent>
(do something)
</RecurringEvent>
<OnCreate>
(sysAddObjRecurringTimerEvent 30 gSource "RecurringEvent")
</OnCreate>
</Events>
</StationType>
I hope you have success with the above, if not just post your issues.
The workarounds are kind of awkward, but at least it'll work. I mostly understand your example, but I do have a few questions about it.
1) I see unid=&stGlobalStation and unid=stSystemLogStation but you have sysCreateStation stEventStation, is that a typo or am I missing something?
2) Does the virtual station always exist? Is that what makes it a virtual station?
3) Is there a reason the recurring event can't be on the virtual station? And I just call it in <OnGlobalPlayerEnteredSystem>?
Sorry, but I'm still really new to XML and tscript. I'm probably going to have to have some really basic things explained to me.
1) I see unid=&stGlobalStation and unid=stSystemLogStation but you have sysCreateStation stEventStation, is that a typo or am I missing something?
2) Does the virtual station always exist? Is that what makes it a virtual station?
3) Is there a reason the recurring event can't be on the virtual station? And I just call it in <OnGlobalPlayerEnteredSystem>?
Sorry, but I'm still really new to XML and tscript. I'm probably going to have to have some really basic things explained to me.
-
- Fleet Officer
- Posts: 1533
- Joined: Tue Mar 22, 2011 8:43 pm
- Location: Alaska
- Contact:
for a global station : you have the station called with creation on an event: " global system created" global Player does handstands"JDMatson wrote:The workarounds are kind of awkward, but at least it'll work. I mostly understand your example, but I do have a few questions about it.
1) I see unid=&stGlobalStation and unid=stSystemLogStation but you have sysCreateStation stEventStation, is that a typo or am I missing something?
2) Does the virtual station always exist? Is that what makes it a virtual station?
3) Is there a reason the recurring event can't be on the virtual station? And I just call it in <OnGlobalPlayerEnteredSystem>?
Sorry, but I'm still really new to XML and tscript. I'm probably going to have to have some really basic things explained to me.
Code: Select all
<StationType UNID="&stGPetty2;"
name= "Getty2 Control Point"
virtual= "True"
>
<Events>
<OnGlobalSystemCreated> <--- when you want it to happen
(sysCreateStation &stGPetty2; nil) <--- nil = that it is based at the star on the system generation not a station in the game
</OnGlobalSystemCreated>
<OnCreate> <--- what you want it to do
at the bottom you add your closing tags after you put in your desired stuff
</OnCreate>
</Events>
</StationType>
the recurring events are called by the actual station the global one is calling into the system :
say; you have a global station calling in a salvager encounter: the encounter station would carry it's details which can include everything from recurring events to balloons.
Flying Irresponsibly In Eridani......
I don't like to kill pirates in cold blood ..I do it.. but I don't like it..
I don't like to kill pirates in cold blood ..I do it.. but I don't like it..
I apparently don't understand it as well as I thought I did. It's working great. Here's a code snippet:
The part that I don't understand is that I'm only using OnCreate, and not OnGlobalPlayerEnteredSystem. Are the stations getting recreated every time I leave a system and come back? I don't see a way for the events to be firing if that isn't the case.
Code: Select all
<!-- CIG Global Virtual Station -->
<StationType UNID="&stCIGGlobal;"
name= "CIG Global"
virtual= "True"
>
<Events>
<OnGlobalSystemCreated>
(sysCreateStation &stCIGGlobal; nil)
</OnGlobalSystemCreated>
<OnCreate>
(block nil
(if (not (sysGetData 'CIGEventStationExists))
(block nil
(sysCreateStation &stCIGEvent; (sysVectorPolarOffset nil 0 1000000))
(sysSetData 'CIGEventStationExists true)
)
)
)
</OnCreate>
<OnGlobalPlayerEnteredSystem>
</OnGlobalPlayerEnteredSystem>
</Events>
</StationType>
<!-- CIG Event Generator Station -->
<StationType UNID="&stCIGEvent;"
name= "CIG Event"
backgroundObject= "true"
timeStopImmune= "true"
unique= "inSystem"
noMapLabel= "True"
noMapIcon= "True"
>
<Image imageID="&rsDebris1;" imageX="0" imageY="0" imageWidth="1" imageHeight="1"/>
<Events>
<CIGInterest>
(block Nil
(objEnumItems gPlayerShip "*U" theItem
(if (itmHasAttribute theItem "CIGID")
(block Nil
(setq PlayersCIGID theItem)
(objRemoveItem gplayership theItem)
)
)
)
(setq CurrentCharges (itmGetCharges PlayersCIGID))
(setq InterestRate (random 0 5))
(setq Interest (Multiply CurrentCharges InterestRate))
(setq Interest (Divide Interest 100))
(setq NewCharges (add CurrentCharges Interest))
(setq PlayersCIGID (itmSetCharges PlayersCIGID NewCharges))
(objAddItem gPlayerShip PlayersCIGID)
(plyMessage gplayer (cat "CIG Interest: " Interest))
)
</CIGInterest>
<CIGAddInterestEvent>
(sysAddObjRecurringTimerEvent 300 gSource "CIGInterest")
</CIGAddInterestEvent>
<OnCreate>
(objFireEvent gSource "CIGAddInterestEvent")
</OnCreate>
<OnGlobalPlayerEnteredSystem>
<!--(objFireEvent gSource "CIGAddInterestEvent")-->
</OnGlobalPlayerEnteredSystem>
</Events>
</StationType>
-
- Militia Captain
- Posts: 779
- Joined: Wed Nov 18, 2009 1:01 am
- Location: Still looking for the csc Antarctica
- Contact:
i would recommend you use <OnGlobalTopologyCreated> so that your station would only be made once and if you used data on the playership for the amount of money they have not charges on an item it would be easier imo to modify/add interest. in my bank mod i made a global function to calculate the interest on money
and for the storage of money i use more global functions to simplify the work
see http://xelerus.de/index.php?s=mod&id=918
if you got any Q's on how I did it feel free to ask them
i am also on irc most days if you want live help, (click the image in my sig)
Code: Select all
<globals>
(setq interest (lambda (amount percent)
(block nil
(setq ints (multiply (divide amount 100) percent))
ints
)))
</globals>
and run with
(setq inst (interest crd (random 5 7 )))
where crd is the amount of money the player has invested and (random 5 7 ) is the rate
and for the storage of money i use more global functions to simplify the work
see http://xelerus.de/index.php?s=mod&id=918
if you got any Q's on how I did it feel free to ask them

i am also on irc most days if you want live help, (click the image in my sig)




"Dash_Merc - George is a genius, in that he created this game engine that is infinitely extendable"
"<@sheepluva>Good night everybody, may the source be with you." <-- FOSG dev
"You only need THREE tools in life - WD-40 to make things go, Duct Tape to make things stop And C-4 to make things go away"
Yeah, I was pretty impressed by the bank you did, but I have to confess I don't understand much of it's inner workings. That's why I'm handling things the way I am. I don't really grok the language yet. I'll look into <OnGlobalTopologyCreated>, though. That's probably what I was expecting <OnGlobalSystemCreated> to be. Also, I've never used IRC before, but I can see that the community is pretty fond of it. I'll have to check it out.
edit: <OnGlobalTopologyCreated> wasn't what I was after. But I think I was looking at things wrong. I thought that recurring events would get canceled after leaving a system. It looks like they just get paused instead. I think I'm back on track now.
edit: <OnGlobalTopologyCreated> wasn't what I was after. But I think I was looking at things wrong. I thought that recurring events would get canceled after leaving a system. It looks like they just get paused instead. I think I'm back on track now.
- alterecco
- Fleet Officer
- Posts: 1658
- Joined: Wed Jan 14, 2009 3:08 am
- Location: Previously enslaved by the Iocrym
I seem to be a bit late to the party, but i thought i might as well answerJDMatson wrote:The workarounds are kind of awkward, but at least it'll work. I mostly understand your example, but I do have a few questions about it.
1) I see unid=&stGlobalStation and unid=stSystemLogStation but you have sysCreateStation stEventStation, is that a typo or am I missing something?
2) Does the virtual station always exist? Is that what makes it a virtual station?
3) Is there a reason the recurring event can't be on the virtual station? And I just call it in <OnGlobalPlayerEnteredSystem>?
Sorry, but I'm still really new to XML and tscript. I'm probably going to have to have some really basic things explained to me.
1) Yes it is a typo... i thought i checked for all of those
2) The virtual station is never placed in game. But it's event section still triggers for OnGlobal* type events. So, you could probably place the OnGlobalPlayerEnteredSystem on the Event station, there just might be as many checks as there are stations in game (to be honest i never tested this, which is why i do it this way still)
3) Since recurring events must be placed on spaceobjects and are system local, no. The event stations is responsible for handling the event that must recurr in each individual system. It pauses when the player leaves, and resumes as soon as he enters a new system (if that system has the same event station)
Hope that helps