Noobish questions, mostly about scripting

Forum Archive - from http://theuniversal.net
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

Any way to edit item stats yet?
Like hunger/thirst/health gain/loss?

Although using a script for them all would allow this pretty easily. Wasn't there a setting where *all* items provided a 'use item' option and triggered a script and thus disabled the normal Eat/Drink inventory options?
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

Ah um, you've been able to edit items for ages.. method is just a bit clunky and was supposed to be replaced by a world ed UI which i haven't finished yet. (That's probably why you don't know about it). Meanwhile..

Code: Select all

*setitemuse ItemName,[UseVal][|Size]
*setitemnutrition ItemName,[Primary]|[Health]|[MaxHealth]
*setitemadvancednutrition ItemName,[Val1]|[Val2]|...|[Val6]
Advanced nutrition isn't used anywhere yet. The main values for the 'UseVal' for *setitemuse are:

Code: Select all

0 - None
1 - Food
2 - Drink
3 - Misc
12 - Scripted
13 - Combination
You can now add custom named options to the main menu displays, and override each of the buttons in the player popup display, all of which trigger a 'MenuOption' event which your script can do what it likes with.
Just for reference, the 0.63.3 process is:
manually override the buttons you want to using:

Code: Select all

*scriptedoption [OPTION_NUM],[TEXT]
Valid [OPTION_NUM]s right now are :
1- F9 option on the mini menu
2 - 1st option on the player popup menu (replaces barter)
3 - 2nd option on the player popup menu (replaces challenge)
4 - 3rd option on the player popup menu
5 - 4th option on the player popup menu
(more to follow..)
e.g. Doing

Code: Select all

*scriptoption 2,Attack
Means that when you click a player's name, instead of "Barter with" being the top option, "Attack" is instead. When selected by the user, the server triggers a MenuOption event instead of the Barter one. e.g.

Code: Select all

Event( "MenuOption", "2" )
{
	*msg %PLAYER% You selected option 1 on player %TARGET%	
}
Last edited by Mit on Sat Oct 06, 2012 10:04 pm, edited 1 time 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 »

:D

so just to be noobish,
the designation %target% will apply even in the event script thats triggered after the barterrequest?

ANSWER

CUSTOM EVENTS REMEMBER WHO THE TARGET IS!!

Code: Select all

Event( "Custom", "sayhi" ) 
{
SetContext( $gTargetID )
CustomEvent("hi")
RestoreContext()
sleep (1)
CustomEvent("hello")
}
Event( "Custom", "hi" ) 
{
*msg %player% HI %player%!!!
}
Event( "Custom", "hello" ) 
{
*msg %player% youre saying hi to %target%
*msg %target% %player% said hi to you
}

Last edited by flametard on Fri Feb 08, 2013 2:38 am, edited 1 time in total.
User avatar
MasterNiCron
Posts: 582
Joined: Wed Feb 17, 2010 10:57 pm
Location: Frost

Post by MasterNiCron »

how would target verables work then any thing like this??

---------------------------------------------------

Code: Select all

