I'm working on a plugin at the moment and I've been familiarizing myself well as I can with Sourcemod/Sourcepawn. I've just tried to add a rather complicated feature to my plugin that handles an array, uses multiple loops, and uses a ton of conditionals. I thought I did everything right, but when I went to compile, it did this:
The local compiler threw this error:
Here's the block of code I've added since the last time I compiled successfully. It's for a half-satirical Sonic gamemode that handles 7 "Chaos Emeralds" that change hands when somebody gets a kill, which handles 2 global variables called steEmeralds[7], which is supposed to be an array of 7 integers (one for each emerald), and steEmScatter, which is an integer used to handle the number of "Chaos Emeralds" that are not currently "held."
Spoiler
Code:
//Shadow the Edgehog
//Player spawn function sets speed, health, and gives weapon. Also includes conditions to pick up an emerald that's scattered around.
public void steMode(Handle eventvar4)
{
int steClient = GetClientOfUserId(GetEventInt(eventvar4, "userid"));
int steWepSlot = GetPlayerWeaponSlot(steClient, 1);
SetEntPropFloat(steClient, Prop_Data, "m_flLaggedMovementValue", 1.6);
if (IsValidEntity(steWepSlot))
{
RemovePlayerItem(steClient, steWepSlot);
}
GivePlayerItem(steClient, "weapon_mp5navy");
if (steEmScatter > 0)
{
int steEmSwitch = 0;
int steEmKey = 0;
while (steEmSwitch == 0 && steEmKey < 7)
{
if (steEmeralds[steEmKey] == 0)
{
steEmeralds[steEmKey] = steClient;
steEmSwitch = 1;
}
steEmKey++;
}
steEmScatter -= 1;
PrintToChat(steClient, "You found a Chaos Emerald laying around!");
}
PrintToChatAll("There are %i Chaos Emeralds scattered around the map!", steEmScatter);
}
//Player death function handles changing hands of Chaos Emeralds.
public void steMode2(Handle eventvar4a)
{
int steKiller = GetClientOfUserId(GetEventInt(eventvar4a, "attacker"));
int steVictim = GetClientOfUserId(GetEventInt(eventvar4a, "userid"));
GetClientName(steKiller, steKillName, sizeof(steKillName));
GetClientName(steVictim, steVicName, sizeof(steVicName));
int steEmHave1 = FindValueInArray(steEmeralds, steKiller);
int steEmNum1 = 0;
if (steEmHave1 != -1)
{
for (int steNum = 0; steNum <= 6; steNum++)
{
if (steEmeralds[steNum] == steKiller)
{
steEmNum1++;
}
}
}
int steEmHave2 = FindValueInArray(steEmeralds, steVictim);
int steEmNum2 = 0;
if (steEmHave2 != -1)
{
for (int steNum2 = 0; steNum2 <= 6; steNum2++)
{
if (steEmeralds[steNum2] == steVictim)
{
steEmNum2++;
}
}
}
if (steEmNum2 < 6)
{
for (int steNum3 = 1; steNum3 <= steEmNum2; steNum3++)
{
steEmeralds[steEmHave2] = steKiller;
steEmHave2 = FindValueInArray(steEmeralds, steVictim);
}
}
else if (steEmNum2 == 6)
{
for {int steNum5 = 0; steNum5 <= 6; steNum5++)
{
if (steEmeralds[steNum5] == steVictim)
{
steEmeralds[steNum5] = 0;
}
}
steEmScatter += steEmNum2;
PrintToChatAll("%s died and his Chaos Emeralds scattered around the map!", steVicName);
}
else if (steEmNum2 == 7)
{
steEmeralds[] = {0, 0, 0, 0, 0, 0, 0};
steEmScatter += steEmNum2;
PrintToChatAll("%s killed %s! The Edgelord has fallen and his Chaos Emeralds scattered around the map.", steKillName, steVicName);
}
if (steEmNum2 == 0)
{
PrintToChat(steKiller, "You got a kill, but %s didn't have any emeralds! You still have %i though.", steVicName, steEmNum1);
}
else if (steEmNum2 == 1)
{
PrintToChatAll("%s stole 1 Chaos Emerald from %s!", steKillName, steVicName);
}
else if (steEmNum > 1)
{
PrintToChatAll("%s stole %i Chaos Emeralds from %s!", steKillName, steEmNum2, steVicName");
}
int steEmNum3 = steEmNum 1 + steEmNum2;
if (steEmScatter != 0 && steEmNum3 < 6)
{
steEmNum3 += 1;
PrintToChat(steKiller, "You found a Chaos Emerald laying around!");
steEmScatter -= 1;
}
if (steEmNum3 == 0)
{
PrintToChat(steKiller, "You still have 0 Chaos Emeralds! Keep killing!");
}
else if (steEmNum3 == 1)
{
PrintToChat(steKiller, "You have 1 Chaos Emerald! Keep killing!");
}
else if (steEmNum3 > 1 && steEmNum3 < 7)
{
PrintToChat(steKiller, "You have %i Chaos Emeralds! You're getting closer to ultimate power!", steEmNum3);
if (steEmNum3 == 6 && steEmScatter == 0)
{
for (int steNum4 = 0; steNum4 <= 6; steNum4++)
{
if (steEmeralds[steNum4] != steKiller)
{
int steNextVictim = steEmeralds[steNum4];
}
}
GetClientName(steNextVictim, steNxVicName, sizeof(steNxVicName));
PrintToChat(steKiller, "%s has the last emerald! Kill him and become the Edgelord!", steNxVicName);
}
else if (steEmNum3 == 6 && steEmScatter > 0)
{
PrintToChat(steKiller, "You're close, but nobody has found the last emerald!");
}
}
else if (steEmNum3 == 7 && steEmNum3 != steEmNum1)
{
PrintToChatAll("%s says, 'I will destroy all who stand in my way!' He has gained all 7 emeralds and become the Edgelord!", steKillName);
SetEntityHealth(steKiller, 1500);
SetEntPropFloat(steKiller, Prop_Data, "m_flLaggedMovementValue", 2.0);
}
else if (steEmNum3 == 7 && steEmNum3 == steEmNum1)
{
PrintToChat(steKiller, "Yes! Slaughter them all!");
}
}
Edit: Oh! I should clarify, steMode is called on the player_spawn event, and steMode2 is called on the player_death event.
Any help or suggestions that could get this to compile correctly would be appreciated.
Thank you.
Last edited by Wanderlost; 06-16-2018 at 10:43.
Reason: Found and fixed more errors.
It's hard to say since you don't provide the full source, but there's probably at least a bug in the compiler. The end result is it stops instead of reporting any of the errors in your code.
I think this is the problem that trips up the compiler: for {int steNum5 = 0; steNum5 <= 6; steNum5++)
You have an open brace instead of open parenthesis.
There are multiple other mistakes.
steEmeralds[] = {0, 0, 0, 0, 0, 0, 0}; should not have brackets, assuming steEmeralds is something like int steEmeralds[7].
You can't use FindValueInArray on a basic array, only ArrayLists.
else if (steEmNum > 1) should probably be steEmNum1 (or 2).
PrintToChatAll("%s stole %i Chaos Emeralds from %s!", steKillName, steEmNum2, steVicName"); has an extra closing double quote. The condition it's inside is the bullet immediately previous, so make sure you're printing the right number as well.
int steEmNum3 = steEmNum 1 + steEmNum2; should probably be steNum1.
int steNextVictim = steEmeralds[steNum4]; should probably have steNextVictim declared above in a higher scope.
Some of your strings don't seem to be declared. They're probably missing since it doesn't make much sense to declare them elsewhere.
Wow! Thanks for that. I guess I was sloppier writing this than I thought. I'll use these notes to revise my code and let you know if this fixes it. I appreciate the help.
Yeah, reviewing the code with these notes got me to a place where I was able to operate the compiler properly and got it to function. Unfortunately, the gamemode was fundamentally flawed for team death match, but I still appreciate the help, and I archived the functioning code for potential later use.
That being said, you did me a big favor. Thank you again.