Noobish questions, mostly about scripting

Forum Archive - from http://theuniversal.net
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 know im getting on people's nerves, but i am wondering if anyone knows if its possible to make the script determine if a player's inventory has open slots in the inventory? :oops:



ANSWER!

Code: Select all

Event("custom","FB")
{
If ( $gPlayerInventoryFree > 0 )
{
*grantitem %player% -10 Flowerbuds
*grantitem %player% 7 Black Magic
}
else
{
*msg %player% Inventory at capacity, please free up 1 slot in your inventory for the Magic.
}
}
Last edited by flametard on Fri Feb 08, 2013 3:01 am, 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 »

gPlayerInventoryFree
gPlayerInventoryUsed


now i need to learn what they do. I think the first determines if its empty, or if 1 slot is open. and the second determines if its full. :)
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

$gPlayerInventoryFree is the number of empty slots remaining.
$gPlayerInventoryUsed is the number of slots used

All items default to size 1 atm, unless you've specifically changed em.
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

Btw, to answer some of the earlier conv, heres an example of a working value control from Aramathea. The OSD allows the user to view and set the current values of BuildingVars 1 and 2.

Code: Select all

Event( "OSDSelect", "StablesOSD:ApplyLimits" )
{
	$gBuildingVar[1] = $gParam[1]
	$gBuildingVar[2] = $gParam[2]

	$ret = StablesMainOSDCreate()
}

Event( "OSDSelect", "StablesOSD:SetLimits" )
{
	osdcreate(OSDBUILDING,"StablesOSD", "Stables" ) 

	$currentHorseLimit = $gBuildingVar[1]
	osdaddat(OSDTEXTRIGHT, 340, 104, 0, 0, "", "Max number of horses :") 
	osdaddat(OSDVALUE, 350, 100, 100, 25, "horselimit", "$currentHorseLimit|0|10") 

	$currentHayLimit = $gBuildingVar[2]
	osdaddat(OSDTEXTRIGHT, 340, 144, 0, 0, "", "Max amount of Hay stored :") 
	osdaddat(OSDVALUE, 350, 140, 100, 25, "haylimit", "$currentHayLimit|0|100") 

	osdaddat(OSDAPPLYBUTTON, 250, 200, 200, 25, "applylimits|&horselimit|&haylimit", "Apply changes") 
	osdaddat(EXITBUTTON, 10, 345, 150, 20, "", "Close") 
	osdactivate() 
}
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 »

Does anyone know why my code wont work? I'm assuming when you have a skill you have it at level 1.


Event("Useitem","Ring of Protection")
{
$var =Event("custom","FB")
{
If ( $gPlayerInventoryFree > 0 )
{
*grantitem %player% -10 Flowerbuds
*grantitem %player% 7 Black Magic
}
else
{
*msg %player% Inventory at capacity, please free up 1 slot in your inventory for the Magic.
}
}("Shamanic Sight")
If ($var > 0)
{
*customsound %player% 24
*effect %player% 2
sleep (5)
*gocrow %player% 1
*msg %player% dress yourself or relog to return to your body.
}
else
{
*msg %player% You need the Shamanic Sight skill to weild this ring.
}
}
ASNWER
PlayerInventoryFree should be sysPlayerInventoryFree
Last edited by flametard on Fri Feb 08, 2013 3:03 am, edited 1 time in total.
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

need to put sys in front of playerskilllevel

$var = sysPlayerskilllevel("Shamanic Sight")
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 »

graaacias!
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 »

Anyone know how to get the script to recognize the %TARGET%'s cash? i tried something like:
Event( "MenuOption", "3" )
{
If ( $gTargetCash > 499 )
{
*msg %player% this dude is loaded
}
else
{
*msg %player% this chump is broke as a joke
}
}
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

might work based on mits examples on the 2nd page:


