int fd_dictfct_Address_encode(void * data, union avp_value * avp_value)
{
	sSS * ss = (sSS *) data;
	uint16_t AddressType = 0;
	size_t	size = 0;
	unsigned char * buf = NULL;
	
	TRACE_ENTRY("%p %p", data, avp_value);
	CHECK_PARAMS( data && avp_value  );
	
	switch (ss->ss_family) {
		case AF_INET:
			{
				/* We are encoding an IP address */
				sSA4 * sin = (sSA4 *)ss;
				
				AddressType = 1;/* see http://www.iana.org/assignments/address-family-numbers/ */
				size = 6;	/* 2 for AddressType + 4 for data */
				
				CHECK_MALLOC(  buf = malloc(size)  );
				
				/* may not work because of alignment: *(uint32_t *)(buf+2) = htonl(sin->sin_addr.s_addr); */
				memcpy(buf + 2, &sin->sin_addr.s_addr, 4);
			}
			break;
				
		case AF_INET6:
			{
				/* We are encoding an IPv6 address */
				sSA6 * sin6 = (sSA6 *)ss;
				
				AddressType = 2;/* see http://www.iana.org/assignments/address-family-numbers/ */
				size = 18;	/* 2 for AddressType + 16 for data */
				
				CHECK_MALLOC(  buf = malloc(size)  );
				
				/* The order is already good here */
				memcpy(buf + 2, &sin6->sin6_addr.s6_addr, 16);
				
			}
			break;
				
		default:
			CHECK_PARAMS( AddressType = 0 );
	}
	
	*(uint16_t *)buf = htons(AddressType);

	avp_value->os.len = size;
	avp_value->os.data = buf;
	
	return 0;
}
Exemplo n.º 2
0
cell AMX_NATIVE_CALL Natives::AttachDynamicAreaToVehicle(AMX *amx, cell *params)
{
	CHECK_PARAMS(2, "AttachDynamicAreaToVehicle");
	boost::unordered_map<int, Item::SharedArea>::iterator a = core->getData()->areas.find(static_cast<int>(params[1]));
	if (a != core->getData()->areas.end())
	{
		if (a->second->type != STREAMER_AREA_TYPE_CIRCLE && a->second->type != STREAMER_AREA_TYPE_SPHERE)
		{
			Utility::logError("AttachDynamicAreaToVehicle: Only circles and spheres may be attached to vehicles");
			return 0;
		}
		if (static_cast<int>(params[2]) != INVALID_GENERIC_ID)
		{
			a->second->attach = boost::intrusive_ptr<Item::Area::Attach>(new Item::Area::Attach);
			a->second->attach->object = boost::make_tuple(INVALID_STREAMER_ID, STREAMER_OBJECT_TYPE_DYNAMIC, INVALID_PLAYER_ID);
			a->second->attach->player = INVALID_GENERIC_ID;
			a->second->attach->vehicle = static_cast<int>(params[2]);
			core->getStreamer()->attachedAreas.insert(a->second);
		}
		else
		{
			if (a->second->attach)
			{
				if (a->second->attach->vehicle != INVALID_GENERIC_ID)
				{
					a->second->attach.reset();
					core->getStreamer()->attachedAreas.erase(a->second);
					core->getGrid()->removeArea(a->second, true);
				}
			}
		}
		return 1;
	}
	return 0;
}
cell AMX_NATIVE_CALL Natives::Streamer_GetCellDistance(AMX *amx, cell *params)
{
	CHECK_PARAMS(1, "Streamer_GetCellDistance");
	float cellDistance = core->getGrid()->getCellDistance();
	Utility::storeFloatInNative(amx, params[1], cellDistance);
	return 1;
}
cell AMX_NATIVE_CALL funcAttachObjectToVehicle ( AMX* a_AmxInterface, cell* a_Params )
{
	if(bScriptDebug) logprintf ( "[Call]-> funcAttachObjectToVehicle()" );

	// DEPRECATED FUNCTION
	logprintf ( "[Script]-> DEPRECATED FUNCTION: AttachObjectToVehicle(). Use Parent/Child Concept Instead (Read Open SA-MP Docs)." );

	CHECK_PARAMS ( 8 );

	uint16_t l_uint16_ObjectIndex = ( uint16_t )a_Params[ 1 ];

	CDeprecatedObject* l_Object = NULL;
	if ( __NetGame->objectPool && ( l_uint16_ObjectIndex < LIMIT_MAX_OBJECT ) && ( l_Object = __NetGame->objectPool->Get ( l_uint16_ObjectIndex ) ) )
	{
		tVector* 
			l_AttachedOffset = new tVector();
			l_AttachedOffset->X = amx_ctof ( a_Params[ 3 ] );
			l_AttachedOffset->Y = amx_ctof ( a_Params[ 4 ] );
			l_AttachedOffset->Z = amx_ctof ( a_Params[ 5 ] );

		tVector* 
			l_AttachedRotation = new tVector();
			l_AttachedRotation->X = amx_ctof ( a_Params[ 6 ] );
			l_AttachedRotation->Y = amx_ctof ( a_Params[ 7 ] );
			l_AttachedRotation->Z = amx_ctof ( a_Params[ 8 ] );

		l_Object->AttachToVehicle ( ( uint16_t )a_Params[ 2 ], l_AttachedOffset, l_AttachedRotation );

		return 1;
	}
	return -1;
}
cell AMX_NATIVE_CALL funcStopPlayerObject ( AMX* a_AmxInterface, cell* a_Params )
{
	if(bScriptDebug) logprintf ( "[Call]-> funcStopPlayerObject()" );

	// DEPRECATED FUNCTION
	//logprintf ( "[Script]-> DEPRECATED FUNCTION: StopPlayerObject(). Use ElementStop() Instead (Read Open SA-MP Docs)." );

	CHECK_PARAMS ( 2 );

	uint16_t l_uint16_PlayerIndex = ( uint16_t )a_Params[ 1 ];
	if ( ( __NetGame->playerPool > 0 ) && ( l_uint16_PlayerIndex < 500 ) && ( __NetGame->playerPool->isCreated[ l_uint16_PlayerIndex ] ) )
	{
		uint16_t l_uint16_ObjectIndex = ( uint16_t )a_Params[ 2 ];

		CDeprecatedObject* l_Object = NULL;
		if ( __NetGame->objectPool && ( l_uint16_ObjectIndex < LIMIT_MAX_OBJECT ) && ( l_Object = __NetGame->objectPool->Get ( l_uint16_PlayerIndex, l_uint16_ObjectIndex ) ) )
		{
			l_Object->Stop();

			RakNet::BitStream 
				l_BitStream;
				l_BitStream.Write ( l_uint16_ObjectIndex );
				l_BitStream.Write ( l_Object->GetPosition()->X );
				l_BitStream.Write ( l_Object->GetPosition()->Y );
				l_BitStream.Write ( l_Object->GetPosition()->Z );

			
			__NetGame->PlayerRPC( RPC_StopObject, &l_BitStream, l_uint16_PlayerIndex, 2 );

			return 1;
		}
	}
	return -1;
}
cell AMX_NATIVE_CALL funcDestroyPlayerObject ( AMX* a_AmxInterface, cell* a_Params )
{
	if(bScriptDebug) logprintf ( "[Call]-> funcDestroyPlayerObject()" );

	// DEPRECATED FUNCTION
	logprintf ( "[Script]-> DEPRECATED FUNCTION: DestroyPlayerObject(). Use ObjectDestroy() or ElementDestroy() Instead (Read Open SA-MP Docs)." );

	CHECK_PARAMS ( 2 );

	if ( ( __NetGame->playerPool > 0 ) && ( a_Params[ 1 ] < 500 ) && ( __NetGame->playerPool->isCreated[ a_Params[ 1 ] ] ) )
	{
		if ( __NetGame->objectPool && ( a_Params[ 2 ] < LIMIT_MAX_OBJECT ) && ( __NetGame->objectPool->Get ( ( uint16_t )a_Params[ 1 ], ( uint16_t )a_Params[ 2 ] ) ) )
		{
			__NetGame->objectPool->Delete ( ( uint16_t )a_Params[ 1 ], ( uint16_t )a_Params[ 2 ] );

			RakNet::BitStream 
				l_BitStream;
				l_BitStream.Write ( ( uint16_t )a_Params[ 2 ] );

			
			__NetGame->PlayerRPC( RPC_DestroyObject, &l_BitStream, ( uint16_t )a_Params[ 1 ], 2 );

			return 1;
		}
	}
	return -1;
}
cell AMX_NATIVE_CALL funcSetObjectRot ( AMX* a_AmxInterface, cell* a_Params )
{
	if(bScriptDebug) logprintf ( "[Call]-> funcSetObjectRot()" );

	// DEPRECATED FUNCTION
	logprintf ( "[Script]-> DEPRECATED FUNCTION: SetObjectRot(). Use ElementSetRotation() Instead (Read Open SA-MP Docs)." );

	CHECK_PARAMS ( 4 );

	uint16_t l_uint16_ObjectIndex = ( uint16_t )a_Params[ 1 ];

	CDeprecatedObject* l_Object = NULL;
	if ( __NetGame->objectPool && ( l_uint16_ObjectIndex < LIMIT_MAX_OBJECT ) && ( l_Object = __NetGame->objectPool->Get ( l_uint16_ObjectIndex ) ) )
	{
		tVector* 
			l_VectorRotation = new tVector();
			l_VectorRotation->X = amx_ctof ( a_Params[ 2 ] );
			l_VectorRotation->Y = amx_ctof ( a_Params[ 3 ] );
			l_VectorRotation->Z = amx_ctof ( a_Params[ 4 ] );

		l_Object->SetRotation ( l_VectorRotation );

		RakNet::BitStream* l_BitStream = l_Object->ComputeBitStream_SetRotation();
		if ( l_BitStream )
		{
			__NetGame->GlobalRPC( RPC_SetObjectRotation, l_BitStream, 0xFFFFu, 2 );

			return 1;
		}
	}
	return -1;
}
cell AMX_NATIVE_CALL Natives::CreateDynamicRaceCP(AMX *amx, cell *params)
{
	CHECK_PARAMS(13, "CreateDynamicRaceCP");
	if (core->getData()->getGlobalMaxItems(STREAMER_TYPE_RACE_CP) == core->getData()->raceCheckpoints.size())
	{
		return 0;
	}
	int raceCheckpointID = Item::RaceCheckpoint::identifier.get();
	Item::SharedRaceCheckpoint raceCheckpoint(new Item::RaceCheckpoint);
	raceCheckpoint->amx = amx;
	raceCheckpoint->raceCheckpointID = raceCheckpointID;
	raceCheckpoint->originalStreamDistance = -1.0f;
	raceCheckpoint->type = static_cast<int>(params[1]);
	raceCheckpoint->position = Eigen::Vector3f(amx_ctof(params[2]), amx_ctof(params[3]), amx_ctof(params[4]));
	raceCheckpoint->next = Eigen::Vector3f(amx_ctof(params[5]), amx_ctof(params[6]), amx_ctof(params[7]));
	raceCheckpoint->size = amx_ctof(params[8]);
	Utility::addToContainer(raceCheckpoint->worlds, static_cast<int>(params[9]));
	Utility::addToContainer(raceCheckpoint->interiors, static_cast<int>(params[10]));
	Utility::addToContainer(raceCheckpoint->players, static_cast<int>(params[11]));
	raceCheckpoint->streamDistance = amx_ctof(params[12]) < STREAMER_STATIC_DISTANCE_CUTOFF ? amx_ctof(params[12]) : amx_ctof(params[12]) * amx_ctof(params[12]);
	Utility::addToContainer(raceCheckpoint->areas, static_cast<int>(params[13]));
	core->getGrid()->addRaceCheckpoint(raceCheckpoint);
	core->getData()->raceCheckpoints.insert(std::make_pair(raceCheckpointID, raceCheckpoint));
	return static_cast<cell>(raceCheckpointID);
}
Exemplo n.º 9
0
cell AMX_NATIVE_CALL Natives::GetDynamicVehicleDamageStatus(AMX *amx, cell *params)
{
	CHECK_PARAMS(5, "GetDynamicVehicleDamageStatus");
	boost::unordered_map<int, Item::SharedVehicle>::iterator v = core->getData()->vehicles.find(static_cast<int>(params[1]));
	if (v != core->getData()->vehicles.end())
	{
		int panels, doors, lights, tires;
		boost::unordered_map<int, int>::iterator i = core->getData()->internalVehicles.find(v->first);
		if (i != core->getData()->internalVehicles.end())
		{
			GetVehicleDamageStatus(i->second, &panels, &doors, &lights, &tires);
		}
		else
		{
			panels = v->second->panels;
			doors = v->second->doors;
			lights = v->second->lights;
			tires = v->second->tires;
		}
		Utility::storeIntegerInNative(amx, params[2], panels);
		Utility::storeIntegerInNative(amx, params[3], doors);
		Utility::storeIntegerInNative(amx, params[4], lights);
		Utility::storeIntegerInNative(amx, params[5], tires);
		return 1;
	}
	return 0;
}
Exemplo n.º 10
0
cell AMX_NATIVE_CALL Natives::GetDynamicVehComponentInSlot(AMX *amx, cell *params)
{
	CHECK_PARAMS(2, "GetDynamicVehComponentInSlot");
	boost::unordered_map<int, Item::SharedVehicle>::iterator v = core->getData()->vehicles.find(static_cast<int>(params[1]));
	int ret = 0;
	if (v != core->getData()->vehicles.end())
	{
		int slot = static_cast<int>(params[2]);
		boost::unordered_map<int, int>::iterator i = core->getData()->internalVehicles.find(v->first);
		if (i != core->getData()->internalVehicles.end())
		{
			ret = GetVehicleComponentInSlot(i->second, slot);
		}
		else
		{
			try
			{
				ret = v->second->carmods.at(slot);
			}
			catch (...)
			{
				ret = 0;
			}
		}
	}
	return ret;
}
Exemplo n.º 11
0
cell AMX_NATIVE_CALL Natives::CreateDynamicVehicle(AMX *amx, cell *params)
{
	CHECK_PARAMS(12, "CreateDynamicVehicle");
	if (core->getData()->getGlobalMaxItems(STREAMER_TYPE_VEHICLE) == core->getData()->vehicles.size())
	{
		return 0;
	}
	int vehicleID = Item::Vehicle::identifier.get();
	Item::SharedVehicle vehicle(new Item::Vehicle);
	vehicle->amx = amx;
	vehicle->vehicleID = vehicleID;
	vehicle->modelID = static_cast<int>(params[1]);

	vehicle->spawn.position = Eigen::Vector3f(amx_ctof(params[2]), amx_ctof(params[3]), amx_ctof(params[4]));
	vehicle->spawn.angle = amx_ctof(params[5]);
	vehicle->spawn.color1 = static_cast<int>(params[6]);
	vehicle->spawn.color2 = static_cast<int>(params[7]);
	vehicle->respawnDelay = static_cast<int>(params[8]) != -1 ? static_cast<int>(params[8]) * 1000 : -1;
	vehicle->spawn.addsiren = static_cast<int>(params[9]) != 0;
	vehicle->position = vehicle->spawn.position;
	vehicle->angle = vehicle->spawn.angle;
	vehicle->color1 = vehicle->spawn.color1;
	vehicle->color2 = vehicle->spawn.color2;
	vehicle->paintjob = 4; // In GTA, you can use 0 - 3 IDs for paintjobs, 4 is invalid
	vehicle->health = 1000.0f;
	vehicle->carmods.clear();
	vehicle->touched = false;
	vehicle->used = false;
	vehicle->spawnedTick = GetTickCount();
	
	// Reset vehicle damage
	vehicle->panels = 0;
	vehicle->doors = 0;
	vehicle->lights = 0;
	vehicle->tires = 0;

	// Set vehicle parameters as unset
	vehicle->params.engine = VEHICLE_PARAMS_UNSET;
	vehicle->params.lights = VEHICLE_PARAMS_UNSET;
	vehicle->params.alarm = VEHICLE_PARAMS_UNSET;
	vehicle->params.doors = VEHICLE_PARAMS_UNSET;
	vehicle->params.bonnet = VEHICLE_PARAMS_UNSET;
	vehicle->params.boot = VEHICLE_PARAMS_UNSET;
	vehicle->params.objective = VEHICLE_PARAMS_UNSET;
	vehicle->params.siren = VEHICLE_PARAMS_UNSET;
	vehicle->params.cardoors.driver = VEHICLE_PARAMS_UNSET;
	vehicle->params.cardoors.passenger = VEHICLE_PARAMS_UNSET;
	vehicle->params.cardoors.backleft = VEHICLE_PARAMS_UNSET;
	vehicle->params.cardoors.backright = VEHICLE_PARAMS_UNSET;
	vehicle->params.carwindows.driver = VEHICLE_PARAMS_UNSET;
	vehicle->params.carwindows.passenger = VEHICLE_PARAMS_UNSET;
	vehicle->params.carwindows.backleft = VEHICLE_PARAMS_UNSET;
	vehicle->params.carwindows.backright = VEHICLE_PARAMS_UNSET;
	vehicle->worldID = static_cast<int>(params[10]);
	vehicle->interior = static_cast<int>(params[11]);
	vehicle->streamDistance = amx_ctof(params[12]) * amx_ctof(params[12]);
	core->getGrid()->addVehicle(vehicle);
	core->getData()->vehicles.insert(std::make_pair(vehicleID, vehicle));
	return static_cast<cell>(vehicleID);
}
Exemplo n.º 12
0
cell AMX_NATIVE_CALL Natives::GetDynamicVehicleRotationQuat(AMX *amx, cell *params)
{
	CHECK_PARAMS(5, "GetDynamicVehicleRotationQuat");
	boost::unordered_map<int, Item::SharedVehicle>::iterator v = core->getData()->vehicles.find(static_cast<int>(params[1]));
	if (v != core->getData()->vehicles.end())
	{
		float w, x, y, z;
		boost::unordered_map<int, int>::iterator i = core->getData()->internalVehicles.find(v->first);
		if (i != core->getData()->internalVehicles.end())
		{
			GetVehicleRotationQuat(i->second, &w, &x, &y, &z);
		}
		else
		{
			w = v->second->qw;
			x = v->second->qx;
			y = v->second->qy;
			z = v->second->qz;
		}
		Utility::storeFloatInNative(amx, params[2], w);
		Utility::storeFloatInNative(amx, params[3], x);
		Utility::storeFloatInNative(amx, params[4], y);
		Utility::storeFloatInNative(amx, params[5], z);
		return 1;
	}
	return 0;
}
Exemplo n.º 13
0
cell AMX_NATIVE_CALL Natives::CreateDynamicMapIcon(AMX *amx, cell *params)
{
	CHECK_PARAMS(11, "CreateDynamicMapIcon");
	if (core->getData()->getGlobalMaxItems(STREAMER_TYPE_MAP_ICON) == core->getData()->mapIcons.size())
	{
		return 0;
	}
	int mapIconID = Item::MapIcon::identifier.get();
	Item::SharedMapIcon mapIcon(new Item::MapIcon);
	mapIcon->amx = amx;
	mapIcon->mapIconID = mapIconID;
	mapIcon->originalStreamDistance = -1.0f;
	mapIcon->position = Eigen::Vector3f(amx_ctof(params[1]), amx_ctof(params[2]), amx_ctof(params[3]));
	mapIcon->type = static_cast<int>(params[4]);
	mapIcon->color = static_cast<int>(params[5]);
	Utility::addToContainer(mapIcon->worlds, static_cast<int>(params[6]));
	Utility::addToContainer(mapIcon->interiors, static_cast<int>(params[7]));
	Utility::addToContainer(mapIcon->players, static_cast<int>(params[8]));
	mapIcon->streamDistance = amx_ctof(params[9]) < STREAMER_STATIC_DISTANCE_CUTOFF ? amx_ctof(params[9]) : amx_ctof(params[9]) * amx_ctof(params[9]);
	mapIcon->style = static_cast<int>(params[10]);
	Utility::addToContainer(mapIcon->areas, static_cast<int>(params[11]));
	core->getGrid()->addMapIcon(mapIcon);
	core->getData()->mapIcons.insert(std::make_pair(mapIconID, mapIcon));
	return static_cast<cell>(mapIconID);
}
Exemplo n.º 14
0
/* Get a slot in the array */
int fd_hook_data_register(
    size_t permsgdata_size,
    void (*permsgdata_init_cb) (struct fd_hook_permsgdata *),
    void (*permsgdata_fini_cb) (struct fd_hook_permsgdata *),
    struct fd_hook_data_hdl **new_handle)
{
    int ret = ENOSPC, idx;
    TRACE_ENTRY("%zd %p %p %p", permsgdata_size, permsgdata_init_cb, permsgdata_fini_cb, new_handle);

