SA-MP Forums Archive
few error with if & else - 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: few error with if & else (/showthread.php?tid=299743)



few error with if & else - manchestera - 27.11.2011

having a little problem with this code any helped would be great


Код:
C:\Users\GTA ONLY\My Samp Server\gamemodes\MySQL.pwn(347) : warning 209: function "OnPlayerSpawn" should return a value
C:\Users\GTA ONLY\My Samp Server\gamemodes\MySQL.pwn(348) : error 010: invalid function or declaration
C:\Users\GTA ONLY\My Samp Server\gamemodes\MySQL.pwn(351) : error 010: invalid function or declaration
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
Код:
public OnPlayerSpawn(playerid)//337
	{
	new Random = random(sizeof(MdmSpawns));
	new r = random(sizeof(RandomPistol));
	new r1 = random(sizeof(RandomAssault));
	new r2 = random(sizeof(RandomHeavy));
	if(MDM[playerid] != 0) return SetPlayerPos(playerid, MdmSpawns[Random][0], MdmSpawns[Random][1], MdmSpawns[Random][2]);
	GivePlayerWeapon(playerid, RandomPistol[r][0], RandomPistol[r][1]);
	GivePlayerWeapon(playerid, RandomAssault[r1][0], RandomAssault[r1][1]);
	GivePlayerWeapon(playerid, RandomHeavy[r2][0], RandomHeavy[r2][1]);
 }
 else
 {
	 SetPlayerPos(playerid, -2808.0325, -1516.4255, 140.8438), SetPlayerInterior(playerid, 0);
	return 1;
}//352
many thanks


Re: few error with if & else - Kostas' - 27.11.2011

You have an else that it's useless. Your code should be
pawn Код:
public OnPlayerSpawn(playerid)
{
    new Random = random(sizeof(MdmSpawns));
    new r = random(sizeof(RandomPistol));
    new r1 = random(sizeof(RandomAssault));
    new r2 = random(sizeof(RandomHeavy));
    if(MDM[playerid] != 0) return SetPlayerPos(playerid, MdmSpawns[Random][0], MdmSpawns[Random][1], MdmSpawns[Random][2]);
    GivePlayerWeapon(playerid, RandomPistol[r][0], RandomPistol[r][1]);
    GivePlayerWeapon(playerid, RandomAssault[r1][0], RandomAssault[r1][1]);
    GivePlayerWeapon(playerid, RandomHeavy[r2][0], RandomHeavy[r2][1]);
    return 1;
}
Or should remove this
pawn Код:
return SetPlayerPos(playerid, MdmSpawns[Random][0], MdmSpawns[Random][1], MdmSpawns[Random][2]);
to use the else like this
pawn Код:
public OnPlayerSpawn(playerid)
{
    new r = random(sizeof(RandomPistol));
    new r1 = random(sizeof(RandomAssault));
    new r2 = random(sizeof(RandomHeavy));
    if(MDM[playerid] != 0) {
        GivePlayerWeapon(playerid, RandomPistol[r][0], RandomPistol[r][1]);
        GivePlayerWeapon(playerid, RandomAssault[r1][0], RandomAssault[r1][1]);
        GivePlayerWeapon(playerid, RandomHeavy[r2][0], RandomHeavy[r2][1]);
    }
    else {
        SetPlayerPos(playerid, -2808.0325, -1516.4255, 140.8438), SetPlayerInterior(playerid, 0);
    }
    return 1;
}



Re: few error with if & else - manchestera - 27.11.2011

thanks for your help