Event( "MenuOption", "3" )
{
SetContext( $gTargetID )
$targetcash = $gPlayercash
RestoreContext()
If ( $TargetCash > 499 )
{
*msg %player% this dude is loaded
}
else
{
*msg %player% this chump is broke as a joke
}
}
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 »

this work
Event( "MenuOption", "3" )
{
SetContext( $gTargetID )
$targetcash = $gPlayercash
*say %target% has $gPlayercash
RestoreContext()
}
THE ABOVE WAS KINDA WRONG!!
I HAVE A BETTER EXAMPLE NOW!

Code: Select all

Event("custom","pocketcheck")
{
SetContext( $gTargetID ) 
$targetcash = $gPlayercash
If ( $gPlayercash > 499 )
   {
   RestoreContext()
   CustomEvent("pickpocket")
   }
else
   {
   RestoreContext()
   *msg %player% Attempting to pick %target%'s pocket.
   *customsound %player% 3
   sleep (20)
   *msg %player% Attempt failed.
   }
}
Last edited by flametard on Fri Feb 08, 2013 3:05 am, edited 1 time in total.
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

can't goto same building twice in a row

Code: Select all

Event("AccessBuilding", "##")
	{
	if ($gPlayerVar26 = $gBuildingAccessNum)
		{
		*msg %player% Nothing here
		}
	else
		{
		$gPlayerVar26=$gBuildingAccessNum
		*msg %player% you found (whatever)
		*grant %player% # whatever
		}
	}		
Replace the ## in access building with the bdat building number
Replace the Whatever with an item and give an amount for the grant command.
Replicate for each BDAT building its needed for.

Make other changes as needed (playervar, text, etc)

When a player access the building, the script checks the playervar to see if it matches the $gBuildingAccessNum var. If it does, the player cannot access the building. If it does not, the player gets granted stuff and their playervar is set ot equal $gBuildingAccessNum. Thus preventing them from accessing that building again until they access a different building that changes that var.
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 »

oop! :O ok i will test it soon :) THANKS!





THANK YOU ALL for helping me out! i finished the work and hope these questions and answers might help other world builders someday! good luck!

Image
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 »

OOPS! 1 more question:

can i add the little admin button to a scripted building via OSD or something? the little oval one that gives a bunch of options like demolish building, sell building. rename building, etc etc. Or does it all have to be scripted by hand?
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

Do you mean for building owners or for world admins to have access to *all* buildings?

If you mean the first, then it would have to check and only display the button if the player is the buildings owner. If you mean the 2nd, then you need to manually set a var on players who are admins, and set the button to only display if the player has that var. Both ways are pretty easy and pretty much the same, only difference is how it checks if it should show the button.


How much needs to be in the OSD for the building depends on what options are desired.
The initial button would at least need to be in the OSD.
Any buttons it takes you to may not need to be though, unless they are building specific. For example, a button to set a buildings sale price or employee salary wouldn't need to be in each OSD.
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 scanned through the world manual and couldnt find my answer.
All i really need is a demolish building button. I know how to make it for the owner only. How do i get the script to demolish the building which is triggered, and give the appropriate construction item back, or would i have to just *grantitem it?
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

To activate the "little oval one that gives a bunch of options like demolish building, sell building. rename building, etc etc" set *settings -> Buildings -> Scripted Buildings to 1.

To set a percentage of the building materials to be recouped on demolish, set *settings -> Buildings -> Demolish Options (which has been renamed to 'Demolish Recoup Percentage' for 0.64.2).

If you want to do something more custom you can script a custom option to do it.