Event( "MenuOption", "2" ) 
 {
   IF (%TARGET% PLAYERVAR[#] = #)
    {
      someting here
    }
  ELSE
    {
     something else here
    }
 }
or is this not evan close?
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

We're in to quite 'Intermediate level' territory here now :)

Firstly, the target variables will only apply within the event (and any events/functions called from it).. each event has a different 'context' - so, for instance, when you access a building the $gBuildingID field is valid, but in other cases (like a & command for instance) theres no building involved so the field wouldn't be relevant... $gTargetID (and %TARGET%) are relevant in events like those menu selections and other things like 'RobocrowKill'. etc.

%TARGET% (like %PLAYER%) is just a quick way of doing :

Code: Select all

$targetName = sysGetPlayerName( $gTargetID )
though theres nothing wrong with that either.

To get details of the target's playerVars (for instance), you need to get to grips with 'SetContext' and 'RestoreContext'. Setting the context allows you to choose who the 'current player' is. For example :

Code: Select all

$myKudos = $gPlayerKudos
SetContext( $gTargetID )
$targetKudos = $gPlayerKudos
RestoreContext()
*msg %PLAYER% Your kudos is $myKudos. %TARGET%'s kudos is $targetKudos
There are various ways you could keep the target player's info around for later events - you could save it in a playerVar, or pass it as a param via events, timers and osd buttons.

Heres a quick example of a targetted MenuOption event that brings up an OSD with a param to pass in a targetID when the button is pressed.

Code: Select all

Event( "MenuOption", "2" )
{
   OSDCreate( OSDWINDOW, "TargetOSD", "Challenge %TARGET%" )
   OSDAddItem( OSDBUTTON, "Button|$gTargetID", "Press here to challenge %TARGET%" )
   OSDActivate()
}

Event( "OSDSelect", "TargetOSD:Button" )
{
   $paramTargetID = $gParam[1]
   $targetName = sysGetPlayerName( $paramTargetID )
   *msg %PLAYER% You selected to challenge $targetName
}
Keep those questions coming.. this'll be a handy thread to know what sorta questions other folks will have and will help form better documentation when its all written up.
Last edited by Mit on Sun Oct 07, 2012 1:20 am, edited 1 time in total.
User avatar
Omni
Posts: 156
Joined: Sat Feb 25, 2012 11:07 am

Post by Omni »

A new generation of coders is coming up, and that's a good thing for the game.
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 »

back to a noobish question:

I tried to add more stuff like:
Event( "AccessBuilding", "40" )
{
*msg %player% A castle belonging to %buildingowner%.
}
(i've tried all sorts of stuff and nothing works, so i've fallen back to test script)

I'm running all my programs, notepad, buildings editor, Server, Client, as administrator and on the latest patches and I don't understand why things arent working. Weridly, one of my old building trigger scripts still works, and I copied the exact script to another building in the script and no script popped up. So i know my scripts are working, the new trigger buildings just arent reading them for some reason.

HELP!! :cry:
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

can you check your output in the script window of the server and see whether anything at all happens when you access the building.
this sorta thing (in my own experience) is usually something like forgetting to include a file, or having duplicate entries or something like that..
User avatar
MasterNiCron
Posts: 582
Joined: Wed Feb 17, 2010 10:57 pm
Location: Frost

Post by MasterNiCron »

ok being that did not anser the question let me refraze it
im makeing a player 2 player battle script and dont know how to compare %player% playervar to the %target% playervar such as.

Code: Select all

EVENT("MenuOption", "2")
{
 IF ([[%player%]] $gplayervar[1] >  [[%target%]] $gplayervar[1])
   {
    DO THIS
    }
 ELSE
    {
    DO THIS
    }
 }
Last edited by MasterNiCron on Sun Oct 07, 2012 6:17 pm, edited 1 time in total.
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

forget about %TARGET% and stuff in statements like that.. they're just for getting the name text for commands like '*say The Winner was %TARGET%'

To do the stuff you want you need to use SetContext, as described above.
Or to re-do your example :

Code: Select all

Event( "MenuOption", "2" )
{
  // Get the player's var 1
   $myVar = $gPlayerVar[1]

   // Get the target's var 1
   SetContext( $gTargetID )
   $targetVar = $gPlayerVar[1]
   RestoreContext()

   if ( $myVar > $targetVar )
   {
        DO THIS
   }
   else
   {
        DO THIS
   }
}
User avatar
MasterNiCron
Posts: 582
Joined: Wed Feb 17, 2010 10:57 pm
Location: Frost

Post by MasterNiCron »

was just useing the %player% and %target% to indecate the diferant players each playervar wes for :)

and thanks i understude that a lot better than the first 1 u had showed
User avatar
morbydvisns
Posts: 1889
Joined: Sun Jan 30, 2005 12:51 am

Post by morbydvisns »

wes was for none of that.
User avatar
MasterNiCron
Posts: 582
Joined: Wed Feb 17, 2010 10:57 pm
Location: Frost

Post by MasterNiCron »

i add it now world keeps crashing it take it out of script and world works fine is that stuff not active in game yet or something??
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

menuoption is 0.63.3
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 »

ok, i put the computer down, did the dishes, some sweeping, got dog food, pork chops, beer, and a headlight for the car, came back to the surprise that the problem had somehow fixed itself (i just KNEW i did everything right) so we'll never know what that funny business was actually about.
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

maybe you had forgotten to do a *reloadscript :p
User avatar
MasterNiCron
Posts: 582
Joined: Wed Feb 17, 2010 10:57 pm
Location: Frost

Post by MasterNiCron »

Mit wrote:menuoption is 0.63.3
OK I can wate then with that idea :)
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

*reloadscript?
You still do that? Not F11?
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

ooo, that's neat.

It doesn't seem to work with menu mode 2 though (been using that for the simplicity of setting up the world, building, map editing, etc)
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 »

I was turning the world on and off to reload the script and relogging.
Locked