Scripting 101 Part 1: The bare-bone basics

Forum Archive - from http://theuniversal.net
Locked
User avatar
morbydvisns
Posts: 1889
Joined: Sun Jan 30, 2005 12:51 am

Scripting 101 Part 1: The bare-bone basics

Post by morbydvisns »

Ok, heres for an 'official refrence' or whatever for scripting for those that know nothing about it and want to learn. This post will cover the very basics of creating a functional script file and a few example scripts.

First things first, the script file:
You will find the master script file, "serverscript.mit" in the /data/scripts/ folder.

Secondly, loading the script file to your planet:
Pressing f11 will reload your script file.

There are several ways to cause a script to execute, called "triggers". Basically, when a pre-defined event set in the script file happens, the server executes a series of "*commands" (as if you, the world owner, were sitting there typing them in).

Event triggers include:

event( "&command", "command" ) - command a player would type following "&" in the world textbox to execute script

event( "newbuilding", "bdat building #" ) - executed when bldg # is built

event( "buildingdestroyed", "bdat building #" ) - when bldg # is destroyed

event( "buildingpurchase", "bdat building #" ) - executed when player purchases building #

event( "buildingtriggered", "bdat building #" ) - When bldg # is triggered... used with 'trigger' building type, executed after the trigger countdown sequence is completed.

event( "playerlogin", 0 ) - executed whenever a player lands

event( "playerdeath", 0 ) - executed when a player is killed.

event( "useitem", "Item Name" ) - executed when one of the 'usable item 1 - 32' items are used from players inventory. These items can be renamed to whatever, as long
as the item in the script file matches the new name.

***These are a basic event listing. There may be more added from time to time, as Mit finds necessary. Please Visit the Owners Manual Script Event Ref. Page for up to date listing. ***


The format of a script is important for proper function. the above examples are formatted how they would appear in the script file for proper execution, just stick your item name, command, or building number in and ur set to start your script.

along with event triggers, there are also player name references. they are as follows:
%player% - the player the script is executing for
%killer% - the player that killed %player%, used in "playerkilled" event
%buildingowner% - the owner of the building that executed the script.


the above are examples how they would need to appear in the script file. just substitute your building number or item name desired and your ready to go.

Code: Select all

event( "&command", "test" )
{
  *say This is a test.
  *grantitem %player% 100 wood 
  *grantcash %player% 500
}

event( "buildingdestroyed", "3" )
{
 *say %player% has destroyed %buildingowner%'s building.
 *grantkudos %player% 1
 *grantkudos %buildingowner% -1
}
These are 2 basic script examples to show proper use of the resources described so far. The { and } define the start and end of a script. Dont forget one of these, or you could have
your whole script file execute at once on ya, or it could cause nothing to execute. Needless to say, it can get pretty messy.

This concludes the bare-bone basics scripts infopage. As more script basics become available, i will update this post. Soon i will post another with a little more complex scripting, keep a look out.

if anyone has any questions dont hesitate to hunt me down and ask, can usually find me in Ariya, or post here.
Last edited by morbydvisns on Mon Oct 27, 2014 8:06 pm, edited 3 times in total.
User avatar
flametard
Posts: 1245
Joined: Sun Apr 01, 2007 2:05 am
Location: Join NR! faction name: 'NR new recruits' password: 'Truth'
Contact:

Post by flametard »

is that the complete list of events? and thanks.
User avatar
AniCator
Posts: 11
Joined: Tue May 08, 2007 7:08 pm
Contact:

Post by AniCator »

Just a question.
What has happened to universaldownloads.com!?!?!?

EDIT: Never mind it works again.

- AniCator
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

hmm...playerdeath...

can it recognize the killer and the killed?
are there separate variables for them?
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

%player% and %killer%
User avatar
morbydvisns
Posts: 1889
Joined: Sun Jan 30, 2005 12:51 am

Post by morbydvisns »

just to make it official: =)

event( "playerdeath", 0 )
{
*say %Player% has been killed by %killer%
}
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

anybody know if there's a way for the script to see a players vehicle?

so far, i've tried:
$gplayervehicle
$gplayerveh
$gplayercar

none work to show my vehicle.
User avatar
morbydvisns
Posts: 1889
Joined: Sun Jan 30, 2005 12:51 am

Post by morbydvisns »

nah not that ive been told of anyway.
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

Apparently there indeed wasnt one, so for 0.52.0 ive added
$gPlayerVehicle
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

nice. thank you
User avatar
morbydvisns
Posts: 1889
Joined: Sun Jan 30, 2005 12:51 am

Post by morbydvisns »

note:
player vehicle numbers are specified by 1 lower than the world vehicle

if ($gplayervehicle = 1)
would look for the player to be in vehicle 2
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

i probably oughta fix that... I'll change it for 0.53 servers if thats ok with you?
User avatar
morbydvisns
Posts: 1889
Joined: Sun Jan 30, 2005 12:51 am

Post by morbydvisns »

sure.. ive only used it once so far so not like i have alot to hunt thru and adapt XD
User avatar
Fooli
Staff
Staff
Posts: 1957
Joined: Sun Oct 05, 2003 2:38 pm
Location: Mars

Post by Fooli »

note to mit:

Code: Select all

if ($yourbrain = thinks its a good idea to number things from zero in stuff exposed to players)

{
*say Mit, stop feckin doing that, we're not all weirdass programmers :)
}
Or somethin :)f
User avatar
morbydvisns
Posts: 1889
Joined: Sun Jan 30, 2005 12:51 am

Post by morbydvisns »

lol
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

there's a bunch of things like that around.....if your looking to fix more of them :P
besides offsets, there's also differences in naming between the console and namesfile.

*building model/textures, vehicle model/textures, robocrow model/textures, SurfaceTextures, and Texmaps are all offset by 1
*on the server console, it goes Tree 1-8, but in the namesfile they are ObjectModel and ObjectTexture 0 threw 7
*Weapon Models start with 1 on the server console, but use ObjectModel and ObjectTexture starting at 8
*Wildlife starts at 1 in the *settings and on the world console, but uses MiscModel and MiscModelTexture 0-3
*the Background models on the server console start at 1, but use MiscModel and MiscModelTexture starting at 4
*sky/water/sun/water reflect use MiscTexture 0-3
*walls 1-4 use MiscTexture 4-7
*AutoTerrain Src starts at 1 in the console but starts with Autogentexture 0
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

just throwing it out there, current max events in a script is 512
Locked