PonyExpress Posted December 5, 2019 Report Posted December 5, 2019 I would like to manually create an event. How should I do this? For example, I want to create an event in which the program will work just like that if it receives a message. I think I should have 2 options: handling multiple event events or creating an event. I think both options should work something like this: var message = {}; client.on("friendMessage", (SENDER, MSG) => { // If an event or variable is not empty: // (client.on("friendMessage", (SENDER, MSG)) || (message != {}) => { if (message) { SENDER = message.msg; MSG = message.sid; message = {}; } client.chatMessage(SENDER, "OK"); }); message = {sid: { universe: 1, type: 1, instance: 1, accountid: 12345678 }, msg: "test"}; // Something like event creation: // client.on("friendMessage", SENDER: { universe: 1, type: 1, instance: 1, accountid: 23587203 }, MSG: "test"); Quote
vrtgn Posted December 5, 2019 Report Posted December 5, 2019 I'm not so sure about what you're trying to achieve or how you can handle multiple events. To send an event is called 'emitting'. So you can do: this.emit('event-name', event-params) What are you making and what are you trying to achieve? Give some more description. Learn more about events here. PonyExpress 1 Quote
PonyExpress Posted December 5, 2019 Author Report Posted December 5, 2019 Thank you, it looks like what I need. But I can’t figure out how to do it. client.emit('friendMessage', new SteamID('76561197983852931'), "help"); Quote
vrtgn Posted December 5, 2019 Report Posted December 5, 2019 4 hours ago, PonyExpress said: Thank you, it looks like what I need. But I can’t figure out how to do it. client.emit('friendMessage', new SteamID('76561197983852931'), "help"); Like I said before, what are you trying to achieve? Are you trying to simulate the friendMessage event? Quote
PonyExpress Posted December 6, 2019 Author Report Posted December 6, 2019 Yes. I'm trying to simulate the friendMessage event. I want to use it like this: client.on("friendMessage", (SENDER, MSG, FROM_NEW_OFFER, OFFER) => { // or: client.on("friendMessage", (SENDER, [MSG, FROM_NEW_OFFER, OFFER]) => { if (MSG == "help") { // to do something if (FROM_NEW_OFFER) { OFFER.to_do_something(); } } }); manager.on("newOffer", (OFFER) => { client.emit('friendMessage', OFFER.partner, "help", "FROM_NEW_OFFER", OFFER); }); I know I can do it, but I don’t want to: client.on("friendMessage", (SENDER, MSG) => { if (MSG == "help") { Help(SENDER, MSG); } }); manager.on("newOffer", (OFFER) => { Help(OFFER.partner, "help", "FROM_NEW_OFFER", OFFER); }); function Help(SENDER, MSG, FROM_NEW_OFFER, OFFER) { if (MSG == "help") { // to do something if (FROM_NEW_OFFER) { OFFER.to_do_something(); } } } Quote
Dr. McKay Posted December 6, 2019 Report Posted December 6, 2019 Spoofing a built-in event is almost never the right way to accomplish something. In this case, your second snippet is the more correct way to do this. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.