PDA

View Full Version : CLass Selection


sanamalik400
18/09/2015, 11:49 PM
i made this code if time >275 than player can change class..otherwise if time <275 set class for next spawn..but its not working plz see what i forgot in this code
case DIALOG_CLASS_1:
{
if(response)
{
if(time >= 275)
{
switch(listitem)
{
case 0: if(pInfo[playerid][pXP] >= 0) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = CIVILIAN,setClass(playerid); else { SendXPError(playerid,0); }
case 1: if(pInfo[playerid][pXP] >= 500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = POLICEMAN,setClass(playerid); else { SendXPError(playerid,500); }
case 2: if(pInfo[playerid][pXP] >= 1000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = MEDIC,setClass(playerid); else { SendXPError(playerid,1000); }
case 3: if(pInfo[playerid][pXP] >= 1500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = SCOUT,setClass(playerid); else { SendXPError(playerid,1500); }
case 4: if(pInfo[playerid][pXP] >= 5000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = HEAVYMEDIC,setClass(playerid); else { SendXPError(playerid,5000); }
case 5: if(pInfo[playerid][pXP] >= 6000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = FARMER,setClass(playerid); else { SendXPError(playerid,6000); }
case 6: if(pInfo[playerid][pXP] >= 6500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = SOLDIER,setClass(playerid); else { SendXPError(playerid,6500); }
case 7: if(pInfo[playerid][pXP] >= 7500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = ENGINEER,setClass(playerid); else { SendXPError(playerid,7500); }
case 8: if(pInfo[playerid][pXP] >= 15000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = SWAT,setClass(playerid); else { SendXPError(playerid,15000); }
case 9: if(pInfo[playerid][pXP] >= 20000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = HEAVYSHOTGUN,setClass(playerid); else { SendXPError(playerid,20000); }
case 10: if(pInfo[playerid][pXP] >= 30000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = ADVANCEDENGINEER,setClass(playerid); else { SendXPError(playerid,30000); }
}
}
else if (pInfo[playerid][pXP] >= 0) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = CIVILIAN;
else if (pInfo[playerid][pXP] >= 500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = POLICEMAN;
else if (pInfo[playerid][pXP] >= 1000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = MEDIC;
else if (pInfo[playerid][pXP] >= 1500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = SCOUT;
else if (pInfo[playerid][pXP] >= 5000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = HEAVYMEDIC;
else if (pInfo[playerid][pXP] >= 6000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = FARMER;
else if (pInfo[playerid][pXP] >= 6500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = SOLDIER;
else if (pInfo[playerid][pXP] >= 7500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = ENGINEER;
else if (pInfo[playerid][pXP] >= 15000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = SWAT;
else if (pInfo[playerid][pXP] >= 20000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = HEAVYSHOTGUN;
else if (pInfo[playerid][pXP] >= 30000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = ADVANCEDENGINEER;
else return SendClientMessage(playerid,-1,""chat""COL_RED" Class Set Will Change on Next Round");
}
}

Sew_Sumi
19/09/2015, 12:01 AM
Should use 4 space tabs, then you'd see a bit clearer.

As for the problem, I think it relates to your braces.


Re-formatted your code, same code, simply tabbed out correctly. Tabs, using 4 space. Avoid using spaces.


case DIALOG_CLASS_1:
{
if(response)
{
if(time >= 275)
{
switch(listitem)
{
case 0: if(pInfo[playerid][pXP] >= 0) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = CIVILIAN,setClass(playerid); else { SendXPError(playerid,0); }
case 1: if(pInfo[playerid][pXP] >= 500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = POLICEMAN,setClass(playerid); else { SendXPError(playerid,500); }
case 2: if(pInfo[playerid][pXP] >= 1000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = MEDIC,setClass(playerid); else { SendXPError(playerid,1000); }
case 3: if(pInfo[playerid][pXP] >= 1500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = SCOUT,setClass(playerid); else { SendXPError(playerid,1500); }
case 4: if(pInfo[playerid][pXP] >= 5000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = HEAVYMEDIC,setClass(playerid); else { SendXPError(playerid,5000); }
case 5: if(pInfo[playerid][pXP] >= 6000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = FARMER,setClass(playerid); else { SendXPError(playerid,6000); }
case 6: if(pInfo[playerid][pXP] >= 6500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = SOLDIER,setClass(playerid); else { SendXPError(playerid,6500); }
case 7: if(pInfo[playerid][pXP] >= 7500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = ENGINEER,setClass(playerid); else { SendXPError(playerid,7500); }
case 8: if(pInfo[playerid][pXP] >= 15000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = SWAT,setClass(playerid); else { SendXPError(playerid,15000); }
case 9: if(pInfo[playerid][pXP] >= 20000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = HEAVYSHOTGUN,setClass(playerid); else { SendXPError(playerid,20000); }
case 10: if(pInfo[playerid][pXP] >= 30000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = ADVANCEDENGINEER,setClass(playerid); else { SendXPError(playerid,30000); }
}
}
else if (pInfo[playerid][pXP] >= 0) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = CIVILIAN;
else if (pInfo[playerid][pXP] >= 500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = POLICEMAN;
else if (pInfo[playerid][pXP] >= 1000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = MEDIC;
else if (pInfo[playerid][pXP] >= 1500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = SCOUT;
else if (pInfo[playerid][pXP] >= 5000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = HEAVYMEDIC;
else if (pInfo[playerid][pXP] >= 6000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = FARMER;
else if (pInfo[playerid][pXP] >= 6500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = SOLDIER;
else if (pInfo[playerid][pXP] >= 7500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = ENGINEER;
else if (pInfo[playerid][pXP] >= 15000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = SWAT;
else if (pInfo[playerid][pXP] >= 20000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = HEAVYSHOTGUN;
else if (pInfo[playerid][pXP] >= 30000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = ADVANCEDENGINEER;
else return SendClientMessage(playerid,-1,""chat""COL_RED" Class Set Will Change on Next Round");
}
}

Because of it being formatted nicely, now I can read it, and really, the problem is that in the first portion you check the time, and listitem. Second part, you don't.

You're not checking after 275, what item they even selected.

Need to be a bit more patient, and work on your structure.

sanamalik400
19/09/2015, 12:12 AM
see this code
case DIALOG_CLASS_1:
{
if(response)
{
if(time >= 275)
{
switch(listitem)
{
case 0: if(pInfo[playerid][pXP] >= 0) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = CIVILIAN,setClass(playerid);
else if(pInfo[playerid][pXP] >= 0) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][pHumanClass] = CIVILIAN;
else { SendXPError(playerid,0); }
case 1: if(pInfo[playerid][pXP] >= 500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = POLICEMAN,setClass(playerid);
else if(time <= 275) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][pHumanClass] = POLICEMAN;
else { SendXPError(playerid,500); }
case 2: if(pInfo[playerid][pXP] >= 1000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = MEDIC,setClass(playerid);
else if(time <= 275) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][pHumanClass] = MEDIC;
else { SendXPError(playerid,1000); }
case 3: if(pInfo[playerid][pXP] >= 1500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = SCOUT,setClass(playerid);
else if(time <= 275) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][pHumanClass] = SCOUT;
else { SendXPError(playerid,1500); }
case 4: if(pInfo[playerid][pXP] >= 5000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = HEAVYMEDIC,setClass(playerid);
else if(time <= 275) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][pHumanClass] = HEAVYMEDIC;
else { SendXPError(playerid,5000); }
case 5: if(pInfo[playerid][pXP] >= 6000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = FARMER,setClass(playerid);
else if(time <= 275) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][pHumanClass] = FARMER;
else { SendXPError(playerid,6000); }
case 6: if(pInfo[playerid][pXP] >= 6500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = SOLDIER,setClass(playerid);
else if(time <= 275) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][pHumanClass] = SOLDIER;
else { SendXPError(playerid,6500); }
case 7: if(pInfo[playerid][pXP] >= 7500) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = ENGINEER,setClass(playerid);
else if(time <= 275) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][pHumanClass] = ENGINEER;
else { SendXPError(playerid,7500); }
case 8: if(pInfo[playerid][pXP] >= 15000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = SWAT,setClass(playerid);
else if(time <= 275) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][pHumanClass] = SWAT;
else { SendXPError(playerid,15000); }
case 9: if(pInfo[playerid][pXP] >= 20000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = HEAVYSHOTGUN,setClass(playerid);
else if(time <= 275) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][pHumanClass] = HEAVYSHOTGUN;
else { SendXPError(playerid,20000); }
case 10: if(pInfo[playerid][pXP] >= 30000) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][SkinChanges] -= 0,pInfo[playerid][pHumanClass] = ADVANCEDENGINEER,setClass(playerid);
else if(time <= 275) pInfo[playerid][pHumanClass] = 0,pInfo[playerid][pHumanClass] = ADVANCEDENGINEER;
else { SendXPError(playerid,30000); }
}
}
else return SendClientMessage(playerid,-1,""chat""COL_RED" Class Set Will Change on Next Round");
}
}

Sew_Sumi
19/09/2015, 12:14 AM
gah, my eyes...

Please, tab it out, 4 spaces, and edit your post.


(I think you'll need to restruture the way you are doing the checks)


Like, let them choose it, set it, and then decide whether it is time <275 and then set or deny in a seperate portion.

sanamalik400
19/09/2015, 12:26 AM
sorry but i not understand..can u edit this ???

Crayder
19/09/2015, 12:33 AM
If you are just learning to script, you should really work on structure before getting into actual code.

sanamalik400
19/09/2015, 12:38 AM
i said before i m new..so i cant work on structure.else.i dont know what is structure in pawno..anyone edit my code.. i will learn so much from it...if anyone helps :(

Sew_Sumi
19/09/2015, 12:48 AM
Formatting is where you've put up...


functionname
{
code
{
morecode
}
}


where it should be

functionname
{
code
{
morecode
}
}


Structure comes in the form of


functionname
{
if structure
{
if time is XXX
{
if listitem is CC
{
code
}
}
code that should be in another if statement here
else return code that won't be encountered under most circumstances
}
}



functionname
{
if structure
{
if listitem is CC
{
code
}
if time > 275
{
SendMessage Skin changed
SkinChange
Putting a return here will end the checks.
}
if time < 275
{
SendMessage Skin will change next round
return
}
}
}


Don't pin me for accuracy, but this is simply trying to explain what we're mentioning.

sanamalik400
19/09/2015, 11:37 PM
thanks friend ... u nice teaching :) ,,and my problem solved :D +1 for u :D :)