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 »

Wasn't there mention years ago about a way to basically 'make' an npc account like jehovah is?

A command that you type and it gives a billing id a name so it can be used as an npc to hold buildings.
User avatar
morbydvisns
Posts: 1889
Joined: Sun Jan 30, 2005 12:51 am

Post by morbydvisns »

That will probably be an entity function.
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

Code: Select all

*addtoinvestment [building_num] [amount]
*removefrominvestment [building_num] [amount]
$gBuildingInvestment 
are in 0.63.5.
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 »

$var = sysRand(5) returns a value from 1 to 5
ok, so how would i use this in an event script? say i wanted to make a usable item draw a number from 1-5 and after it drew the number *say the according number via text. thanks :) [/quote]
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

should be as straightforward as :

Code: Select all

$myVar = sysRand(5)
*say The random number selected was $myVar
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 »

would this work?
Event ("Useitem","Dice")
{
$myVar = sysRand(6)
If ( $myVar = 1 )
*say you rolled a one.
}
else
{
If ( $myVar = 2 )
*say you rolled a two.
}
else
{
If ( $myVar = 3 )
*say you rolled a three.
}
else
{
If ( $myVar = 4 )
*say you rolled a four.
}
else
{
If ( $myVar = 5 )
*say you rolled a five.
}
else
{
*say you rolled a six.
}
}
}
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 »

hmm that didnt work. it only rolled a 1 over and over, and it seemed a bit weird, didnt register every time
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

'else's replaced with 'else if's (except the last one)
the statements after the ifs need to be encased in { and }

Code: Select all

Event ("Useitem","Dice")
	{
	$myVar = sysRand(6)
	If ( $myVar = 1 )
		{
		*say you rolled a one.
		}
	else If ( $myVar = 2 )
		{
		*say you rolled a two.
		}
	else If ( $myVar = 3 )
		{
		*say you rolled a three.
		}
	Else If ( $myVar = 4 )
		{
		*say you rolled a four.
		}
	else If ( $myVar = 5 )
		{
		*say you rolled a five.
		}
	else
		{
		*say you rolled a six.
		}
	} 
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

More complex example
ELSEs removed entirely, only IFs

*Player activates dice item, which activates the customevent for dice rolling
*rand value assigned, game goes down the script and does the *say command from the matching IF statement
*the game continues down the script and finds the OSD
*player selects Yes or No

If the player selected Yes, the customevent RollDice is activated again
If the player selected No, they get a message saying thanks for playing

If the 'no' event is removed, then the osd will just close when the player clicks no.

Code: Select all

Event ("Useitem","Dice")
	{
	CustomEvent("RollDice")
	}

Event("custom", "RollDice")
	{
	$myVar = sysRand(6)
	If ( $myVar = 1 )
		{
		*say you rolled a one.
		}
	If ( $myVar = 2 )
		{
		*say you rolled a two.
		}
	If ( $myVar = 3 )
		{
		*say you rolled a three.
		}
	If ( $myVar = 4 )
		{
		*say you rolled a four.
		}
	If ( $myVar = 5 )
		{
		*say you rolled a five.
		}
	If ( $myVar = 6 )
		{
		*say you rolled a six.
		}
	sleep(10)
	osdcreate(OSDBUILDING,"dice","dice")
	osdaddat(OSDTEXT, 100, 100, , , "", "Roll Again?")
	osdaddat(OSDBUTTON, 50, 200, 50, 25, "yes", "Yes")
	osdaddat(OSDBUTTON, 150, 200, 50, 25, "no", "No")
	osdactivate()
	}

Event( "OSDSelect", "dice:yes" )
	{
	CustomEvent("RollDice")
	}

Event( "OSDSelect", "dice:no" )
	{
	*msg %player% Thank you for playing!
	}
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 »

Thanks very much, Zar! I've already souped up the 2 events that needed to be randomized and might do some more for other events!



Next, crucially Important Question #20:



I was hoping I could grant the player 1 bottle when they drank a drink item. can i do it by adding a useitem event for the drink, or do i need to script all my food and drink items to do it?

ANSWERRED!!! the food and drink items work WITH their corresponding item number use events! so the drink grape juice automatically removes itselfe from the players inventory unless the player is full. this script just accentuates what it naturally does.

Code: Select all

Event("Useitem","Grape Juice")
   {
If ( $gPlayerThirst = 0 )
   {
   *msg %player% You're not thirsty.
   }
else
{
*grantitem %player% 1 bottles
}
}



which leads me to the next question:
are there currently commands to raise and lower a players hunger, thirst, and/or health via script?
Last edited by flametard on Fri Feb 08, 2013 2:51 am, edited 4 times 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 »

Anybody know if there is a limit to the number of text characters that can be displayed in an 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 know that if you put too much text on one line in a book item, it crashes the game. My guess for osd limit would be it might be different depending on how you have your screen resolution/ moniter settings. Larger window means larger default osd, which means more room for text. I know the book items were this way when putting in html suppourted pictures a few years ago. Some players would be able to see the whole test picture, while it would cut off at the bottom or sides for other players. cant confirm its this way for osd's, just my guess.
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 »

