_MEMBER_FUNCTION_IMPL(GUIFont, drawText)
{
	CEGUI::Font * pFont = sq_getinstance<CEGUI::Font *>(pVM);

	if(!pFont)
	{
		sq_pushbool(pVM, false);
		return 1;
	}

	const char* text;
	SQBool sbRelative;
	float x, y;
	sq_getfloat(pVM, -4, &x);
	sq_getfloat(pVM, -3, &y);
	sq_getstring(pVM, -2, &text);
	sq_getbool(pVM, -1, &sbRelative);

	// Get our GUI instance
	CGUI * pGUI = g_pClient->GetGUI();
	
	if(sbRelative != 0) 
	{
		x *= pGUI->GetDisplayWidth();
		y *= pGUI->GetDisplayHeight();
	}

	pGUI->DrawText(text, CEGUI::Vector2( x, y ), (CEGUI::colour)D3DCOLOR_RGBA(255, 255, 255, 255), pFont, true, true);
	sq_pushbool(pVM, true);
	return 1;
}
Example #2
0
SQInteger CSharedVehicleNatives::SetWindowOpen( SQVM * pVM )
{
	// Get the vehicle id
	SQInteger vehicleId;
	sq_getinteger( pVM, -3, &vehicleId );

	// Get the seat id
	SQInteger iSeat;
	sq_getinteger( pVM, -2, &iSeat );

	// Get the state
	SQBool bState;
	sq_getbool( pVM, -1, &bState );

	// Is the vehicle active?
	if( pCore->GetVehicleManager()->IsActive( vehicleId ) )
	{
		// Set the window state
		pCore->GetVehicleManager()->Get( vehicleId )->SetWindowOpen( iSeat, bState );

		sq_pushbool( pVM, true );
		return 1;
	}

	sq_pushbool( pVM, false );
	return 1;
}
_MEMBER_FUNCTION_IMPL(GUIElement, setPosition)
{
	float x, y;
	SQBool relative;
	sq_getbool(pVM, -1, &relative);
	sq_getfloat(pVM, -2, &y);
	sq_getfloat(pVM, -3, &x);

	CGUIFrameWindow * pWindow = sq_getinstance<CGUIFrameWindow *>(pVM);

	if(!pWindow)
	{
		sq_pushbool(pVM, false);
		return 1;
	}

	if(relative != 0)
	{
		pWindow->setPosition(CEGUI::UVector2(CEGUI::UDim(x, 0), CEGUI::UDim(y, 0)));
	}
	else
	{
		pWindow->setPosition(CEGUI::UVector2(CEGUI::UDim(0, x), CEGUI::UDim(0, y)));
	}
	sq_pushbool(pVM, true);
	return 1;
}
_MEMBER_FUNCTION_IMPL(GUIElement, getPosition)
{
	SQBool relative;
	sq_getbool(pVM, -1, &relative);

	CGUIFrameWindow * pWindow = sq_getinstance<CGUIFrameWindow *>(pVM);

	if(!pWindow)
	{
		sq_pushbool(pVM, false);
		return 1;
	}

	CEGUI::Vector2 pos;

	if(relative != 0)
	{
		pos = pWindow->getPosition().asRelative((CEGUI::Size(g_pClient->GetGUI()->GetDisplayWidth (), g_pClient->GetGUI()->GetDisplayHeight())));
	}
	else
	{
		pos = pWindow->getPosition().asAbsolute((CEGUI::Size(g_pClient->GetGUI()->GetDisplayWidth (), g_pClient->GetGUI()->GetDisplayHeight())));
	}

	CSquirrelArguments args;
	args.push(pos.d_x);
	args.push(pos.d_y);
	sq_pusharg(pVM, CSquirrelArgument(args, true));
	return 1;
}
Example #5
0
SQInteger CSharedVehicleNatives::SetPartOpen( SQVM * pVM )
{
	// Get the vehicle id
	SQInteger vehicleId;
	sq_getinteger( pVM, -3, &vehicleId );

	// Get the part id
	SQInteger iPart;
	sq_getinteger( pVM, -2, &iPart );

	// Get the state
	SQBool bState;
	sq_getbool( pVM, -1, &bState );

	// Is the vehicle active?
	if( pCore->GetVehicleManager()->IsActive( vehicleId ) )
	{
		// Toggle the vehicle part
		pCore->GetVehicleManager()->Get( vehicleId )->SetPartOpen( iPart, bState );

		sq_pushbool( pVM, true );
		return 1;
	}

	sq_pushbool( pVM, false );
	return 1;
}
Example #6
0
_MEMBER_FUNCTION_IMPL(xml, nodeNew)
{
    CXML * pXML = sq_getinstance<CXML *>(pVM);

    if(!pXML)
    {
        CLogFile::Print("Failed to get the XML instance.");
        sq_pushbool(pVM, false);
        return 1;
    }

    SQBool linkNewXml;
    const char * XmlName;

    sq_getbool(pVM, -2, &linkNewXml);
    sq_getstring(pVM, -1, &XmlName);

#pragma warning(disable:4800)
    bool linkXml = (bool)linkNewXml;

    pXML->newNode(XmlName, linkXml);
    sq_pushbool(pVM, true);
    return 1;

}
Example #7
0
// setTrafficLightsLocked(bool locked)
SQInteger CWorldNatives::SetTrafficLightsLocked(SQVM * pVM)
{
	SQBool b;
	sq_getbool(pVM, 2, &b);
	
	CTrafficLights::GetInstance()->SetLocked(b != 0);
	sq_pushbool(pVM, true);
	return 1;
}
Example #8
0
bool SquirrelObject::GetBool(const SQChar *key) //const
{
	SQBool ret = FALSE;
	if(GetSlot(key)) {
		sq_getbool(m_Vm.GetVMPtr(),-1,&ret);
		sq_pop(m_Vm.GetVMPtr(),1);
	}
	sq_pop(m_Vm.GetVMPtr(),1);
	return ret?true:false;
}
Example #9
0
SQInteger CEventNatives::AddEvent ( SQVM *pVM )
{
	const char * szEventName;
	SQBool bTriggerable = SQTrue;
	sq_getstring ( pVM, 2, &szEventName );
	sq_getbool ( pVM, 3, &bTriggerable );

	g_pServer->GetResourceManager()->AddEvent ( CString ( szEventName ), (bTriggerable == SQTrue ? true : false) );

	sq_pushbool ( pVM, true );
	return 1;
}
// toggleAutoAim(toggle)
SQInteger CServerNatives::ToggleAutoAim(SQVM * pVM)
{
	SQBool bSwitch;
	sq_getbool(pVM, -1, &bSwitch);

	bool bToggle = (bSwitch != 0);
	CVAR_SET_BOOL("autoaim", bToggle);

	CBitStream bsSend;
	bsSend.Write(bToggle);
	g_pNetworkManager->RPC(RPC_ScriptingToggleAutoAim, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE, INVALID_ENTITY_ID, true);
	return 1;
}
Example #11
0
/*
 * get boolean value from the stack.
 * this function accepts both integer(1,0) and bool(true,false).
 * returns true if succeeds.
 */