    CHECK_PARAMS( permsgdata_size && new_handle );

    CHECK_POSIX( pthread_mutex_lock(&HDH_lock) );
    if (max_index < FD_HOOK_HANDLE_LIMIT) {
        idx = max_index++;
        ret = 0;
    }
    CHECK_POSIX( pthread_mutex_unlock(&HDH_lock) );

    if (ret == 0) {
        HDH_array[idx].pmd_size = permsgdata_size;
        HDH_array[idx].pmd_init_cb = permsgdata_init_cb;
        HDH_array[idx].pmd_fini_cb = permsgdata_fini_cb;
        *new_handle = &HDH_array[idx];
    }

    return ret;
}
Exemplo n.º 15
0
/* Register a new hook callback */
int fd_hook_register (  uint32_t type_mask,
                        void (*fd_hook_cb)(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata),
                        void  *regdata,
                        struct fd_hook_data_hdl *data_hdl,
                        struct fd_hook_hdl ** handler )
{
    struct fd_hook_hdl * newhdl = NULL;
    int i;

    TRACE_ENTRY("%x %p %p %p %p", type_mask, fd_hook_cb, regdata, data_hdl, handler);

    CHECK_PARAMS( fd_hook_cb && handler );

    CHECK_MALLOC( newhdl = malloc(sizeof(struct fd_hook_hdl)) );
    memset(newhdl, 0, sizeof(struct fd_hook_hdl));

