Both methods for arrays are very usefull, i prefer yours though becous its logic is not specifically sourcemod related and it could benefit me more in the future for other projects idk .
Actually, a dynamic container may benefit you more Valve uses dynamic containers all over the place (see CUtlVector). However, I find that static containers are easier to use in SourcePawn. Were I coding this plugin in c++, I would have used std::vector instead. Dynamic arrays, after optimization, can be fast-- with O(1) pushing back and O(log n) popping back. In SourcePawn however, there seems to be an overhead to it, so I always use static containers unless I really need dynamic ones.
Quote:
Originally Posted by striker07
an invalid edict id would not be a problem in all these stocks becous all possible entities are cached into the array? it would only retrieve a false result?
Because the entire array is initialized to zero (see the 'new' declaration in Pawn), we can be sure that the entire array at the start of the map is initialized to NO_ACTIVATOR (defined as zero). The stocks would then just return false.
Note that all the additions I have made are untested-- I wrote it on my jailbroken Ubuntu tablet
I do get a problem with making the entity, in both cs:s and cs:go.
for createentitybyname, can't i choose my own classname? do i have to choose one from this list?: https://developer.valvesoftware.com/...#Item_entities
This is my error message in console:
Code:
L 02/17/2013 - 20:47:25: "Nick<4><BOT><CT>" killed "Troy<6><BOT><TERRORIST>" with "usp" (headshot)
Attempted to create unknown entity type my_entity!
L 02/17/2013 - 20:47:25: [SM] Native "TeleportEntity" reported: NULL not allowed
L 02/17/2013 - 20:47:25: [SM] Displaying call stack trace for plugin "DDamagePerk2.smx":
L 02/17/2013 - 20:47:25: [SM] [0] Line 116, C:\Program Files (x86)\Sourcemod\SourcePawn\temp397.sp::CreateSomeEntity()
L 02/17/2013 - 20:47:25: [SM] [1] Line 108, C:\Program Files (x86)\Sourcemod\SourcePawn\temp397.sp::Event_PlayerDeath()
tryed both SetEntPropVector and teleportentity, it gives the same result
// =============================================================== // - GLOBALS - // =============================================================== new LaserSprite, Halosprite; enum TOUCH_DATA { ACTIVATOR, // (integer) who/what did the touching? TOUCH_FLAG // (bool) was this entity touched by a client? } new g_Touch[MAX_EDICTS+1][TOUCH_DATA];
// =============================================================== // - STOCK FUNCTIONS - // =============================================================== // These are for you to use (if you need them). // Resets all elements of the array stock ResetNPCVars(entity) { g_Touch[entity][TOUCH_DATA:ACTIVATOR] = NO_ACTIVATOR; g_Touch[entity][TOUCH_DATA:TOUCH_FLAG] = FALSE; } // Returns true if an entity was touched by a specifik client stock bool:WasNPCTouchedByClient(entity, client) { return (g_Touch[entity][TOUCH_DATA:ACTIVATOR] == client); } // Returns the last activator to touch the entity stock GetNPCActivator(entity) { return g_Touch[entity][TOUCH_DATA:ACTIVATOR]; } // Returns true if the NPC was touched by a client at all in all of its touches stock WasNPCTouchedAtAll(entity) { return (g_Touch[entity][TOUCH_DATA:ACTIVATOR] || g_Touch[entity][TOUCH_DATA:TOUCH_FLAG]); } // Sets entity touch data (see usage under Plugin Code section) stock SetNPCTouchVars(entity, TOUCH_DATA:data, value) { g_Touch[entity][data] = value; }
if (IsValidEntity(entity)) { // Remove edict when touched HookSingleEntityOutput(entity, "OnStartTouch", Entity_OnStartTouch);
// Change rendermode in 20.0 seconds CreateTimer(20.0, Timer_SetRenderGlow, entity);
SetVariantString("rotate"); AcceptEntityInput(entity, "SetAnimation"); IgniteEntity(entity, FLAME_TIME, true); } } public Entity_OnStartTouch(const String:output[], caller, activator, Float:delay) { // Something touched this entity if (caller > 0) SetNPCTouchVars(caller, ACTIVATOR, activator); // caller was touched by an ACTIVATOR of index: activator
// If you're going to use RemoveEdict, then you need to make sure that the edict is valid. // In this case, the edict will be valid, but get into the habit of checking if an edict is valid before removing it. // // Secondly, sometimes the activator won't always be a player. Try throwing a prop_physics onto your NPC and see // what happens. This callback will be fired, but IsPlayerAlive() will receive an index that does not belong // to a player. Therefore, you need to check that the index belongs to a player.
if (activator >= 1 && activator <= MaxClients) { if (IsPlayerAlive(activator) && IsValidEdict(caller)) { // This entity was touched by a client (alive player) SetNPCTouchVars(caller, TOUCH_FLAG, TRUE);
RemoveEdict(caller); } } } public Action:Timer_SetRenderGlow(Handle:timer, any:entity) { if (IsValidEntity(entity)) { SetEntityRenderMode(entity, RENDER_GLOW); SetEntityRenderFx(entity, RENDERFX_PULSE_FAST_WIDER);
// Remove this entity 10 seconds from now (i.e. 30.0 after spawn) CreateTimer(10.0, Timer_RemoveEntity, entity); } } public Action:Timer_RemoveEntity(Handle:timer, any:entity) { if (IsValidEdict(entity)) RemoveEdict(entity); } public Event_RoundEnd(Handle:event, String:name[], bool:dontBroadcast) { // Reset variables after the round is over for (new i = 0; i < MAX_EDICTS; i++) ResetNPCVars(i); } public Plugin:MyInfo = { name = "CBase entity?", author = "Sky-High", description = "My first SM entity plugin", version = "1.0", url = "** AM Spam-Blocker V3.6 **" };
__________________
Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]
changing that to prop_static, prop_detail doesnt work neighter, same errors and changing it to monster_generic crashes the server.(csgo)
If i place the teleportentity command in the block of a succesful spawn then the next line is replaced in the error log,
it said
[SM] Native "SetEntityModel" reported: NULL not allowed
EDIT:
nvm, after some experimenting this finally shows up: Attempting to precache model, but model name is NULL
my model isnt compiled correctly i think
EDIT 2:
Finally fixed the model now, but now it cant spawn becous the entity id created is wrong so i made an extra check to be sure.
-> Code:
L 02/18/2013 - 0299: "Henry<27><BOT><TERRORIST>" [-62 372 2] killed "Keith<29><BOT><CT>" [468 90 69] with "xm1014"
Attempted to create unknown entity type prop_static!
DEBUG ----> Invalid entity index -1
L 02/18/2013 - 029:43: "Bill<21><BOT><CT>" [
code: spawn ent block
PHP Code:
stock CreateSomeEntity(Float:Origin[3]) { new entity = CreateEntityByName("prop_static");
if (!IsValidEntity(entity)) { PrintToServer("DEBUG ----> Invalid entity index %i", entity); return Plugin_Handled; }
TeleportEntity(entity, Origin, NULL_VECTOR, NULL_VECTOR); //SetEntPropVector(entity, Prop_Data, "m_vecOrigin", Origin); // Causes errors ingame(only do if ent is inworld) SetEntityModel(entity, "models/props/perk1c/perk1c.mdl"); SetEntityRenderMode(entity, RENDER_TRANSCOLOR); SetEntityRenderFx(entity, RENDERFX_PULSE_SLOW); SetEntityRenderColor(entity, 31, 191, 36, 160);
// * Rest of the code is unchanged from prev post
return Plugin_Handled; }
__________________
Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]
prop_dynamic crashes the server for both css and csgo.
changed the code abit again (removed plugin handled) and added a diffrent model but the game also sais its a bad model:
(with prop_static)
Code:
L 02/18/2013 - 03:40:22: ".:}O$G{:. ,.SkyHigH,<2><STEAM_1:1:4926290><TERRORIST>" [495 1323 32] killed "Eric<12><BOT><CT>" [657 1032 96] with "glock" (headshot)
Attempted to create unknown entity type prop_static!
DEBUG ----> Invalid entity index -1
L 02/18/2013 - 03:40:23: "Finn<17><BOT><TERRORIST>" threw hegrenade [-922 745 -181]
Attempting to precache model, but model name is NULL
L 02/18/2013 - 03:40:28: "Eric<12><BOT><CT>" purchased "m4a1"
csgo error with prop_dynamic:
Spoiler
right before a player is going to die the server crashes
Code:
Attempting to precache model, but model name is NULL
L 02/18/2013 - 03:47:47: "Vinny<32><BOT><CT>" purchased "m4a1"
L 02/18/2013 - 03:47:47: "Zane<36><BOT><CT>" purchased "vesthelm"
L 02/18/2013 - 03:47:47: "Zane<36><BOT><CT>" purchased "hegrenade"
L 02/18/2013 - 03:47:47: "John<33><BOT><TERRORIST>" purchased "ak47"
L 02/18/2013 - 03:47:47: "Adrian<37><BOT><TERRORIST>" purchased "vesthelm"
L 02/18/2013 - 03:47:47: "Adrian<37><BOT><TERRORIST>" purchased "p250"
L 02/18/2013 - 03:47:47: "GUploading dump (in-process) [proxy '']
/tmp/dumps/crash_20130218034804_1.dmp
success = yes
response: CrashID=bp-ce8a358d-bac3-4194-aed0-795ed2130217
./vg_run: line 432: 14073 Segmentation fault $HL_CMD
cs:s with prop_dynamic:
Spoiler
Same result as in csgo but no error about the model
Code:
L 02/18/2013 - 03:57:04: "Connor<5><BOT><CT>" attacked "Ron<4><BOT><TERRORIST>" with "usp" (damage "21") (damage_armor "0") (health "79") (armor "0") (hitgroup "right arm")
L 02/18/2013 - 03:57:04: "Connor<5><BOT><CT>" attacked "Dustin<3><BOT><TERRORIST>" with "usp" (damage "27") (damage_armor "0") (health "53") (armor "0") (hitgroup "stomach")
L 02/18/2013 - 03:57:04: "Connor<5><BOT><CT>" attacked "Dustin<3><BOT><TERRORIST>" with "usp" (damage "16") (damage_armor "0") (Uploading dump (in-process) [proxy '']
/tmp/dumps/crash_20130218035705_1.dmp
./vg_run: line 410: 16595 Segmentation fault $HL_CMD
tested alot of things out and none work been looking at it so long and just can't find the problem
EDIT:
Quote:
Originally Posted by ajr1234
PHP Code:
CreateSomeEntity(Float:Origin[3]) { new entity = CreateEntityByName("prop_dynamic");
...
// add before dispatchspawn() function DispatchKeyValue(entity, "Solid", "6");
// move the following code to after dispatchspawn() TeleportEntity(entity, Origin, NULL_VECTOR, NULL_VECTOR); SetEntityModel(entity, "models/props/perk1c/perk1c.mdl"); SetEntityRenderMode(entity, RENDER_TRANSCOLOR); SetEntityRenderFx(entity, RENDERFX_PULSE_SLOW); SetEntityRenderColor(entity, 31, 191, 36, 160);
...
// no need to "return" anything (void) }
server still crashes, gonna play around some more today try some new diffrent things
__________________
Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]
Ok, made a third attempt, again it failed :s. really need some help here.
Just tested the BETA version and now aprox 3.5 seconds after a player died the server crashes but shows these logs now:
console logs
Code:
Attempting to precache model, but model name is NULL
L 02/18/2013 - 12:40:23: "Mike<4><BOT><CT>" purchased "m4a1"
L 02/18/2013 - 12:40:25: World triggered "Round_Start"
L 02/18/2013 - 12:40:31: "Yahn<5><BOT><TERRORIST>" threw hegrenade [-390 891 -27]
L 02/18/2013 - 12:40:31: "Dean<3><BOT><CT>" threw hegrenade [-416 1535 -124]
AddMultiDamage: g_MultiDamage.GetDamageForce() == vec3_origin
L 02/18/2013 - 12:40:41: ".:}O$G{:. ,.SkyHigH,<2><STEAM_1:1:4926290><TERRORIST>" [-286 1397 -28] killed "Jon<11><BOT><CT>" [-367 1626 -62] with "glock" (headshot)
prop prop_dynamic at 0 0 0 missing modelname
L 02/18/2013 - 12:40:46: ".:}O$G{:. ,.SkyHigH,<2><STEAM_1:1:4926290><TERRORIST>" triggered "Got_The_Bomb"
L 02/18/2013 - 12:40:51: World triggered "Round_Start"
L 02/18/2013 - 12:41:28: ".:}O$G{:. ,.SkyHigH,<2><STEAM_1:1:4926290><TERRORIST>" triggered "Planted_The_Bomb"
L 02/18/2013 - 12:41:34: "Jon<11><BOT><CT>" [-272 1492 -124] killed "Ian<10><BOT><TERRORIST>" [-435 1693 -63] with "hkp2000" (headshot)
prop prop_dynamic at 0 0 0 missing modelname
L 02/18/2013 - 12:41:38: ".:}O$G{:. ,.SkyHigH,<2><STEAM_1:1:4926290><TERRORIST>" [-483 1991 -126] killed "Jon<11><BOT><CT>" [-385 1493 -60] with "glock"
prop prop_dynamic at 0 0 0 missing modelname
L 02/18/2013 - 12:41:42: "Keith<7><BOT><TERRORIST>" [-538 1705 -120] killed "Greg<6><BOT><CT>" [-276 1515 -61] with "glock" (headshot)
L 02/18/2013 - 12:41:42: "Ian<10><BOT><TERRORIST>" assisted killing "Greg<6><BOT><CT>"
prop prop_dynamic at 0 0 0 missing modelname
L 02/18/2013 - 12:42:04: Team "TERRORIST" triggered "SFUI_Notice_Target_Bombed" (CT "0") (T "1")
L 02/18/2013 - 12:42:04: Team "CT" scored "0" with "5" players
L 02/18/2013 - 12:42:04: Team "TERRORIST" scored "1" with "5" players
L 02/18/2013 - 12:42:04: World triggered "Round_End"
L 02/18/2013 - 12:42:08: ".:}O$G{:. ,.SkyHigH,<2><STEAM_1:1:4926290><TERRORIST>" [-149 2080 -123] killed "Irving<9><BOT><CT>" [304 2133 -63] with "glock" (headshot)
L 02/18/2013 - 12:42:08: "Keith<7><BOT><TERRORISTUploading dump (in-process) [proxy '']
/tmp/dumps/crash_20130218124212_1.dmp
success = yes
response: CrashID=bp-5ee94266-eda0-4c0a-8238-969732130218
./vg_run: line 432: 20549 Segmentation fault $HL_CMD
keep running into "prop at 0 0 0 missing modelname" when i try other models
Update:
Made a beta version with debug information, i got it to run and my server doesnt crash
but the model isnt being shown correctly or teleported correctly not sure it never gets touched neighter.
Also the visual effects are not visible :s.
Console logs:
Code:
L 02/18/2013 - 15:06:26: "Andy<7><BOT><TERRORIST>" killed "Matt<3><BOT><CT>" with "galil"
DispatchSpawn succes for perk 60, sending data..
Special effects for perk 60 done
Perk 60 teleported to x: -918.817 , y: 1396.754 , z: -47.968
Setting CBaseEntity to non-brush model models/player/lomme/lomme1.mdl
perk 60 is assigned a model and render
Why is the entity id in spawnsucces suddenly not valid anymore, what could cause that?
__________________
Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]