SA-MP Forums Archive
About return 0; - 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: About return 0; (/showthread.php?tid=370127)



About return 0; - budelis - 19.08.2012

Hi. Why some callback's is return by return 0; ? like i found in one gm:

Code:
public OnPlayerDisconnect(playerid)
{
	if(gPlayerVehicles[playerid]) {
	    // Make sure their vehicle is destroyed when they leave.
    	DestroyVehicle(gPlayerVehicles[playerid]);
    	gPlayerVehicles[playerid] = 0;
	}
	return 0;
}
Code:
public OnPlayerRequestClass(playerid, classid)
{
	// put them straight into observer mode, effectively
	// bypassing class selection.
 	TogglePlayerSpectating(playerid,1);
    ObserverSwitchToNextVehicle(playerid);
    TextDrawShowForPlayer(playerid, txtObsHelper);

    // also force this dud spawn info upon them so that they
    // have spawn information set.
    SetSpawnInfo(playerid,0,0,
			gSpawnPositions[playerid][0],
			gSpawnPositions[playerid][1],
			gSpawnPositions[playerid][2],
			gSpawnPositions[playerid][3],
			-1,-1,-1,-1,-1,-1);
    
	return 0;
}
And why here need return?

Code:
stock GetPlayerNameEx( playerid )
{
	new
	    Name[ MAX_PLAYER_NAME ]
	;
	GetPlayerName( playerid,Name,MAX_PLAYER_NAME );
	return Name;
}
And when need return 0; or just return in my own callbacks? when i settimer and forward it...


Re: About return 0; - [MM]RoXoR[FS] - 19.08.2012

If you put return 0 in OnPlayerRequestClass the player wont spawn.
In GetPlayerNameEx, it will return you name of the player.


Re: About return 0; - IceMeteor - 19.08.2012

The return in GetPlayerNameEx is the result of the stock


Re: About return 0; - budelis - 19.08.2012

Code:
COMMAND:myname(playerid,params[])
{
    new string[ 25 ];
    format( string, 25,"%s", GetPlayerNameEx( playerid ) );
    SendClientMessage( playerid, -1, string );
	return 1;
}
if i write /myname first of all pawno will do this:

Code:
new string[ 25 ];
And then

Code:
format( string, 25,"%s", GetPlayerNameEx( playerid ) );
Ok. pawno will do this format, but if somebody will write this command, then

Code:
new string[ 25 ];
And when i have to get a message:

Code:
SendClientMessage( playerid, -1, string );
And i will get no message. Or i get other player name. Is it right? I think that because new string[ 25 ]; is global.


Re : About return 0; - ricardo178 - 19.08.2012

pawn Code:
COMMAND:myname(playerid,params[])
{
    new string[ 25 ], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format( string, 25,"%s", name);
    SendClientMessage( playerid, -1, string );
    return 1;
}



Re: About return 0; - budelis - 19.08.2012

I don't need code... Read my all post + Need answer with OnPlayerDisconnect.

RICARDO:

I saw one thing in your one script:

Code:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    new Float:hp;
    GetPlayerHealth(playerid, hp);
    if(hp <= 80 && animLocked[playerid] == 0)
    {
        for(new i = 0; i < MAX_VEHICLES; i++)
        SetVehicleParamsForPlayer(i, playerid, 0, 1);
        animLocked[playerid] = 1;
        ApplyAnimation(playerid, "CRACK", "crckdeth2", 4.0, 0, 1, 1, 1, 0, 1);
        return 1;
    }
    return 0;
}
why you use return 0; ?


Re: About return 0; - playbox12 - 19.08.2012

It just how the function is laid out, return is basically just a value or variable. If you create your own function you could use return to send a certain variable back like with GetName it would be the players name. For the native functions in samp, it is controlled by the samp-server, on the wiki you can see what it does. OnPlayerTakeDamage doesn't handle returns according to the wiki, so it doesn't matter what you return there.

(It is basically just an exit out of the function, usally used to tell the script the status of which it returned with).


Re: About return 0; - ryansheilds - 19.08.2012

From my understanding - Might be a load of bullshit - I think returns basically have two ways they can be used, firstly been whether the function/command (Whatever it it) should be processed (True/False) - Like returning unknown command (return 0; - Don't process). The second way is pretty much the same but can return many values, for example:
pawn Code:
stock GetAdmin(playerid)
{
    if(pinfo[playerid][padmin] == 1)
        return 1
    else if(pinfo[playerid][padmin] == 2)
        return 2
    else if(pinfo[playerid][padmin] == 3)
        return 3
}
That's how I understand it... Kind of how it sound - What would you like to return? (Rhetorical )