CRUCIAL QUESTION#20 ANSWERED!!

*settings> world rules> inventory mode 2

create a useitem event for the drink, in my case it just grants the player 1 bottles.

the drink will now cure thirst AND give a bottle! :D


the bit about editing itemproperties was covered by Mit in page 2 of this thread and i skimmed over it by accident.

:oops:

thanks everyone! things going along swimmingly now.
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

lol, stim,
I must have not have been thinking straight when i made those above scripts for you, neither one of them needs any IF statements..

Code: Select all

Event ("Useitem","Dice")
	{
	$myVar = sysRand(6)
	*say you rolled a $myVar
	} 

Code: Select all

Event ("Useitem","Dice")
   {
   CustomEvent("RollDice")
   }

Event("custom", "RollDice")
   {
   $myVar = sysRand(6)
   osdcreate(OSDBUILDING,"dice","dice")
   osdaddat(OSDTEXT, 100, 50, , , "", "You rolled a $myvar")
   osdaddat(OSDTEXT, 100, 100, , , "", "Roll Again?")
   osdaddat(OSDBUTTON, 50, 200, 50, 25, "yes", "Yes")
   osdaddat(OSDBUTTON, 150, 200, 50, 25, "no", "No")
   osdactivate()
   }

Event( "OSDSelect", "dice:yes" )
   {
   CustomEvent("RollDice")
   }

Event( "OSDSelect", "dice:no" )
   {
   *msg %player% Thank you for playing!
   } 
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 »

technically true, my goal was actually to figure out ways to make outcomes for each number rolled (was re-doing my disease scripts).Thanks for clarifying, though. :) helpful knowledge here.
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 »

Hey, I'm in the home stretch of finishing up my world, and next on the list is to finish the half dozen or so scripted buildings. I'm going to sift through the material, but in the spirit of noobness, I'm going to hope that some of these questions are so easy, that you guys can spout off some of the answers off hand and help me out a bit. :)

Question A:
How do i make the script check if the player possesses an item?
ANSWER

Code: Select all

Event("Useitem","Flowerbuds")
{
$Itemcount = sysPlayerinventory ("Fire")
If ( $Itemcount > 0 )
   {
   *grantitem %player% -1 flowerbuds
   *effect %player% 9
   sleep (30)
   *msg %player% The Flowerbuds have cought fire!
   }
else
   {
   *msg %player% The smell is light, yet pungent aromas of citrus and berries.
   }
}
Question B:
Can I make a ticker that trades the number of items specified by the amount set on the ticker?

Question C:
Can I make the script decrease your thirst by small increments?


Question D:
can the script check to see if the players inventory is clear?
ANSWER

Code: Select all

Event("custom","Princess")
{
If ( $gPlayerInventoryFree > 0 )
{
*grantitem %player% -1 Magical Armor
*grantitem %player% 1 Message from the Princess
}
else
{
sleep (10)
*msg %player% Oh, please free up 1 slot in your inventory for the Message.
}
}

Question E:
checks to see if the player possesses a skill
ANSWER

Code: Select all

Event("Useitem","Ring of Speed")
{
$var = sysPlayerskilllevel("Shamanic Sight")
If ($var > 0)
{
*customsound %player% 24
*effect %player% 2
sleep (5)
*gocrow %player%
*msg %player% dress yourself or relog to return to your body.
}
else
{
*msg %player% You need the Shamanic Sight skill to weild this ring.
}
}
Last edited by flametard on Fri Feb 08, 2013 2:57 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 »

I think i figured out A, and E. :) night
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 »

New Question:
is there any way to close the buildings window via script? or do players have to press esc to close that window always? i tried *osdclosewindow %player% but it didnt work

ANSWER:

I made an invisible osd which removes the current one just the way i wanted it. I did it using a sleep timer :)
Last edited by flametard on Fri Feb 08, 2013 3:00 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 »

I don't know if there is a way to make it close automatically. but, you could toss in an OSDbutton labelled close and not have it point to anything. Player clicks it, the OSD closes.

For a ticker, there is the way the scripts work on civilization. using tempvars etc which mit could better explain. click click click clkick to increase the amount, or like the bank, click and hold. Could use buttons with numbers that set a var to that number and the amount transferred is that var (ie, click a button labeled '10' to set playervar5 to 10, and then when they click the item, they are granted playervar5 of that item. I'm going to script a calculator style OSD number input thing for zoric so players can 'type in' amounts.

I think there are commands that are somehting along the lines of addthirst and addhunger. Script could use those commands to adjust thirst/hunger

There is a command to see how many items are in inventory, or percent filled. Civilizations scripts use it and the buildings show a message saying 'Inventory full' if you have 15 items when you load up a purchase screen.



for those last two, in the most recent few pages of the general forum, the commands should be listed in one of the version changes topics that mit posted
Last edited by zaroba on Sat Jan 12, 2013 7:08 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 »

ive actually got everything answered that i needed, and ill go in and edit all my questions to include the answers for others, soon.
Locked