Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[Help] Making a Chat Script

So I've been crawling around the API lists for about an hour now. I'm looking for a simple script that allows me to on a triggering event put a simple message into chat. Can anyone help me find this missing piece because it would be really useful. Please note that it has to be to all players not just one.
1425559515
Ziechael
Forum Champion
Sheet Author
API Scripter
Hi Amir, sounds simple enough (says the complete amateur coder who started learning javascript officially yesterday!). What are the 'events' that you are wanting to use as the trigger as a variety of scripts out there will send to chat based on triggers but knowing what those triggers are will help narrow the field or define whether or not a bespoke script is required rather than a chopped/butchered version of an existing one ;
<a href="https://gist.github.com/anonymous/5980034" rel="nofollow">https://gist.github.com/anonymous/5980034</a> I'm using the script as listed above. I'm basically trying to use it for when the guard spots the intruders for him to simply say "Halt"
1425568724
The Aaron
Pro
API Scripter
Are you just looking for the sendChat(FromName,Message) function, or do you need help with the logic of when to call it?
I needed both. So where should I position that function to run?
1425606212
The Aaron
Pro
API Scripter
I'd try it wferever seen is being set to 1
So I think I've found the spot but now the sendChat feature is causing errors that stop the script. Can I get an example of how you'd add that function to the script cause I'm not sure where I've gone wrong here.
1425607958
The Aaron
Pro
API Scripter
sendChat('The Script!','Hi there, a message from your script.');
1425627788

Edited 1425632579
Ziechael
Forum Champion
Sheet Author
API Scripter
Had a brain wave last night, can't expand upon it till i'm at work though (spoiler, Stephen L's trap script could be easily modded to do what you want here) Watch this space: edit: now i'm at work i'll explain... Ok, here goes. Currently Stephen's script allows you to put a token on the GM layer which when walked over (please note you'll also need the TokenCollisions and Vector Math scripts!) will trigger a message to chat and/or bring the token to the map layer for the players to see. My thinking here is that if you are basing your guards vision on a set distance then you could simply place a token on the GM layer that triggers the scripts natural response: if(trap) { sendChat("Admiral Ackbar", "IT'S A TRAP!!! " + obj.get("name") + " set off a trap!"); moveTokenToTrap(obj, trap); and quick hack that to read: if(trap) { sendChat("Guard", "HALT!!! " + obj.get("name") + " was spotted by a guard!"); moveTokenToTrap(obj, trap); This is super restrictive for obvious reasons as i'm essentially proposing hard coding the name Guard and his response of Halt as well as the fact that the PC has 'been spotted by a guard' as opposed to any other action you would want to use this for. It also returns the token to the point at which the 'trap' is triggered which i find handy for those pesky players who move too far too quickly lol. Greater minds than mine, or at least more experienced coders, would no doubt be able to take this section of the script and modify it to use the GM layer tokens GM notes to provide specific output without ruining the scripts versatility re: traps etc. They could probably also make it so that the GM layer token name could be used to prefix the output... If they could it would mean that you could put a token on the GM layer, give it a name of Guard or whatever and put in the GM notes HALT!!! and with wizardry when the 'trap' was triggered (please note, by just using the web status marker nothing would be moved to the map layer either ;) ) it would give the same output 'Guard: HALT!!!' without the need to hard code it. This would work best with guards who have easily 'guarded' approaches such as narrow corridors, or stationary guards who you could set a large token on the gm layer to represent their 'sight'. For your patrolling guards it would be somewhat harder and it is way beyond me to think of a way of getting a script to recognise a tokens 'sight' in the sense of actually spotting someone while patrolling... Like i said, this is a quick hack with potential for greater flexibility. ^^^^^^^^^^^^^ All of that being said, i'm sure Aaron can develop something that could do exactly what you need but i know for a fact his list is Looooooooong!
Thank you very much for all your help.
1425756833
Ada L.
Marketplace Creator
Sheet Author
API Scripter
I'm not so sure the It's A Trap script would be the best thing to use for this since it is designed for stationary traps and similar effects, but you could definitely do you what you want to do using the library provided by the Token Collisions script (which the It's A Trap script uses). Whenever the guard's "sight" object moves, use the Token Collisions library to check if it collides with any of the player character tokens during its movement. If it does, Make the guard stop patrolling and say "HALT!" in the chat. Same thing if a player moves and collides with the guard's "sight" object during their movement.