lua:scriptenvironments
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
lua:scriptenvironments [2015/10/17 05:46] – [Simple Interactions] aethyn | lua:scriptenvironments [2016/02/08 04:45] (current) – [Script Environments] vodur | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Script Environments ====== | ====== Script Environments ====== | ||
- | With the exception of the [[: | + | All prog scripts run in the scripting |
+ | |||
+ | There are a few ways to share values between different script | ||
===== Simple interactions ===== | ===== Simple interactions ===== | ||
Line 11: | Line 13: | ||
<code lua> | <code lua> | ||
-- GRALL. Let's say HI! to PCs | -- GRALL. Let's say HI! to PCs | ||
- | if ch.ispc then – ispc is also a property of CH | + | if ch.ispc then -- ispc is also a property of CH |
say(" | say(" | ||
end | end | ||
Line 57: | Line 59: | ||
In this case OBJs have a property " | In this case OBJs have a property " | ||
+ | |||
+ | ===== Finding the correct environment ===== | ||
+ | |||
+ | There are many [[: | ||
+ | |||
+ | ==== getmobworld() and getobjworld() ==== | ||
+ | |||
+ | These two functions work the same way. Only getmobworld() is shown, but the examples can be made to fit getobjworld(), | ||
+ | |||
+ | <code lua> | ||
+ | -- Let's find a mob with vnum 22000 and make him " | ||
+ | getmobworld(22000)[1]: | ||
+ | </ | ||
+ | |||
+ | Since we know there' | ||
+ | |||
+ | <code lua> | ||
+ | -- Make mob 22000 in room 22050 " | ||
+ | for _,mobile in ipairs(getmobworld(22000)) do | ||
+ | if mobile.room.vnum == 22050 then | ||
+ | mobile: | ||
+ | end | ||
+ | end | ||
+ | </ | ||
+ | |||
+ | In this example we've looped over the getmobworld() list for that vnum, but also "broke out" in a more conventional way. A mob has a ROOM property, which has a vnum property. In that way we can find out which room a mobile is in and make them sleep if they' | ||
+ | |||
+ | ==== getpc() and getroom() ==== | ||
+ | |||
+ | getpc() takes a string argument. It, like getroom(), can return only one object because PC names are unique. | ||
+ | |||
+ | <code lua> | ||
+ | -- TIMER. Every 5 minutes let's give Vodur a hug. He deserves it. | ||
+ | if getpc(" | ||
+ | mob: | ||
+ | mob: | ||
+ | end | ||
+ | </ | ||
+ | |||
+ | This contrived example is obviously not very useful. In the Cards Against Humanity script we can see how to use getpc() in a more constructive way: | ||
+ | |||
+ | <code lua> | ||
+ | function check_player_num() | ||
+ | for _,v in ipairs(players) do | ||
+ | if not(getpc(v.name)) then | ||
+ | missing_players = {} | ||
+ | table.insert(missing_players, | ||
+ | active_players = #players - # | ||
+ | end | ||
+ | end | ||
+ | if active_players> | ||
+ | start_hand() | ||
+ | else | ||
+ | for _,j in ipairs(players) do | ||
+ | tell(j.name, | ||
+ | tell(j.name, | ||
+ | delay(30, final_check) | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | </ | ||
+ | |||
+ | In the function the " | ||
+ | |||
+ | getroom() is even more straightforward. Since ROOMs of a certain vnum always exist, using getroom() will always allow you to access that ROOMs properties and methods. For instance, we can turn a " | ||
+ | |||
+ | <code lua> | ||
+ | -- DEATH. Make the exit up from 22000 visible. | ||
+ | getroom(22000).up: | ||
+ | </ | ||
+ | |||
+ | Again, there' | ||
lua/scriptenvironments.1445060812.txt.gz · Last modified: 2015/10/17 05:46 by aethyn