Page 1 of 1

A way to consolidate this script piece?

Posted: Thu Oct 25, 2012 7:45 pm
by zaroba
This piece of script is used to decide what buttons are displayed on the OSD for adding and removing items from buildings on zoric. Because of this, it will be replicated for each item in each building. The main thing I want to know is, in order to cut down on sheer length due to being for each item, can anybody see an easy way to consolidate it a bit since most of it is replicated? Mainly, the parts 'add and remove stocks' and the following part 'if player is owner' since they are completely identical.

Code: Select all

	if ("$gBuildingVar128=0")
		{
		osdaddat(OSDFADEDBUTTON, 200, xx1, 25, 25, " ", "1") 
		}
	if ("$gBuildingVar128<5")
		{
		osdaddat(OSDFADEDBUTTON, 225, xx1, 25, 25, " ", "5") 
		}
	if ("$gBuildingVar128<2")
		{
		osdaddat(OSDFADEDBUTTON, 250, xx1, 30, 25, " ", "All") 
		}
	if ("$item1=0")
		{
		osdaddat(OSDFADEDBUTTON, 300, xx1, 25, 25, " ", "1") 
		}
	if ("$item1<5")
		{
		osdaddat(OSDFADEDBUTTON, 325, xx1, 25, 25, " ", "5") 
		}
	if ("$item1<2")
		{
		osdaddat(OSDFADEDBUTTON, 350, xx1, 30, 25, " ", "All") 
		}							
	if ($gPlayerVar26=1)				\\--------------------------If player is employee
		{
		if ($gBuildingVar13=1)				\\--------------------------add stocks only
			{
			if ("$item1>0")
				{
				osdaddat(OSDFADEDBUTTON, 200, xx1, 25, 25, " ", "1") 
				}
			if ("$item1>4")
				{
				osdaddat(OSDFADEDBUTTON, 225, xx1, 25, 25, " ", "5") 
				}
			if ("$item1>1")
				{
				osdaddat(OSDFADEDBUTTON, 250, xx1, 30, 25, " ", "All") 
				}
			if ("$item1>0")
				{
				osdaddat(OSDBUTTON, 300, xx1, 25, 25, "b##v128a1", "1") 
				}
			if ("$item1>4")
				{
				osdaddat(OSDBUTTON, 325, xx1, 25, 25, "b##v128a5", "5") 
				}
			if ("$item1>1")
				{
				osdaddat(OSDBUTTON, 350, xx1, 30, 25, "b##v128aa", "All") 
				}
			}
		if ($gBuildingVar13=2)				\\--------------------------add and remove stocks
			{
			if ("$gBuildingVar128>0")
				{
				osdaddat(OSDBUTTON, 200, xx1, 25, 25, "b##v128r1", "1") 
				}
			if ("$gBuildingVar128>4")
				{
				osdaddat(OSDBUTTON, 225, xx1, 25, 25, "b##v128r5", "5") 
				}
			if ("$gBuildingVar128>1")
				{
				osdaddat(OSDBUTTON, 250, xx1, 30, 25, "b##v128ra", "All") 
				}
			if ("$item1>0")
				{
				osdaddat(OSDBUTTON, 300, xx1, 25, 25, "b##v128a1", "1") 
				}
			if ("$item1>4")
				{
				osdaddat(OSDBUTTON, 325, xx1, 25, 25, "b##v128a5", "5") 
				}
			if ("$item1>1")
				{
				osdaddat(OSDBUTTON, 350, xx1, 30, 25, "b##v128aa", "All") 
				}
			}
		}
	if ($gBuildingOwnerID = $gPlayerID)				\\--------------------------If player is owner
		{
		if ("$gBuildingVar128>0")
			{
			osdaddat(OSDBUTTON, 200, xx1, 25, 25, "b##v128r1", "1") 
			}
		if ("$gBuildingVar128>4")
			{
			osdaddat(OSDBUTTON, 225, xx1, 25, 25, "b##v128r5", "5") 
			}
		if ("$gBuildingVar128>1")
			{
			osdaddat(OSDBUTTON, 250, xx1, 30, 25, "b##v128ra", "All") 
			}
		if ("$item1>0")
			{
			osdaddat(OSDBUTTON, 300, xx1, 25, 25, "b##v128a1", "1") 
			}
		if ("$item1>4")
			{
			osdaddat(OSDBUTTON, 325, xx1, 25, 25, "b##v128a5", "5") 
			}
		if ("$item1>1")
			{
			osdaddat(OSDBUTTON, 350, xx1, 30, 25, "b##v128aa", "All") 
			}
		}



Image

Posted: Thu Oct 25, 2012 8:00 pm
by zaroba
Nevermind, I figured out a way.

I split adding and removing stocks into 2 separate OSDs and limited access to them instead of having the script decide what buttons to display based on what vars are set.

Posted: Thu Oct 25, 2012 10:35 pm
by Mit
Use OSDValue

Posted: Thu Oct 25, 2012 10:51 pm
by zaroba
seems to not work...although its more probable that i'm doing something wrong.

Code: Select all

Event("&command", "test")
	{
	*say server var 1 = $gServerVar1
	osdcreate(OSDLIST,"test","test")
	osdadditem(OSDTEXT, "", " ")
	osdaddat(OSDVALUE, 100, 100, 100, 20, "buyval", "$gServerVar1|0|50|1|Not Buying")
	osdaddat(OSDBUTTON, 220, 100, 150, 20, "SetBuy|&buyval", "Set Buy Price")
	osdadditem(OSDTEXT, "", " ")
	osdactivate()
	}
Took the example you made in the topic about it and only changed the $buyvar to $gServerVar1
$gserverVar1 remains at 0.

Posted: Thu Oct 25, 2012 11:12 pm
by Mit
whats your SetBuy OSDSelect look like?
Sorry wasn't clear earlier.. but that first param of the OSDValue (where you've put the $gServerVar1) is just the initial value for the OSDValue control.

To make it set anything you need something like

Code: Select all

Event( "OSDSelect", "SetBuy" )
{
   $gServerVar1 = $gParam[1]
}
The $gParam[1] is set in the "SetBuy|&buyVar" with the &buyVar being a reference to the value that is selected in the OSDValue control.

Posted: Fri Oct 26, 2012 12:34 am
by zaroba
Figures I was missing the 2nd half of it :oops:

Got it working now. I'm guessing those $gParam vars are basically just temp vars that get erased when the script finishes? I notice they carry threw osd events, and are retained when a custom event is called, but when hitting escape they seem to return to 0.

Are they linked per player? per building? server wide? per script run?

Only thing I want to avoid is the possibility of having 2 different players running scripts at the same time and coincidentally hitting buttons that use the same $gParam# var and something getting mixed up.

Posted: Sat Oct 27, 2012 12:36 am
by Mit
$gParams are per event. theres no issue with them getting mixed up.

atm, they're only valid during an OSDSelect event if you've passed em in as | separated fields in a button or image identifier.
(and in the "PlaceAnyBuilding" event, linked to *buildingconstruct [NAME] [BUILDING_NUM] which we need to explore separately :) )