Noobish questions, mostly about scripting

Forum Archive - from http://theuniversal.net
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

$gGameDay and $gGameTime
have been in for a while.
And on a related subject, 0.64.9 adds a newOSD 'DATE' control which allows the user to select a real-time date from a specified range. fuller docs to follow later.
User avatar
matias
World Owner
World Owner
Posts: 46
Joined: Wed Apr 24, 2013 7:37 pm

My first Script

Post by matias »

The Question is how can i add a task loading bar, an image and a sound to the script

Code: Select all

Tree
------------------------------------------------------------------------------------------------------------------
EVENT("accessbuilding", "8")
	 {
	 $RS = sysPlayerInventory("Axe")
	 if ($RS < 1)
		{
		osdcreate(OSDBUILDING, "Chop", "Tree")
		osdadditem(OSDBIGTEXT, " ", "You need an AXE")
		osdadditem(OSDBIGTEXT, " ", "")
		osdadditem(OSDBIGTEXT, " ", "")
		osdadditem(OSDEXITBUTTON, "exit", "OK")
		osdactivate()
		}

	 ELSE IF ($RS >= 1)
		

		{
		osdcreate(OSDBUILDING, "Chop", "Tree")
		osdadditem(OSDBIGTEXT, "", "Chop the Tree to get a Log")
 		osdadditem(OSDBIGTEXT, " ", "")
		osdadditem(OSDBIGTEXT, " ", "")
		osdadditem(OSDEXITBUTTON,"1", "Chop")
		osdadditem(OSDEXITBUTTON,"2", "Leave")
		osdactivate()
		}
	 
	}