bool getBool(HSQUIRRELVM v, int idx, SQBool* value) {
	if (sq_gettype(v, idx) == OT_INTEGER) {
		SQInteger val;
		sq_getinteger(v, idx, &val);
		*value = (val == 1);
	} else if (sq_gettype(v, idx) == OT_BOOL) {
		sq_getbool(v, idx, value);
	} else {
		return false;
	}
	
	return true;
}
Example #12
0
SQInteger SquirrelStd::notifyallexceptions(HSQUIRRELVM vm)
{
	SQBool b;

	if (sq_gettop(vm) >= 1) {
		if (SQ_SUCCEEDED(sq_getbool(vm, -1, &b))) {
			sq_notifyallexceptions(vm, b);
			return 0;
		}
	}

	return SQ_ERROR;
}
Example #13
0
void CSquirrelVM::Pop(bool& b)
{
	SQObjectType argType = sq_gettype(m_pVM, m_iStackIndex);
	if (argType == OT_BOOL)
	{
		SQBool sqB;
		sq_getbool(m_pVM, m_iStackIndex++, &sqB);
		b = sqB ? true : false;
		return;
	}

	b = false;
	m_iStackIndex++;
}
Example #14
0
SQInteger SFInitScreen(HSQUIRRELVM v)
{
    int w;
    int h;
    const char *title;
    bool fullscreen;
    sq_getinteger(Scripts.vm, 2, &w);    /* получаем 1-ый */
                                         /* переданный параметр */
    sq_getinteger(Scripts.vm, 3, &h);
    sq_getstring(Scripts.vm, 4, &title);
    sq_getbool(Scripts.vm, 5, &fullscreen);
    ScreenInit(w, h, title, fullscreen);
    return 0;
}
Example #15
0
_MEMBER_FUNCTION_IMPL(GUIElement, setVisible)
{
	CGUIFrameWindow * pWindow = sq_getinstance<CGUIFrameWindow *>(pVM);
	if(!pWindow)
	{
		sq_pushbool(pVM, false);
		return 1;
	}

	SQBool visible;
	sq_getbool(pVM, -1, &visible);

	pWindow->setVisible(visible != 0);
	sq_pushbool(pVM, true);
	return 1;
}
Example #16
0
// toggleActorHelmet(actorid, toggle)
SQInteger CActorNatives::ToggleHelmet(SQVM * pVM)
{
	EntityId actorId;
	SQBool helmet;
	sq_getentity(pVM, -2, &actorId);
	sq_getbool(pVM, -1, &helmet);
		
	if(g_pActorManager->DoesExist(actorId))
	{
		bool bToggle = (helmet != 0);
		g_pActorManager->ToggleHelmet(actorId, bToggle);
		return 1;
	}
	sq_pushbool(pVM, false);
	return 1;
}
Example #17
0
// toggleActorFrozen(actorid, toggle)
SQInteger CActorNatives::ToggleFrozen(SQVM * pVM)
{
	EntityId actorId;
	SQBool frozen;
	sq_getentity(pVM, -2, &actorId);
	sq_getbool(pVM, -1, &frozen);
		
	if(g_pActorManager->DoesExist(actorId))
	{
		bool bToggle = (frozen != 0);
		g_pActorManager->ToggleFrozen(actorId, bToggle);
		return 1;
	}
	sq_pushbool(pVM, false);
	return 1;
}
Example #18
0
// toggleActorBlip(actorid, toggle)
SQInteger CActorNatives::ToggleBlip(SQVM * pVM)
{
	EntityId actorId;
	SQBool show;
	sq_getentity(pVM, -2, &actorId);
	sq_getbool(pVM, -1, &show);
		
	if(g_pActorManager->DoesExist(actorId))
	{
		bool bToggle = (show != 0);
		g_pActorManager->ToggleBlip(actorId, bToggle);
		return 1;
	}
	sq_pushbool(pVM, false);
	return 1;
}
Example #19
0
_MEMBER_FUNCTION_IMPL(GUICheckBox, setChecked)
{
	SQBool sqbChecked;
	sq_getbool(pVM, -1, &sqbChecked);

	CEGUI::Checkbox * pWindow = sq_getinstance<CEGUI::Checkbox *>(pVM);

	if(!pWindow)
	{
		sq_pushbool(pVM, false);
		return 1;
	}

	pWindow->setSelected(sqbChecked != 0);
	sq_pushbool(pVM, true);
	return 1;
}
Example #20
0
int Sq_Export() {
  // take the level path and take off the filename
  strcpy(ExportPath, LevelFilenameFull);
  char *Temp = strrchr(ExportPath, '/');
  if(!Temp)
    Temp = strrchr(ExportPath, '\\');
  if(!Temp)
   strcpy(ExportPath, "./");
  if(Temp)
    Temp[1] = 0;
  SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Exporting to \"%s\"", ExportPath);

  const char *ExportFormat = GetLevelStr("", "Meta/ExportFormat");
  if(!ExportFormat || !*ExportFormat) {
    SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "No export format specified in the file");
    return 0; // no format
  }

  SquirrelHook *Hook = AllExportFormats;
  for(; Hook; Hook=Hook->Next) {
    if(!strcasecmp(Hook->Name, ExportFormat))
      break;
  }
  if(!Hook) {
    SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "No exporter registered for \"%s\"", ExportFormat);
    return 0; // format not found
  }

  IsExporting = 1;
  SQInteger top = sq_gettop(Hook->Script);
  sq_pushroottable(Hook->Script);
  sq_pushobject(Hook->Script, Hook->Function);
  sq_pushroottable(Hook->Script); // push "this"
  sq_call(Hook->Script, 1, SQTrue, SQTrue);
  IsExporting = 0;

  // if we return a true, then it was successful
  SQBool BoolResult = SQFalse;
  if(OT_BOOL == sq_gettype(Hook->Script,-1))
    sq_getbool(Hook->Script, -1, &BoolResult);
  sq_settop(Hook->Script,top);

  return (BoolResult==SQTrue)?1:0;
}
Example #21
0
bool CScripts::onRconCommand(const char *command, const char *arg)
{
	bool found = false;
	for(int i = 0; i < MAX_SCRIPTS; i++) {
		if(m_pScripts[i]) {
			// get the script vm pointer
			SQVM * pVM = m_pScripts[i]->GetVM();

			// Get the stack top
			int iTop = sq_gettop(pVM);

			// Push the root table onto the stack
			sq_pushroottable(pVM);

			// Push the function name onto the stack
			sq_pushstring(pVM, "onRconCommand", -1);

			// Get the closure for the function
			if(SQ_SUCCEEDED(sq_get(pVM, -2))) {
				// Push the root table onto the stack
				sq_pushroottable(pVM);

				// Push the command onto the stack
				sq_pushstring(pVM, command, -1);

				// Push the command arguments onto the stack
				sq_pushstring(pVM, arg, -1);

				// Call the function
				if (!SQ_FAILED(sq_call(pVM, 3, true, true)))
				{
					SQBool result;
					sq_getbool(pVM, sq_gettop(pVM), &result);
					if(result) found = true;
				}

			}

			// Restore the stack top
			sq_settop(pVM, iTop);
		}
	}
	return found;
}
Example #22
0
bool CScripts::onPlayerText(int playerId, const char *text)
{
	bool ret = true;
	for(int i = 0; i < MAX_SCRIPTS; i++) {
		if(m_pScripts[i]) {
			// get the script vm pointer
			SQVM * pVM = m_pScripts[i]->GetVM();

			// Get the stack top
			int iTop = sq_gettop(pVM);

			// Push the root table onto the stack
			sq_pushroottable(pVM);

			// Push the function name onto the stack
			sq_pushstring(pVM, "onPlayerText", -1);

			// Get the closure for the function
			if(SQ_SUCCEEDED(sq_get(pVM, -2))) {
				// Push the root table onto the stack
				sq_pushroottable(pVM);

				// Push the player id onto the stack
				sq_pushinteger(pVM, playerId);

				// Push the text onto the stack
				sq_pushstring(pVM, text, -1);

				// Call the function
				// Call the function
				if (!SQ_FAILED(sq_call(pVM, 3, true, true)))
				{
					SQBool result;
					sq_getbool(pVM, sq_gettop(pVM), &result);
					if(result == false) ret = false;
				}
			}

			// Restore the stack top
			sq_settop(pVM, iTop);
		}
	}
	return ret;
}
Example #23
0
// Font
_MEMBER_FUNCTION_IMPL(GUIFont, constructor)
{
	if(sq_gettop(pVM) < 2)
	{
		sq_pushbool(pVM, false);
		return 1;
	}

	const char * szFont;
	int iSize = 8;
	bool bScaled = false;

	sq_getstring(pVM, 2, &szFont);
	if(sq_gettop(pVM) >= 3)
	{
		sq_getinteger(pVM, 3, &iSize);
		if(iSize < 3 || iSize > 100)
		{
			sq_pushbool(pVM, false);
			return 1;
		}

		if(sq_gettop(pVM) >= 4)
		{
			SQBool sqb;
			sq_getbool(pVM, 4, &sqb);
			bScaled = sqb != 0;
		}
	}


	CEGUI::Font * pFont = g_pClient->GetGUI()->GetFont(szFont, iSize, bScaled);

	if(!pFont || SQ_FAILED(sq_setinstance(pVM, pFont)))
	{
		CLogFile::Printf("Can't create GUIFont.");
		sq_pushbool(pVM, false);
		return 1;
	}

	sq_pushbool(pVM, true);
	return 1;
}
// showTextForPlayer
SQInteger sq_toggleTextForAll(SQVM * pVM)
{
	SQInteger textId;
	SQBool show;

	sq_getbool(pVM, -1, &show);
	sq_getinteger(pVM, -2, &textId);

	if(pNetowkManager->GetTextManager()->GetSlotState(textId))
	{
		pNetowkManager->GetTextManager()->GetAt(textId)->Show(show != 0);

		sq_pushbool(pVM, true);
		return 1;
	}

	sq_pushbool(pVM, false);
	return 1;		
}
Example #25
0
bool read_bool(HSQUIRRELVM vm, const char* name)
{
  sq_pushstring(vm, name, -1);
  if(SQ_FAILED(sq_get(vm, -2))) {
    std::ostringstream msg;
    msg << "Couldn't get bool value for '" << name << "' from table";
    throw scripting::SquirrelError(vm, msg.str());
  }

  SQBool result;
  if(SQ_FAILED(sq_getbool(vm, -1, &result))) {
    std::ostringstream msg;
    msg << "Couldn't get bool value for '" << name << "' from table";
    throw scripting::SquirrelError(vm, msg.str());
  }
  sq_pop(vm, 1);

  return result == SQTrue;
}
Example #26
0
/*
 * Call Squirrel function with one float parameter
 * Returns SQTrue if sq_call succeeds.
 */
