MCPcopy Create free account
hub / github.com/alliedmodders/sourcemod / SetEntPropString

Function SetEntPropString

core/smn_entities.cpp:2380–2521  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2378}
2379
2380static cell_t SetEntPropString(IPluginContext *pContext, const cell_t *params)
2381{
2382 CBaseEntity *pEntity;
2383 char *prop;
2384 int offset;
2385 int maxlen;
2386 int bit_count;
2387 edict_t *pEdict;
2388 bool bIsStringIndex;
2389
2390 int element = 0;
2391 if (params[0] >= 5)
2392 {
2393 element = params[5];
2394 }
2395
2396 if (!IndexToAThings(params[1], &pEntity, &pEdict))
2397 {
2398 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
2399 }
2400
2401 switch (params[2])
2402 {
2403 case Prop_Data:
2404 {
2405 datamap_t *pMap;
2406 if ((pMap=CBaseEntity_GetDataDescMap(pEntity)) == NULL)
2407 {
2408 return pContext->ThrowNativeError("Unable to retrieve GetDataDescMap offset");
2409 }
2410 pContext->LocalToString(params[3], &prop);
2411 sm_datatable_info_t info;
2412 if (!g_HL2.FindDataMapInfo(pMap, prop, &info))
2413 {
2414 return pContext->ThrowNativeError("Property \"%s\" not found for entity %d", prop, params[1]);
2415 }
2416
2417 typedescription_t *td = info.prop;
2418 if ((td->fieldType != FIELD_CHARACTER
2419 && td->fieldType != FIELD_STRING
2420 && td->fieldType != FIELD_MODELNAME
2421 && td->fieldType != FIELD_SOUNDNAME)
2422 || (td->fieldType == FIELD_CUSTOM && (td->flags & FTYPEDESC_OUTPUT) != FTYPEDESC_OUTPUT))
2423 {
2424 return pContext->ThrowNativeError("Property \"%s\" is not a valid string", prop);
2425 }
2426
2427 offset = info.actual_offset;
2428
2429 bIsStringIndex = (td->fieldType != FIELD_CHARACTER);
2430
2431 if (element != 0)
2432 {
2433 if (bIsStringIndex)
2434 {
2435 if (element < 0 || element >= td->fieldSize)
2436 {
2437 return pContext->ThrowNativeError("Element %d is out of bounds (Prop %s has %d elements).",

Callers

nothing calls this directly

Calls 8

IndexToAThingsFunction · 0.85
CanSetPropNameFunction · 0.85
ReferenceToIndexMethod · 0.80
FindDataMapInfoMethod · 0.80
ToCStrMethod · 0.80
AllocPooledStringMethod · 0.80
SetEdictStateChangedMethod · 0.80

Tested by

no test coverage detected