EVENT("OSDSELECT", "Chop:1")
	{
	Event ("Useitem","Axe") 
	{ 
		$myVar = sysRand(50) 

		If ( $myVar = 1 ) 

		{ 
	
		*msg %player% I Told you!!!
		*msg %player% The Axe has broken down
		*grantitem %player% -1 Axe
		} 
		else If ( $myVar >= 2 ) 
		{ 
		*msg %player% Ouch it hurts!!!, Someday I'll take revenge
		*grantitem %player% 1 log
		} 
	osdactivate()
	}
My first Script Thanks to all that helped.
I always laugh when the Tree takes revenge
User avatar
MasterNiCron
Posts: 582
Joined: Wed Feb 17, 2010 10:57 pm
Location: Frost

Post by MasterNiCron »

not really shur how my self so i just been useing sleep timers
like this

Code: Select all

EVENT("playerlogin", "")
	{
	 $gPlayerVar[2] = $gPlayerVar[3]
	 IF ($gPlayerVar[1] >= 1)
		{
		 sleep(100)
		 IF ($gPlayerVar[6] >= 1)
			{
			 CustomEvent( "TIMERS" )
			}
		 ELSE
			{
			 *say blaze %player% battles ant working.
			}
		}
	 ELSE
		{
		 *say %PLAYER% is new and may need help.
		 sleep(100)
		 CustomEvent( "newplayer" )
		}
	 *say Type &cps any time to see your current player stats.
	}
where it says sleep(100) will make it wate for 10 sec then finsh the script
User avatar
matias
World Owner
World Owner
Posts: 46
Joined: Wed Apr 24, 2013 7:37 pm

Post by matias »

I know how to make that what i mean its the task that appears in aramathea when collecting clay
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

tasks is a combo of script and * command.

*dotask (player name) (task#) (text to use)

it links to a TaskStart event with a timer PlayerTaskStartSetTime


one i had made for zoric while testing is:

Event( "OSDSelect", "b44o:b44opmsmap" )
{
$gBuildingVar41=$gBuildingVar41+1
*dotask %player% 100 Working on the $gPlayerVar25
CustomEvent("b44opmsm2")
}

Event( "TaskStart", "100" )
{
PlayerTaskStartSetTime(20)
}

When the osd button is clicked to activate the first script, the task is done which lasts 20 seconds, then the first script continues, loading the custom event.
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 close the building window via script? my scource items are all in scripted buildings, but a blank building osd always pops up when u press ctrl. any ideas? thanks.
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 really hope someone can help me figure this out. I just want to make a button that closes the osd window. I made a 'blank' button, and it blanks out the osd, but doesnt close the window, and I know it's possible because buildings on aramathea do it. please help!!
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

had found this last week while looking threw the civ scripts.
Appears to close the buildings window.

osdaddat(OSDEXITBUTTON, 300, 300, 125, 30, "exit", "Exit")
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

As of the 0.65.2 buildings editor you've also got a new building type ("Scripted-NoWindow") which triggers the normal 'AccessBuilding' event but doesn't open the standard building window. You can then script whatever display you want (e.g. an OSDLIST).
What we don't have at the moment is a way to close an already open buildings window from script (which is something I've found I need for Galleons) so that'll be added later.
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 »

strange, the download links dont seem to be working for me. I tried 2 different browsers. could someone send me a linkor the new buildings editor?
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 »

Also, could someone help me build a script that allows a player to set one tile (tile#2 for this example) under the position they are standing... but only in a town that they own. I know it's possible.

I know it has something to do with:
*settile 2,$gPlayerWorldX,$gPlayerWorldY

but i dont know where all the other stuff goes and how similar it is to construction a building. thanks!
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 »

hi, i need help getting the script to properly name the town building the name the player wantsit to be named. right now, i skipped all the building names and made it so whatever they try to type, the default building name is a space.. but since towns NEED unique names as to not confuse the server, i need this one to work right. here is my script:

Code: Select all

Event( "UseSkill", "Build Town" )
{
   $itemcount = sysPlayerinventory("Stone")
   If ($Itemcount > 49)
   { 
   CustomEvent("towntown")  
   }
   else
   {
   *msg %PLAYER% You need 50 stone to construct the new town.
   }
}
Event( "Custom", "towntown" )
{
   $itemcount = sysPlayerinventory("Villagers")
   If ($Itemcount > 49)
   { 
   *buildingconstruct %PLAYER% 64  
   }
   else
   {
   *msg %PLAYER% You need 50 villagers to construct the new town.
   }
}
Event( "PlaceBuilding", "64" )
{
   $valid = sysIsBuildingPositionValid( $nBuildingCode )
   if ( $valid = 1 )
   {
   *grantitem %player% -50 stone
   $didAdd = sysAddBuildingWorld( 64, $gPlayerID,         
   $gPlayerWorldX,$gPlayerWorldY,New %player%town, $constrAmount )
   }
   else
   {
   *Customsound %player% 12 
   }
}
thanks!!
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

This should work. Hope you don't mind that I slightly changed it based on how I have zoric's building script, but hey, everybody will have their own variations :p

-combined the first 2 events so the use skill event will check stone then villagers. Also added a message so if you don't have enough stone, the script will also tell you if you need more villagers.
-since the script appears to only be for towns (building 64) made it use that number instead of using $gBuildingCode (which appears to only work while your *in* a script activated by a building)
-changed it to use $gBuildingName so spaces can be used
-removed $constrAmount, which doesn't appear to do anything in the script you posted. I don't have it anywhere on zoric's buildings and they seem to be working completely fine
-the $didAdd part in your script is on 2 seperate lines which will cause it to not work. But that could have been due to the forum.

I notice you don't have it removing villagers from the players inventory despite requiring them for a town. Don't know if that was intentional or just a mistake, so I'll leave that to you.

Image

Code: Select all


Event( "UseSkill", "Build Town" )
	{
	$stone = sysPlayerinventory("Stone")
	$villagers = sysPlayerinventory("Villagers")
	If ($stone > 49)
		{
		If ($villagers > 49)
			{
			$buildingname = "%player%'s town"
			*buildingconstruct %PLAYER% 64 $buildingname
			}
		else
			{
			*msg %PLAYER% You need 50 villagers to construct the new town.
			}
		}
	else
		{
		*msg %PLAYER% You need 50 stone to construct the new town.
		If ($villagers < 50)
			{
			*msg %PLAYER% You need 50 villagers to construct the new town.
			}
		}
	}

Event( "PlaceBuilding", "64" )
	{
	$valid = sysIsBuildingPositionValid( 64 )
	if ( $valid = 1 )
		{
		*grantitem %player% -50 stone
		$buildingName = sysGetTextEntry()
		$didAdd = sysAddBuildingWorld( 64, $gPlayerID, $gPlayerWorldX,$gPlayerWorldY, $buildingname )
		}
	else
		{
		*Customsound %player% 12
		}
	}
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 »

ah dang. i tried it, but it gave me a "this building must be within town limits" i guess the $valid = sysIsBuildingPositionValid( 64 ) stuff didnt realize it was its own town. :\
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

building type set to town in the bdat?
if the type is set to 'scripted', maybe check the box so it ignores town limits.
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 is the command: *removebuilding type,mapX,mapY
Does anybody know if this will work with $gBuildingWorldX, $gBuildingWorldY

If it only uses $gBuildingX, $gBuildingY then I need an alternative way for a script to automatically remove a building on a tile that may have mulitple copies of the same building.
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

nevermind, i figured it out:

*demolishbuilding $buildingnum
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 need to figure out how to get the sysgettextentry () stuff to work for naming the new towns as theyre built. this is what i got so far:

Code: Select all

Event( "UseSkill", "Build Town" )
{
   $buildingName = "%PLAYER%town" 
   *buildingconstruct %PLAYER% 64 $buildingname
}
Event( "PlaceBuilding", "64" )
{
   $buildingName = sysGetTextEntry()
   $didAdd = sysAddBuildingWorld(64,$gPlayerID,$gPlayerWorldX,$gPlayerWorldY,$buildingName,)
         if ( $didAdd != 0 ) 
            { 
            *msg %player% construction complete
            } 
}
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 need to figure out how to get the sysgettextentry () stuff to work for naming the new towns as theyre built. this is what i got so far:

Code: Select all

Event( "UseSkill", "Build Town" )
{
   $buildingName = "%PLAYER%town" 
   *buildingconstruct %PLAYER% 64 $buildingname
}
Event( "PlaceBuilding", "64" )
{
   $buildingName = sysGetTextEntry()
   $didAdd = sysAddBuildingWorld(64,$gPlayerID,$gPlayerWorldX,$gPlayerWorldY,$buildingName,)
         if ( $didAdd != 0 ) 
            { 
            *msg %player% construction complete
            } 
}
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 »

damn i swore this was working before... but it doesnt work now, causing problems. players need to be able to name their new town upon building it. its only naming it the default name, which means players will only be able to build a town once, after that, the script thinks the town name already exists.

Code: Select all

Event( "PlaceBuilding", "64" )
{
   $buildingName = sysGetTextEntry()
   $didAdd = sysAddBuildingWorld(64,$gPlayerID,$gPlayerWorldX,$gPlayerWorldY,$buildingName,)
         if ( $didAdd != 0 ) 
}
Event( "Custom", "towntown" )
{
   $buildingName = "%PLAYER%ton" 
   *buildingconstruct %PLAYER% 64 $buildingname
}
Locked