Compiles, but doesnt work ingame
#1

I'm trying to script a code to buy weapons in game. It compiles, there's a couple warnings. But once i get in game the commands doesn't work. Here is my code

public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/help", cmdtext, true, 5) == 0)
{
SendClientMessage(playerid,0x33CCFFAA, " -~Weapons For Sale~-");
SendClientMessage(playerid,0x33CCFFAA, "[Hint] Use /buy [name] to buy a weapon");
SendClientMessage(playerid,0x33CCFFAA, "Pistols- 9mm($450), S9mm($500), Deagle($1500)");
SendClientMessage(playerid,0x33CCFFAA, "Shotguns- Shotgun($800), CShotgun($2100), Sawnoff($1000)");
SendClientMessage(playerid,0x33CCFFAA, "Automatics- MicroSMG($800), SMG($1200), Tec9($900)");
SendClientMessage(playerid,0x33CCFFAA, "Rifles- CountryRifle($700), Sniper($1100),");
SendClientMessage(playerid,0x33CCFFAA, "AssaultRifles- AK47($1800), M4($2500),");
SendClientMessage(playerid,0x33CCFFAA, "Thrown- Grenade($3500), Molotov($3500), SatchelCharge($4000");
}
return 1;
return 0;
if (strcmp("/buy 9mm", cmdtext, true, == 0)
{
GivePlayerWeapon(playerid, 22, 60);
SendClientMessage(playerid,0x33AA33AA,"You have bought a 9mm for $450!");
GivePlayerMoney(playerid, -450);
}
return 1;
if (strcmp("/buy S9mm", cmdtext, true, 9) == 0)
{
GivePlayerWeapon(playerid, 23, 45);
SendClientMessage(playerid,0x33AA33AA,"You have bought a Silenced 9mm for $500!");
GivePlayerMoney(playerid, -500);
}
return 1;
if (strcmp("/buy Deagle", cmdtext, true, 11) == 0)
{
GivePlayerWeapon(playerid, 24, 30);
SendClientMessage(playerid,0x33AA33AA,"You have bought a Desert Eagle for $1500!");
GivePlayerMoney(playerid, -1500);
}
return 1;
if (strcmp("/buy Shotgun", cmdtext, true, 12) == 0)
{
GivePlayerWeapon(playerid, 25, 25);
SendClientMessage(playerid,0x33AA33AA,"You have bought a Shotgun for $800!");
GivePlayerMoney(playerid, -800);
}
return 1;
if (strcmp("/buy CShotgun", cmdtext, true, 13) == 0)
{
GivePlayerWeapon(playerid, 27, 35);
SendClientMessage(playerid,0x33AA33AA,"You have bought a CShotgun for $2100!");
GivePlayerMoney(playerid, -2100);
}
return 1;
if (strcmp("/buy Sawnoff", cmdtext, true, 12) == 0)
{
GivePlayerWeapon(playerid, 26, 20);
SendClientMessage(playerid,0x33AA33AA,"You have bought a Sawnoff for $1000!");
GivePlayerMoney(playerid, -1000);
}
return 1;
if (strcmp("/buy MicroSMG", cmdtext, true, 13) == 0)
{
GivePlayerWeapon(playerid, 28, 90);
SendClientMessage(playerid,0x33AA33AA,"You have bought a MicroSMG for $800!");
GivePlayerMoney(playerid, -800);
}
return 1;
if (strcmp("/buy SMG", cmdtext, true, == 0)
{
GivePlayerWeapon(playerid, 29, 90);
SendClientMessage(playerid,0x33AA33AA,"You have bought a SMG for $1200!");
GivePlayerMoney(playerid, -1200);
}
return 1;
if (strcmp("/buy Tec9", cmdtext, true, 9) == 0)
{
GivePlayerWeapon(playerid, 32, 90);
SendClientMessage(playerid,0x33AA33AA,"You have bought a Tec9 for $900!");
GivePlayerMoney(playerid, -900);
}
return 1;
if (strcmp("/buy CountryRifle", cmdtext, true, 17) == 0)
{
GivePlayerWeapon(playerid, 33, 20);
SendClientMessage(playerid,0x33AA33AA,"You have bought a Country Rifle for $700!");
GivePlayerMoney(playerid, -700);
}
return 1;
if (strcmp("/buy Sniper", cmdtext, true, 11) == 0)
{
GivePlayerWeapon(playerid, 34, 20);
SendClientMessage(playerid,0x33AA33AA,"You have bought a Sniper for $1100!");
GivePlayerMoney(playerid, -1100);
}
return 1;
if (strcmp("/buy AK47", cmdtext, true, 9) == 0)
{
GivePlayerWeapon(playerid, 30, 120);
SendClientMessage(playerid,0x33AA33AA,"You have bought a AK47 for $1800!");
GivePlayerMoney(playerid, -1800);
}
return 1;
if (strcmp("/buy M4", cmdtext, true, 7) == 0)
{
GivePlayerWeapon(playerid, 31, 120);
SendClientMessage(playerid,0x33AA33AA,"You have bought a M4 for $2500!");
GivePlayerMoney(playerid, -2500);
}
return 1;
if (strcmp("/buy Grenade", cmdtext, true, 12) == 0)
{
GivePlayerWeapon(playerid, 16, 3);
SendClientMessage(playerid,0x33AA33AA,"You have bought a Grenade for $3500!");
GivePlayerMoney(playerid, -3500);
}
return 1;
if (strcmp("/buy Molotov", cmdtext, true, 12) == 0)
{
GivePlayerWeapon(playerid, 18, 3);
SendClientMessage(playerid,0x33AA33AA,"You have bought a Molotov for $3500!");
GivePlayerMoney(playerid, -3500);
}
return 1;
if (strcmp("/buy SatchelCharge", cmdtext, true, 1 == 0)
{
GivePlayerWeapon(playerid, 39, 2);
SendClientMessage(playerid,0x33AA33AA,"You have bought a SatchelCharge for $4000!");
GivePlayerMoney(playerid, -4000);
}
return 1;
return 0;
}





And the message after compiling

C:\Users\lad\Desktop\samp03asvr_R2_win32\gamemodes \SnipeMadness.pwn(239) : warning 217: loose indentation
C:\Users\lad\Desktop\samp03asvr_R2_win32\gamemodes \SnipeMadness.pwn(240) : warning 225: unreachable code
C:\Users\lad\Desktop\samp03asvr_R2_win32\gamemodes \SnipeMadness.pwn(241) : warning 225: unreachable code
C:\Users\lad\Desktop\samp03asvr_R2_win32\gamemodes \SnipeMadness.pwn(24 : warning 225: unreachable code
C:\Users\lad\Desktop\samp03asvr_R2_win32\gamemodes \SnipeMadness.pwn(255) : warning 225: unreachable code
C:\Users\lad\Desktop\samp03asvr_R2_win32\gamemodes \SnipeMadness.pwn(262) : warning 225: unreachable code
C:\Users\lad\Desktop\samp03asvr_R2_win32\gamemodes \SnipeMadness.pwn(269) : warning 225: unreachable code
C:\Users\lad\Desktop\samp03asvr_R2_win32\gamemodes \SnipeMadness.pwn(276) : warning 225: unreachable code
C:\Users\lad\Desktop\samp03asvr_R2_win32\gamemodes \SnipeMadness.pwn(283) : warning 225: unreachable code
C:\Users\lad\Desktop\samp03asvr_R2_win32\gamemodes \SnipeMadness.pwn(290) : warning 225: unreachable code
C:\Users\lad\Desktop\samp03asvr_R2_win32\gamemodes \SnipeMadness.pwn(297) : warning 225: unreachable code
C:\Users\lad\Desktop\samp03asvr_R2_win32\gamemodes \SnipeMadness.pwn(304) : warning 225: unreachable code
C:\Users\lad\Desktop\samp03asvr_R2_win32\gamemodes \SnipeMadness.pwn(311) : warning 225: unreachable code
C:\Users\lad\Desktop\samp03asvr_R2_win32\gamemodes \SnipeMadness.pwn(31 : warning 225: unreachable code
C:\Users\lad\Desktop\samp03asvr_R2_win32\gamemodes \SnipeMadness.pwn(325) : warning 225: unreachable code
C:\Users\lad\Desktop\samp03asvr_R2_win32\gamemodes \SnipeMadness.pwn(332) : warning 225: unreachable code
C:\Users\lad\Desktop\samp03asvr_R2_win32\gamemodes \SnipeMadness.pwn(339) : warning 225: unreachable code
C:\Users\lad\Desktop\samp03asvr_R2_win32\gamemodes \SnipeMadness.pwn(346) : warning 225: unreachable code
C:\Users\lad\Desktop\samp03asvr_R2_win32\gamemodes \SnipeMadness.pwn(353) : warning 225: unreachable code
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


19 Warnings.

Reply
#2

Lol unreachable codes means it cant find the code so it wont work ingame fix it
Reply
#3

Wow im an idiot ignore my last post.

pawn Код:
if (strcmp("/help", cmdtext, true, 5) == 0)
  {
SendClientMessage(playerid,0x33CCFFAA, " -~Weapons For Sale~-");
SendClientMessage(playerid,0x33CCFFAA, "[Hint] Use /buy [name] to buy a weapon");
SendClientMessage(playerid,0x33CCFFAA, "Pistols- 9mm($450), S9mm($500), Deagle($1500)");
SendClientMessage(playerid,0x33CCFFAA, "Shotguns- Shotgun($800), CShotgun($2100), Sawnoff($1000)");
SendClientMessage(playerid,0x33CCFFAA, "Automatics- MicroSMG($800), SMG($1200), Tec9($900)");
SendClientMessage(playerid,0x33CCFFAA, "Rifles- CountryRifle($700), Sniper($1100),");
SendClientMessage(playerid,0x33CCFFAA, "AssaultRifles- AK47($1800), M4($2500),");
SendClientMessage(playerid,0x33CCFFAA, "Thrown- Grenade($3500), Molotov($3500), SatchelCharge($4000");
}
return 1;
return 0;
The return 0;
Remove it. Compile.
Move all the return 1; inside the if statement brackets.
Reply
#4

Remove the return 0; at the botton of the weapons as well ?
Reply
#5

Quote:
Originally Posted by Pachellis
Remove the return 0; at the botton of the weapons as well ?
The reason your getting the Unreachable code, is the misplacement of all the returns. Place them INSIDE the if statement brackets, remove the return 0's if you want.
Reply
#6

A return 0; must be at the bottom of OnPlayerCommandText
Reply
#7

Quote:
Originally Posted by dice7
A return 0; must be at the bottom of OnPlayerCommandText
Ya but the one at the top shouldn't be there.
Reply
#8

Will this work ?



public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/help", cmdtext, true, 5) == 0)
{
SendClientMessage(playerid,0x33CCFFAA, " -~Weapons For Sale~-");
SendClientMessage(playerid,0x33CCFFAA, "[Hint] Use /buy [name] to buy a weapon");
SendClientMessage(playerid,0x33CCFFAA, "Pistols- 9mm($450), S9mm($500), Deagle($1500)");
SendClientMessage(playerid,0x33CCFFAA, "Shotguns- Shotgun($800), CShotgun($2100), Sawnoff($1000)");
SendClientMessage(playerid,0x33CCFFAA, "Automatics- MicroSMG($800), SMG($1200), Tec9($900)");
SendClientMessage(playerid,0x33CCFFAA, "Rifles- CountryRifle($700), Sniper($1100),");
SendClientMessage(playerid,0x33CCFFAA, "AssaultRifles- AK47($1800), M4($2500),");
SendClientMessage(playerid,0x33CCFFAA, "Thrown- Grenade($3500), Molotov($3500), SatchelCharge($4000");
return 1;
}
if (strcmp("/buy 9mm", cmdtext, true, Cool == 0)
{
GivePlayerWeapon(playerid, 22, 60);
SendClientMessage(playerid,0x33AA33AA,"You have bought a 9mm for $450!");
GivePlayerMoney(playerid, -450);

return 1;
}
if (strcmp("/buy S9mm", cmdtext, true, 9) == 0)
{
GivePlayerWeapon(playerid, 23, 45);
SendClientMessage(playerid,0x33AA33AA,"You have bought a Silenced 9mm for $500!");
GivePlayerMoney(playerid, -500);

return 1;
}
if (strcmp("/buy Deagle", cmdtext, true, 11) == 0)
{
GivePlayerWeapon(playerid, 24, 30);
SendClientMessage(playerid,0x33AA33AA,"You have bought a Desert Eagle for $1500!");
GivePlayerMoney(playerid, -1500);

return 1;
}
if (strcmp("/buy Shotgun", cmdtext, true, 12) == 0)
{
GivePlayerWeapon(playerid, 25, 25);
SendClientMessage(playerid,0x33AA33AA,"You have bought a Shotgun for $800!");
GivePlayerMoney(playerid, -800);

return 1;
}
if (strcmp("/buy CShotgun", cmdtext, true, 13) == 0)
{
GivePlayerWeapon(playerid, 27, 35);
SendClientMessage(playerid,0x33AA33AA,"You have bought a CShotgun for $2100!");
GivePlayerMoney(playerid, -2100);

return 1;
}
if (strcmp("/buy Sawnoff", cmdtext, true, 12) == 0)
{
GivePlayerWeapon(playerid, 26, 20);
SendClientMessage(playerid,0x33AA33AA,"You have bought a Sawnoff for $1000!");
GivePlayerMoney(playerid, -1000);

return 1;
}
if (strcmp("/buy MicroSMG", cmdtext, true, 13) == 0)
{
GivePlayerWeapon(playerid, 28, 90);
SendClientMessage(playerid,0x33AA33AA,"You have bought a MicroSMG for $800!");
GivePlayerMoney(playerid, -800);

return 1;
}
if (strcmp("/buy SMG", cmdtext, true, Cool == 0)
{
GivePlayerWeapon(playerid, 29, 90);
SendClientMessage(playerid,0x33AA33AA,"You have bought a SMG for $1200!");
GivePlayerMoney(playerid, -1200);

return 1;
}
if (strcmp("/buy Tec9", cmdtext, true, 9) == 0)
{
GivePlayerWeapon(playerid, 32, 90);
SendClientMessage(playerid,0x33AA33AA,"You have bought a Tec9 for $900!");
GivePlayerMoney(playerid, -900);

return 1;
}
if (strcmp("/buy CountryRifle", cmdtext, true, 17) == 0)
{
GivePlayerWeapon(playerid, 33, 20);
SendClientMessage(playerid,0x33AA33AA,"You have bought a Country Rifle for $700!");
GivePlayerMoney(playerid, -700);

return 1;
}
if (strcmp("/buy Sniper", cmdtext, true, 11) == 0)
{
GivePlayerWeapon(playerid, 34, 20);
SendClientMessage(playerid,0x33AA33AA,"You have bought a Sniper for $1100!");
GivePlayerMoney(playerid, -1100);

return 1;
}
if (strcmp("/buy AK47", cmdtext, true, 9) == 0)
{
GivePlayerWeapon(playerid, 30, 120);
SendClientMessage(playerid,0x33AA33AA,"You have bought a AK47 for $1800!");
GivePlayerMoney(playerid, -1800);

return 1;
}
if (strcmp("/buy M4", cmdtext, true, 7) == 0)
{
GivePlayerWeapon(playerid, 31, 120);
SendClientMessage(playerid,0x33AA33AA,"You have bought a M4 for $2500!");
GivePlayerMoney(playerid, -2500);

return 1;
}
if (strcmp("/buy Grenade", cmdtext, true, 12) == 0)
{
GivePlayerWeapon(playerid, 16, 3);
SendClientMessage(playerid,0x33AA33AA,"You have bought a Grenade for $3500!");
GivePlayerMoney(playerid, -3500);

return 1;
}
if (strcmp("/buy Molotov", cmdtext, true, 12) == 0)
{
GivePlayerWeapon(playerid, 18, 3);
SendClientMessage(playerid,0x33AA33AA,"You have bought a Molotov for $3500!");
GivePlayerMoney(playerid, -3500);

return 1;
}
if (strcmp("/buy SatchelCharge", cmdtext, true, 1 == 0)
{
GivePlayerWeapon(playerid, 39, 2);
SendClientMessage(playerid,0x33AA33AA,"You have bought a SatchelCharge for $4000!");
GivePlayerMoney(playerid, -4000);

return 1;
return 0;
}
Reply
#9

did u compile it and did u get any warning dat says Unreachable code? pst here
Reply
#10

Quote:
Originally Posted by Lilcuete
did u compile it and did u get any warning dat says Unreachable code? pst here
I'll test it as soon as i get home. In advance, thanks
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)