optimize code - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: optimize code (
/showthread.php?tid=579270)
optimize code -
DeadNudock - 25.06.2015
resolvi smd..
Re: optimize code -
Stanford - 25.06.2015
I don't think that removing { } would optimize your code, it might make it 'look' better for some people however, I think it doesn't affect that much in performance. Moreover, some people find this a cause for confusion due to you can remove the { } once there's one operation/function whatever to be done. For instance,
pawn Code:
if(Carlos == "good")
foreach(new i : Player)
{
SendClientMessage(i, -1, "CARLOS IS GOOD!");
}
This is not a must!
Re: optimize code -
DeadNudock - 25.06.2015
Not quite understand, but I'll try ..
@edit
I did not make it.. please
Re: optimize code -
!damo!spiderman - 25.06.2015
Quote:
Originally Posted by DeadNudock
I tried to let the faster code, let easier to understand, more can not, please someone can tell me how I can remove the
without harming the code?
PHP Code:
if (IsGangueGRI(i))
{
if (PlayerInfo[i][pCargo] == 1)
{
if (CofreOrg[GetPlayerOrg(i)][salarioc1] == 0)
{}///
else if (CofreOrg[GetPlayerOrg(i)][Dinheiro] < CofreOrg[GetPlayerOrg(i)][salarioc1])
{
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc1];
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc1]);
}
}
if (PlayerInfo[i][pCargo] == 2)
{
if (CofreOrg[GetPlayerOrg(i)][salarioc2] == 0)
{}/////
else if (CofreOrg[GetPlayerOrg(i)][Dinheiro] >= CofreOrg[GetPlayerOrg(i)][salarioc2])
{
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc2];
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc2]);
}
}
if (PlayerInfo[i][pCargo] == 3)
{
if (CofreOrg[GetPlayerOrg(i)][salarioc3] == 0)
{}////
else if (CofreOrg[GetPlayerOrg(i)][Dinheiro] >= CofreOrg[GetPlayerOrg(i)][salarioc3])
{
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc3];
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc3]);
}
}
if (PlayerInfo[i][pCargo] == 4)
{
if (CofreOrg[GetPlayerOrg(i)][salarioc4] == 0)
{}////
else if (CofreOrg[GetPlayerOrg(i)][Dinheiro] >= CofreOrg[GetPlayerOrg(i)][salarioc4])
{
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc4];
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc4]);
}
}
if (PlayerInfo[i][pCargo] == 5)
{
if (CofreOrg[GetPlayerOrg(i)][salarioc5] == 0)
{}///
else if (CofreOrg[GetPlayerOrg(i)][Dinheiro] >= CofreOrg[GetPlayerOrg(i)][salarioc5])
{
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc5];
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc5]);
}
}
if (PlayerInfo[i][pCargo] == 6)
{
if (CofreOrg[GetPlayerOrg(i)][Dinheiro] >= 2000) PlayerInfo[i][pSalario] += 2000, SacarGranaOrg(GetPlayerOrg(i), 2000);
}
}
|
PHP Code:
if (CofreOrg[GetPlayerOrg(i)][salarioc1] == 0)
{}///
else if (CofreOrg[GetPlayerOrg(i)][Dinheiro] < CofreOrg[GetPlayerOrg(i)][salarioc1])
{
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc1];
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc1]);
}
// Change to
if (CofreOrg[GetPlayerOrg(i)][salarioc1] != 0 && CofreOrg[GetPlayerOrg(i)][Dinheiro] < CofreOrg[GetPlayerOrg(i)][salarioc1])
{
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc1];
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc1]);
}
Re: optimize code -
!damo!spiderman - 25.06.2015
You could also change the whole thing into a switch statement which would be a lot nicer to read
PHP Code:
if (IsGangueGRI(i))
{
switch(PlayerInfo[i][pCargo]){
case 1:
if (CofreOrg[GetPlayerOrg(i)][salarioc1] != 0 && CofreOrg[GetPlayerOrg(i)][Dinheiro] < CofreOrg[GetPlayerOrg(i)][salarioc1])
{
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc1];
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc1]);
}
case 2:
// next section
case 3:
// etc
}
}