SQBool callSqFunction_Bool_Float(HSQUIRRELVM v, const SQChar* nname, const SQChar* name, SQFloat value, SQBool defaultValue) {
	SQBool   result = SQFalse;

	SQInteger top = sq_gettop(v);
	sq_pushroottable(v);
	sq_pushstring(v, nname, -1);
	if (SQ_SUCCEEDED(sq_get(v, -2))) {
		sq_pushstring(v, name, -1);
		if(SQ_SUCCEEDED(sq_get(v, -2))) {
			sq_pushroottable(v);
			sq_pushfloat(v, value);
			if (SQ_SUCCEEDED(sq_call(v, 2, SQTrue, SQTrue))) {
				sq_getbool(v, sq_gettop(v), &result);
			}
		}
	}
	sq_settop(v,top);

	return result;
}
Example #27
0
void CSquirrelVM::Pop(bool& b, bool bDefaultValue)
{
	SQObjectType argType = sq_gettype(m_pVM, m_iStackIndex);
	if (argType == OT_BOOL)
	{
		SQBool sqB;
		sq_getbool(m_pVM, m_iStackIndex++, &sqB);
		b = sqB ? true : false;
		return;
	} else {
		if(argType == OT_NULL)
		{
			b = bDefaultValue;
			m_iStackIndex++;
			return;
		}
	}
	b = false;
	m_iStackIndex++;
}
Example #28
0
bool GameWorld::callVariadricSquirrelFunction(const std::string name,
                                              const std::vector<SQParam> &message) {
  HSQUIRRELVM v = _vm.GetVM();
  sq_pushroottable(v);
  sq_pushstring(v,name.c_str(),-1);
  sq_get(v,-2);
  sq_pushroottable(v);
  for (const auto &p : message) {
    switch (p.type) {
      case OT_NULL:
        sq_pushnull(v);
        break;
      case OT_BOOL:
        sq_pushbool(v, p.as_bool);
        break;
      case OT_INTEGER:
        sq_pushinteger(v, p.as_int);
        break;
      case OT_FLOAT:
        sq_pushfloat(v, p.as_float);
        break;
      case OT_STRING:
        sq_pushstring(v, p.as_string, -1);
        break;
      default:
        std::cout<<"Wrong argument";
    }
  }
  SQBool ret = SQFalse;
  sq_call(v, message.size() + 1, SQTrue, SQTrue);
  SQInteger top = sq_gettop(v);
  if (top == 3) {  // Return value, Closure and Roottable
    if (sq_gettype(v, top) == OT_BOOL) {
      sq_getbool(v, top, &ret);
      std::cout<<"Got bool:"<<ret<<std::endl;
    }
  }
  sq_pop(v, top);
  return ret;
}
Example #29
0
/*
 * Call Squirrel function with multiple float parameters, returns boolean
 * Returns default value if sq_call failed.
 */