Adding a button that only appears for the owner is easy (and something you'll see done frequently in the civ sample code)..

Code: Select all

	if ( $gBuildingOwnerID == $gPlayerID )
	{
	      // Add your owner button(s) here
	}
	else
	{
                           // Don't
                      }
From there, yeh, you'd do the normal OSDSelect event and *grantitem any items you want to return.
That leads to the interesting conclusion that there isnt a command to demolish an individual building yet (only *demolishplayerbuildings, which removes everything the player owns) so *demolishbuilding [BUILDING_ID] has been added for the 0.64.2 server
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

How does one set up a script to show a ghosted building when 'using' a skill to activate the OSD that allows construction like on Civ and now Aramathea?

I was looking threw the Civ scripts and found the OSDs from the various use skill events, but it looked to me like the buttons and info for that little bit seemed to have been removed from them as the OSDs only listed the building names, a web picture, and what they neded to be made. No buttons.
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

mm, do you mean .. ?

Code: Select all

*buildingconstruct %PLAYER% $buildingNum $buildingName
this triggers the construction process with the semi-transparent building model.
When the user selects construct, a PlaceBuilding event is triggered with the building num as parameter (and PlaceAnyBuilding event is triggered for any building types that don't have a PlaceBuilding event specified).
Somewhere in there you'd generally use sysAddBuilding or sysAddBuildingWorld to finish off the construction.

The default "PlaceAnyBuilding" event for Aramathea looks like this :

Code: Select all

Event( "PlaceAnyBuilding", "" )
{
    $nBuildingCode = $gParam[1]
    $posX = $gPlayerWorldX
    $posY = $gPlayerWorldY

    $hasWood = sysPlayerInventory( "Wood" )
    if ( $hasWood >= 5 )
    {
        $valid = sysIsBuildingPositionValid( $nBuildingCode )
        if ( $valid = 1 )
        {
             $buildingName = sysGetTextEntry()
             $newBuildingID = sysAddBuildingWorld( $nBuildingCode,$gPlayerID,$posX,$posY,$buildingName,-1 )
              if ( $newBuildingID != 0 )
              {
                   *grantitem %PLAYER% -5 Wood
              }
         }
    }
    else
    {
        *msg %PLAYER% You need 5 wood to build
    }
}
User avatar
MasterNiCron
Posts: 582
Joined: Wed Feb 17, 2010 10:57 pm
Location: Frost

Post by MasterNiCron »

i got a 2 part question

{1}is there a way to make a scrip run as soon as its a new game day and if so can u make it cheack what day of year it is.

used to make sertan days have events happen anuely (i.e. holadays)
and to make some scripts only work dering sertan set of days (i.e seaonal events)

so say if my world has 48 days it will check every start of the day to see what day it is if it comes back day 1 it will say happy new year to eavry 1 and activat spring events and if it comes back as day (13) summer events will abcome activ and lock spring events ect..ect..ect....

{2}could it also check year to see if it contans a sertan # in the year??

say so a specal event will oonly run if the year has a 4 in it or someting (i.e.if the year is 243 the event will becom active cas it has a #4 in it but year 152 dont so the event is then locked till next year with a #4 in it ect..ect..ect....
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

I don't think there is any script stuff currently to detect gameday/year.

But, a kinda complex workaround is to set the production cycle to run every game day and have a script run every time a production cycle runs.

To tie in the other stuff asked about, you need to have the script add 1 to a var (timevar or the timer will stop working on day 32 of year 683, day 32768) you'd have to calculate out what gameday it would be (from the start of the timer) and have it do various things whenever the var hit that number (did it in msexcell to make the below examples actually, can send it to you if you want)

So, with a 48 gameday year with the first day being day 1 of year 1:
$gServerTimeVar1=49 = new year
$gServerTimeVar1=97 = new year
$gServerTimeVar1=145 = new year
$gServerTimeVar1=193 = new year
etc, counting every 48


for years with a 4, more calculating
$gServerTimeVar1=145 to 192 = year 4
$gServerTimeVar1=625 to 672 = year 14
(add 480 to both numbers to count by every 10 years to get the years ending in 4)

$gServerTimeVar1=1873 to 2352 = years 40 threw 49
$gServerTimeVar1=19153 to 23952 = years 400 threw 499
Locked