    newhdl->fd_hook_cb = fd_hook_cb;
    newhdl->regdata = regdata;
    newhdl->data_hdl = data_hdl;

    for (i=0; i <= HOOK_LAST; i++) {
        fd_list_init(&newhdl->chain[i], newhdl);
        if (type_mask & (1<<i)) {
            CHECK_POSIX( pthread_rwlock_wrlock(&HS_array[i].rwlock) );
            fd_list_insert_before( &HS_array[i].sentinel, &newhdl->chain[i]);
            CHECK_POSIX( pthread_rwlock_unlock(&HS_array[i].rwlock) );
        }
    }

    *handler = newhdl;
    return 0;
}
Exemplo n.º 16
0
cell AMX_NATIVE_CALL Natives::SetDynamicObjectMaterialText(AMX *amx, cell *params)
{
	CHECK_PARAMS(10, "SetDynamicObjectMaterialText");
	boost::unordered_map<int, Item::SharedObject>::iterator o = core->getData()->objects.find(static_cast<int>(params[1]));
	if (o != core->getData()->objects.end())
	{
		int index = static_cast<int>(params[2]);
		o->second->materials[index].text = boost::intrusive_ptr<Item::Object::Material::Text>(new Item::Object::Material::Text);
		o->second->materials[index].text->materialText = Utility::convertNativeStringToString(amx, params[3]);
		o->second->materials[index].text->materialSize = static_cast<int>(params[4]);
		o->second->materials[index].text->fontFace = Utility::convertNativeStringToString(amx, params[5]);
		o->second->materials[index].text->fontSize = static_cast<int>(params[6]);
		o->second->materials[index].text->bold = static_cast<int>(params[7]) != 0;
		o->second->materials[index].text->fontColor = static_cast<int>(params[8]);
		o->second->materials[index].text->backColor = static_cast<int>(params[9]);
		o->second->materials[index].text->textAlignment = static_cast<int>(params[10]);
		for (boost::unordered_map<int, Player>::iterator p = core->getData()->players.begin(); p != core->getData()->players.end(); ++p)
		{
			boost::unordered_map<int, int>::iterator i = p->second.internalObjects.find(o->first);
			if (i != p->second.internalObjects.end())
			{
				SetPlayerObjectMaterialText(p->first, i->second, o->second->materials[index].text->materialText.c_str(), index, o->second->materials[index].text->materialSize, o->second->materials[index].text->fontFace.c_str(), o->second->materials[index].text->fontSize, o->second->materials[index].text->bold, o->second->materials[index].text->fontColor, o->second->materials[index].text->backColor, o->second->materials[index].text->textAlignment);
			}
		}
		o->second->materials[index].main.reset();
		return 1;
	}
	return 0;
}
Exemplo n.º 17
0
cell AMX_NATIVE_CALL funcObjectCreate ( AMX* a_AmxInterface, cell* a_Params )
{
	if ( bScriptDebug ) logprintf ( "[Call]-> funcObjectCreate()" );

	//playerid, model, x, y, z, rx, ry, rz, elementid
	CHECK_PARAMS ( 9 );
	
	tVector* 
		l_VectorPosition = new tVector();
		l_VectorPosition->X = amx_ctof ( a_Params[ 3 ] );
		l_VectorPosition->Y = amx_ctof ( a_Params[ 4 ] );
		l_VectorPosition->Z = amx_ctof ( a_Params[ 5 ] );

	tVector* 
		l_VectorRotation = new tVector();
		l_VectorRotation->X = amx_ctof ( a_Params[ 6 ] );
		l_VectorRotation->Y = amx_ctof ( a_Params[ 7 ] );
		l_VectorRotation->Z = amx_ctof ( a_Params[ 8 ] );

	CObject* l_Object = __ElementFactory->CreateObject ( ( uint16_t )a_Params[ 1 ], ( uint32_t )a_Params[ 2 ], l_VectorPosition, l_VectorRotation, __ElementFactory->GetElementFromIndex ( a_Params[ 9 ] ) );
	if ( l_Object )
	{
		uint32_t l_uint32_ElementIndex = l_Object->GetElementIndex();
		if ( l_uint32_ElementIndex == -1 )
			return -1;
		return l_uint32_ElementIndex;
	}
	return -1;
}
Exemplo n.º 18
0
/* The callback called on new messages */
static int rtereg_out(void * cbdata, struct msg ** pmsg, struct fd_list * candidates)
{
	struct msg * msg = *pmsg;
	struct avp * avp = NULL;
	
	TRACE_ENTRY("%p %p %p", cbdata, msg, candidates);
	
	CHECK_PARAMS(msg && candidates);
	
	/* Check if it is worth processing the message */
	if (FD_IS_LIST_EMPTY(candidates)) {
		return 0;
	}
	
	/* Now search the AVP in the message */
	CHECK_FCT( fd_msg_search_avp ( msg, rtereg_conf.avp, &avp ) );
	if (avp != NULL) {
		struct avp_hdr * ahdr = NULL;
		CHECK_FCT( fd_msg_avp_hdr ( avp, &ahdr ) );
		if (ahdr->avp_value != NULL) {
#ifndef HAVE_REG_STARTEND
			int ret;
		
			/* Lock the buffer */
			CHECK_POSIX( pthread_mutex_lock(&mtx) );
			
			/* Augment the buffer if needed */
			if (ahdr->avp_value->os.len >= bufsz) {
				CHECK_MALLOC_DO( buf = realloc(buf, ahdr->avp_value->os.len + 1), 
					{ pthread_mutex_unlock(&mtx); return ENOMEM; } );
cell AMX_NATIVE_CALL Natives::TogglePlayerDynamicRaceCP(AMX *amx, cell *params)
{
	CHECK_PARAMS(3, "TogglePlayerDynamicRaceCP");
	boost::unordered_map<int, Player>::iterator p = core->getData()->players.find(static_cast<int>(params[1]));
	if (p != core->getData()->players.end())
	{
		boost::unordered_set<int>::iterator d = p->second.disabledRaceCheckpoints.find(static_cast<int>(params[2]));
		if (static_cast<int>(params[3]))
		{
			if (d != p->second.disabledRaceCheckpoints.end())
			{
				p->second.disabledRaceCheckpoints.quick_erase(d);
				return 1;
			}
		}
		else
		{
			if (d == p->second.disabledRaceCheckpoints.end())
			{
				if (p->second.visibleRaceCheckpoint == static_cast<int>(params[2]))
				{
					DisablePlayerRaceCheckpoint(p->first);
					p->second.activeRaceCheckpoint = 0;
					p->second.visibleRaceCheckpoint = 0;
				}
				p->second.disabledRaceCheckpoints.insert(static_cast<int>(params[2]));
				return 1;
			}
		}
	}
	return 0;
}
Exemplo n.º 20
0
cell AMX_NATIVE_CALL Natives::SetDynamicObjectRot(AMX *amx, cell *params)
{
	CHECK_PARAMS(4, "SetDynamicObjectRot");
	boost::unordered_map<int, Item::SharedObject>::iterator o = core->getData()->objects.find(static_cast<int>(params[1]));
	if (o != core->getData()->objects.end())
	{
		o->second->rotation = Eigen::Vector3f(amx_ctof(params[2]), amx_ctof(params[3]), amx_ctof(params[4]));
		for (boost::unordered_map<int, Player>::iterator p = core->getData()->players.begin(); p != core->getData()->players.end(); ++p)
		{
			boost::unordered_map<int, int>::iterator i = p->second.internalObjects.find(o->first);
			if (i != p->second.internalObjects.end())
			{
				SetPlayerObjectRot(p->first, i->second, o->second->rotation[0], o->second->rotation[1], o->second->rotation[2]);
			}
		}
		if (o->second->move)
		{
			if ((o->second->move->rotation.get<0>().maxCoeff() + 1000.0f) > std::numeric_limits<float>::epsilon())
			{
				o->second->move->rotation.get<1>() = o->second->rotation;
				o->second->move->rotation.get<2>() = (o->second->move->rotation.get<0>() - o->second->rotation) / static_cast<float>(o->second->move->duration);
			}
		}
		return 1;
	}
	return 0;
}
cell AMX_NATIVE_CALL funcDestroyObject ( AMX* a_AmxInterface, cell* a_Params )
{
	if(bScriptDebug) logprintf ( "[Call]-> funcDestroyObject()" );

	// DEPRECATED FUNCTION
	logprintf ( "[Script]-> DEPRECATED FUNCTION: DestroyObject(). Use ObjectDestroy() or ElementDestroy() Instead (Read Open SA-MP Docs)." );

	CHECK_PARAMS ( 1 );

	uint16_t l_uint16_ObjectIndex = ( uint16_t )a_Params[ 1 ];

	CDeprecatedObject* l_Object = NULL;
	if ( __NetGame->objectPool && ( l_uint16_ObjectIndex < LIMIT_MAX_OBJECT ) && ( l_Object = __NetGame->objectPool->Get ( l_uint16_ObjectIndex ) ) )
	{
		__NetGame->objectPool->Delete ( l_uint16_ObjectIndex );

		
		RakNet::BitStream 
			l_BitStream;
			l_BitStream.Write ( l_uint16_ObjectIndex );

			__NetGame->GlobalRPC( RPC_DestroyObject, &l_BitStream, 0xFFFFu, 2 );

		return 1;
	}
	return -1;
}
Exemplo n.º 22
0
cell AMX_NATIVE_CALL Natives::CreateDynamicObject(AMX *amx, cell *params)
{
	CHECK_PARAMS(13, "CreateDynamicObject");
	if (core->getData()->getGlobalMaxItems(STREAMER_TYPE_OBJECT) == core->getData()->objects.size())
	{
		return 0;
	}
	int objectID = Item::Object::identifier.get();
	Item::SharedObject object(new Item::Object);
	object->amx = amx;
	object->objectID = objectID;
	object->noCameraCollision = false;
	object->originalStreamDistance = -1.0f;
	object->modelID = static_cast<int>(params[1]);
	object->position = Eigen::Vector3f(amx_ctof(params[2]), amx_ctof(params[3]), amx_ctof(params[4]));
	object->rotation = Eigen::Vector3f(amx_ctof(params[5]), amx_ctof(params[6]), amx_ctof(params[7]));
	Utility::addToContainer(object->worlds, static_cast<int>(params[8]));
	Utility::addToContainer(object->interiors, static_cast<int>(params[9]));
	Utility::addToContainer(object->players, static_cast<int>(params[10]));
	object->streamDistance = amx_ctof(params[11]) < STREAMER_STATIC_DISTANCE_CUTOFF ? amx_ctof(params[11]) : amx_ctof(params[11]) * amx_ctof(params[11]);
	object->drawDistance = amx_ctof(params[12]);
	Utility::addToContainer(object->areas, static_cast<int>(params[13]));
	core->getGrid()->addObject(object);
	core->getData()->objects.insert(std::make_pair(objectID, object));
	return static_cast<cell>(objectID);
}
cell AMX_NATIVE_CALL funcGetPlayerObjectRot ( AMX* a_AmxInterface, cell* a_Params )
{
	if(bScriptDebug) logprintf ( "[Call]-> funcGetPlayerObjectRot()" );

	// DEPRECATED FUNCTION
	logprintf ( "[Script]-> DEPRECATED FUNCTION: GetPlayerObjectRot(). Use ElementGetRotation() Instead (Read Open SA-MP Docs)." );

	CHECK_PARAMS ( 5 );

	uint16_t l_uint16_PlayerIndex = ( uint16_t )a_Params[ 1 ];
	if ( ( __NetGame->playerPool > 0 ) && ( l_uint16_PlayerIndex < 500 ) && ( __NetGame->playerPool->isCreated[ l_uint16_PlayerIndex ] ) )
	{
		uint16_t l_uint16_ObjectIndex = ( uint16_t )a_Params[ 2 ];

		CDeprecatedObject* l_Object = NULL;
		if ( __NetGame->objectPool && ( l_uint16_ObjectIndex < LIMIT_MAX_OBJECT ) && ( l_Object = __NetGame->objectPool->Get ( l_uint16_PlayerIndex, l_uint16_ObjectIndex ) ) )
		{
			tVector* l_VectorRotation = l_Object->GetRotation();

			cell* cptr;
			amx_GetAddr ( a_AmxInterface, a_Params[ 3 ], &cptr);
			*cptr = amx_ftoc ( l_VectorRotation->X );

			amx_GetAddr ( a_AmxInterface, a_Params[ 4 ], &cptr);
			*cptr = amx_ftoc ( l_VectorRotation->Y );

			amx_GetAddr ( a_AmxInterface, a_Params[ 5 ], &cptr);
			*cptr = amx_ftoc ( l_VectorRotation->Z );

			return 1;
		}
	}
	return 0;
}
Exemplo n.º 24
0
cell AMX_NATIVE_CALL Natives::EditDynamicObject(AMX *amx, cell *params)
{
	CHECK_PARAMS(2, "EditDynamicObject");
	boost::unordered_map<int, Player>::iterator p = core->getData()->players.find(static_cast<int>(params[1]));
	if (p != core->getData()->players.end())
	{
		int internalID = INVALID_GENERIC_ID;
		boost::unordered_map<int, int>::iterator i = p->second.internalObjects.find(static_cast<int>(params[2]));
		if (i == p->second.internalObjects.end())
		{
			boost::unordered_map<int, Item::SharedObject>::iterator o = core->getData()->objects.find(static_cast<int>(params[2]));
			if (o != core->getData()->objects.end())
			{
				p->second.position = Eigen::Vector3f(o->second->position[0], o->second->position[1], o->second->position[2]);
				core->getStreamer()->startManualUpdate(p->second, STREAMER_TYPE_OBJECT);
			}
			boost::unordered_map<int, int>::iterator j = p->second.internalObjects.find(static_cast<int>(params[2]));
			if (j != p->second.internalObjects.end())
			{
				internalID = j->second;
			}
		}
		else
		{
			internalID = i->second;
		}
		if (internalID != INVALID_GENERIC_ID)
		{
			EditPlayerObject(p->first, internalID);
			return 1;
		}
	}
	return 0;
}
cell AMX_NATIVE_CALL funcAttachObjectToPlayer ( AMX* a_AmxInterface, cell* a_Params )
{
	if(bScriptDebug) logprintf ( "[Call]-> funcAttachObjectToPlayer()" );

	// DEPRECATED FUNCTION
	logprintf ( "[Script]-> DEPRECATED FUNCTION: AttachObjectToPlayer(). Use Parent/Child Concept Instead (Read Open SA-MP Docs)." );

	CHECK_PARAMS ( 8 );

	uint16_t l_uint16_ObjectIndex = ( uint16_t )a_Params[ 1 ];
	if ( __NetGame->objectPool && ( l_uint16_ObjectIndex < LIMIT_MAX_OBJECT ) && ( __NetGame->objectPool->Get ( l_uint16_ObjectIndex ) ) )
	{
		uint16_t l_uint16_PlayerIndex = ( uint16_t )a_Params[ 2 ];
		if ( ( __NetGame->playerPool > 0 ) && ( l_uint16_PlayerIndex < 500 ) && ( __NetGame->playerPool->isCreated[ l_uint16_PlayerIndex ] ) )
		{
			RakNet::BitStream 
				l_BitStream;
				l_BitStream.Write ( l_uint16_ObjectIndex );
				l_BitStream.Write ( l_uint16_PlayerIndex );
				l_BitStream.Write ( amx_ctof ( a_Params[ 3 ] ) );
				l_BitStream.Write ( amx_ctof ( a_Params[ 4 ] ) );
				l_BitStream.Write ( amx_ctof ( a_Params[ 5 ] ) );
				l_BitStream.Write ( amx_ctof ( a_Params[ 6 ] ) );
				l_BitStream.Write ( amx_ctof ( a_Params[ 7 ] ) );
				l_BitStream.Write ( amx_ctof ( a_Params[ 8 ] ) );

				
			
			__NetGame->AddedPlayersRPC( RPC_AttachObjectToPlayer, &l_BitStream, l_uint16_PlayerIndex, 2 );
			__NetGame->PlayerRPC( RPC_AttachObjectToPlayer, &l_BitStream, l_uint16_PlayerIndex, 2 );
			return 1;
		}
	}
	return -1;
}
Exemplo n.º 26
0
cell AMX_NATIVE_CALL Natives::SetDynamicObjectMaterial(AMX *amx, cell *params)
{
	CHECK_PARAMS(6, "SetDynamicObjectMaterial");
	boost::unordered_map<int, Item::SharedObject>::iterator o = core->getData()->objects.find(static_cast<int>(params[1]));
	if (o != core->getData()->objects.end())
	{
		int index = static_cast<int>(params[2]);
		o->second->materials[index].main = boost::intrusive_ptr<Item::Object::Material::Main>(new Item::Object::Material::Main);
		o->second->materials[index].main->modelID = static_cast<int>(params[3]);
		o->second->materials[index].main->txdFileName = Utility::convertNativeStringToString(amx, params[4]);
		o->second->materials[index].main->textureName = Utility::convertNativeStringToString(amx, params[5]);
		o->second->materials[index].main->materialColor = static_cast<int>(params[6]);
		for (boost::unordered_map<int, Player>::iterator p = core->getData()->players.begin(); p != core->getData()->players.end(); ++p)
		{
			boost::unordered_map<int, int>::iterator i = p->second.internalObjects.find(o->first);
			if (i != p->second.internalObjects.end())
			{
				SetPlayerObjectMaterial(p->first, i->second, index, o->second->materials[index].main->modelID, o->second->materials[index].main->txdFileName.c_str(), o->second->materials[index].main->textureName.c_str(), o->second->materials[index].main->materialColor);
			}
		}
		o->second->materials[index].text.reset();
		return 1;
	}
	return 0;
}
Exemplo n.º 27
0
cell AMX_NATIVE_CALL Natives::Streamer_GetRadiusMultiplier(AMX *amx, cell *params)
{
	CHECK_PARAMS(3, "Streamer_GetRadiusMultiplier");
	float radiusMultiplier = Utility::getRadiusMultiplier(static_cast<std::size_t>(params[1]), static_cast<int>(params[3]));
	Utility::storeFloatInNative(amx, params[2], radiusMultiplier);
	return 1;
}
Exemplo n.º 28
0
cell AMX_NATIVE_CALL Natives::GetDynamicObjectMaterialText(AMX *amx, cell *params)
{
	CHECK_PARAMS(12, "GetDynamicObjectMaterialText");
	boost::unordered_map<int, Item::SharedObject>::iterator o = core->getData()->objects.find(static_cast<int>(params[1]));
	if (o != core->getData()->objects.end())
	{
		boost::unordered_map<int, Item::Object::Material>::iterator m = o->second->materials.find(static_cast<int>(params[2]));
		if (m != o->second->materials.end())
		{
			if (m->second.text)
			{
				Utility::convertStringToNativeString(amx, params[3], params[11], m->second.text->materialText);
				Utility::storeIntegerInNative(amx, params[4], m->second.text->materialSize);
				Utility::convertStringToNativeString(amx, params[5], params[12], m->second.text->fontFace);
				Utility::storeIntegerInNative(amx, params[6], m->second.text->fontSize);
				Utility::storeIntegerInNative(amx, params[7], m->second.text->bold != 0);
				Utility::storeIntegerInNative(amx, params[8], m->second.text->fontColor);
				Utility::storeIntegerInNative(amx, params[9], m->second.text->backColor);
				Utility::storeIntegerInNative(amx, params[10], m->second.text->textAlignment);
				return 1;
			}
		}
	}
	return 0;
}
Exemplo n.º 29
0
cell AMX_NATIVE_CALL Natives::Streamer_SetCellDistance(AMX *amx, cell *params)
{
	CHECK_PARAMS(1, "Streamer_SetCellDistance");
	core->getGrid()->setCellDistance(amx_ctof(params[1]) * amx_ctof(params[1]));
	core->getGrid()->rebuildGrid();
	return 1;
}
Exemplo n.º 30
0
cell AMX_NATIVE_CALL Natives::IsAnyPlayerInAnyDynamicArea(AMX *amx, cell *params)
{
	CHECK_PARAMS(1, "IsAnyPlayerInAnyDynamicArea");
	for (boost::unordered_map<int, Player>::iterator p = core->getData()->players.begin(); p != core->getData()->players.end(); ++p)
	{
		bool recheck = static_cast<int>(params[1]) != 0;
		if (!recheck)
		{
			if (!p->second.internalAreas.empty())
			{
				return 1;
			}
		}
		else
		{
			for (boost::unordered_map<int, Item::SharedArea>::const_iterator a = core->getData()->areas.begin(); a != core->getData()->areas.end(); ++a)
			{
				if (Utility::isPointInArea(p->second.position, a->second))
				{
					return 1;
				}
			}
		}
	}
	return 0;
}