SQBool callSqFunction_Bool_Floats(HSQUIRRELVM v, const SQChar* nname, const SQChar* name, SQFloat param[], int count, SQBool defaultValue) {
	SQBool   result = defaultValue;

	SQInteger top = sq_gettop(v);
	sq_pushroottable(v);
	sq_pushstring(v, nname, -1);
	if (SQ_SUCCEEDED(sq_get(v, -2))) {
		sq_pushstring(v, name, -1);
		if(SQ_SUCCEEDED(sq_get(v, -2))) {
			sq_pushroottable(v);
			for (int i = 0; i < count; i++) {
				sq_pushfloat(v, param[i]);
			}
			if (SQ_SUCCEEDED(sq_call(v, count + 1, SQTrue, SQTrue))) {
				sq_getbool(v, sq_gettop(v), &result);
			}
		}
	}
	sq_settop(v,top);

	return result;
}
Example #30
0
// setVehicleLightState( vehicleid, enabled );
SQInteger CSharedVehicleNatives::SetLightState( SQVM * pVM )
{
	// Get the vehicle id
	SQInteger vehicleId;
	sq_getinteger( pVM, -2, &vehicleId );

	// Get the light state
	SQBool bLightState;
	sq_getbool( pVM, -1, &bLightState );

	// Is the vehicle active?
	if( pCore->GetVehicleManager()->IsActive( vehicleId ) )
	{
		// Set the vehicle light state
		pCore->GetVehicleManager()->Get( vehicleId )->SetLightState ( bLightState );

		sq_pushbool ( pVM, true );
		return 1;
	}

	sq_pushbool( pVM, false );
	return 1;
}