Return + continue
#1

How i can return something, and then continue..
Reply
#2

In any loop?
Reply
#3

i dont use loop..
Reply
#4

You mean something like yield in python? I think that's reserved for generators. If you mean something else, please explain what do you exactly mean.
Reply
#5

yes please explain what do you exactly mean.
Reply
#6

I making Pocketbook system.
When player die server takes player money.
But if player are member or leader i don't want server takes for him money.
But if i set return when player die server don't respawn him in L.S.P.D spawn or FBI spawn or JSO spawn..

Код:
public ReleaseFromHospital(playerid)
{
	KillTimer(stopactimer[playerid]);
	Dead[playerid] = 1;
	SCM(playerid, COLOR_LIGHT_BLUE, "You were released from hospital.");
	TogglePlayerControllable(playerid, 1);
	SetCameraBehindPlayer(playerid);
	SafeSetPlayerHealth(playerid, 50.0);
	if(PlayerInfo[playerid][pPocketbookexpire] < 1)
    {
    	PlayerInfo[playerid][pPocketbook] = 0;
    	PlayerInfo[playerid][pPocketbookexpire] = 0;
    	SCM(playerid, COLOR_WHITE, "Your Pocketbook expire buy new!");
	}
	if(PlayerInfo[playerid][pPocketbook] > 0)
	{
		SCM(playerid, COLOR_WHITE, "You are insured.");
		SafeGivePlayerMoney(playerid, -500);
	}
	if(PlayerInfo[playerid][pPocketbook] < 1)
	{
		SCM(playerid, COLOR_WHITE, "You don't have pocketbook");
	}
	if((PlayerInfo[playerid][pMember] == 1 || PlayerInfo[playerid][pLeader] == 1) && PlayerInfo[playerid][pDuty] == 1)//L.S.P.D spawn
	{
		SetPlayerToTeamColor(playerid);
		SafeSetPlayerInterior(playerid,6);
		SafeSetPlayerPos(playerid, 216.9725,79.1339,1005.0391);
		SetPlayerFacingAngle(playerid, 270.0);
		SafeSetPlayerArmor(playerid, 50.0);
		return 1;
	}
	if(PlayerInfo[playerid][pDuty] == 1 || PlayerInfo[playerid][pMember] == 1 || PlayerInfo[playerid][pLeader] == 1
	|| PlayerInfo[playerid][pMember] == 2 || PlayerInfo[playerid][pLeader] == 2 || PlayerInfo[playerid][pMember] == 3 || PlayerInfo[playerid][pLeader] == 3)
	{
		SCM(playerid, COLOR_WHITE, "Country pay insured for you.");
		return 1;
	}
	else if((PlayerInfo[playerid][pMember] == 2 || PlayerInfo[playerid][pLeader] == 2) && PlayerInfo[playerid][pDuty] == 1)//FBI spawn
	{
		SetPlayerToTeamColor(playerid);
		SafeSetPlayerInterior(playerid,3);
		SafeSetPlayerPos(playerid, 299.7097,183.1322,1007.1719);
		SetPlayerFacingAngle(playerid, 90);
		SafeSetPlayerHealth(playerid, 75.0);
		SafeSetPlayerArmor(playerid, 75.0);
		return 1;
	}
	else if((PlayerInfo[playerid][pMember] == 3 || PlayerInfo[playerid][pLeader] == 3) && PlayerInfo[playerid][pDuty] == 1)//JSO spawn
	{
	    SetPlayerToTeamColor(playerid);
	    SafeSetPlayerInterior(playerid, 0);
	    SafeSetPlayerPos(playerid, 2731.5229,-2451.3643,17.5937);
		SafeSetPlayerHealth(playerid, 100.0);
		SafeSetPlayerArmor(playerid, 99.0);
	    return 1;
	}
	else
	{
		new decidehosp = random(2);
		switch(decidehosp)
		{
			case 0:
			{
				SafeSetPlayerPos(playerid, 1177.4866,-1323.9749,14.0731);
				SetPlayerFacingAngle(playerid, 270.0);
				SafeSetPlayerInterior(playerid, 0);
				SafeResetPlayerWeapons(playerid);
			}
			case 1:
			{
				SafeSetPlayerPos(playerid, 2025.1497,-1402.8643,17.2089);
				SetPlayerFacingAngle(playerid, 270.0);
				SafeSetPlayerInterior(playerid, 0);
				SafeResetPlayerWeapons(playerid);
			}
		}
	}
	KillTimer(stopactimer[playerid]);
	stopactimer[playerid] = SetTimerEx("resumeanticheat", 4000, false, "i", playerid);
	return 1;
}
Reply
#7

Return is final keyword in function, nothing can happen after it. But, you can make it conditional, so it only returns in certain situations. Also, simply moving chunks of code can make your code clearer:

pawn Код:
#define ActiveMemberOnDuty(%0,%1) (PlayerInfo[%0][pDuty] && (PlayerInfo[%0][pMember] == %1 || PlayerInfo[%0][pLeader] == %1))

public ReleaseFromHospital(playerid)
{
    KillTimer(stopactimer[playerid]);
    Dead[playerid] = 1;
    SCM(playerid, COLOR_LIGHT_BLUE, "You were released from hospital.");
    TogglePlayerControllable(playerid, 1);
    SetCameraBehindPlayer(playerid);
    SafeSetPlayerHealth(playerid, 50.0);
   
    if(PlayerInfo[playerid][pPocketbookexpire] < 1)
    {
        PlayerInfo[playerid][pPocketbook] = 0;
        PlayerInfo[playerid][pPocketbookexpire] = 0;
        SCM(playerid, COLOR_WHITE, "Your Pocketbook expire buy new!");
    }

    if(!PlayerInfo[playerid][pPocketbook]) {
        SCM(playerid, COLOR_WHITE, "You don't have pocketbook");
        SafeGivePlayerMoney(playerid, -500);
    }
    else {
        SCM(playerid, COLOR_WHITE, "You are insured.");
    }

    KillTimer(stopactimer[playerid]);
    stopactimer[playerid] = SetTimerEx("resumeanticheat", 4000, false, "i", playerid);

    if(ActiveMemberOnDuty(playerid, 1) || ActiveMemberOnDuty(playerid, 2) || ActiveMemberOnDuty(playerid, 3))
    {
        SCM(playerid, COLOR_WHITE, "Country pay insured for you.");
    }

    if(ActiveMemberOnDuty(playerid, 1))//L.S.P.D spawn
    {
        SetPlayerToTeamColor(playerid);
        SafeSetPlayerInterior(playerid,6);
        SafeSetPlayerPos(playerid, 216.9725,79.1339,1005.0391);
        SetPlayerFacingAngle(playerid, 270.0);
        SafeSetPlayerArmor(playerid, 50.0);
        return 1;
    }

    if(ActiveMemberOnDuty(playerid, 2)) //FBI spawn
    {
        SetPlayerToTeamColor(playerid);
        SafeSetPlayerInterior(playerid,3);
        SafeSetPlayerPos(playerid, 299.7097,183.1322,1007.1719);
        SetPlayerFacingAngle(playerid, 90);
        SafeSetPlayerHealth(playerid, 75.0);
        SafeSetPlayerArmor(playerid, 75.0);
        return 1;
    }
   
    if(ActiveMemberOnDuty(playerid, 3))
    {
        SetPlayerToTeamColor(playerid);
        SafeSetPlayerInterior(playerid, 0);
        SafeSetPlayerPos(playerid, 2731.5229,-2451.3643,17.5937);
        SafeSetPlayerHealth(playerid, 100.0);
        SafeSetPlayerArmor(playerid, 99.0);
        return 1;
    }
     
    new decidehosp = random(2);

    switch(decidehosp)
    {
        case 0: SafeSetPlayerPos(playerid, 1177.4866,-1323.9749,14.0731);
        case 1: SafeSetPlayerPos(playerid, 2025.1497,-1402.8643,17.2089);
    }

    SetPlayerFacingAngle(playerid, 270.0);
    SafeSetPlayerInterior(playerid, 0);
    SafeResetPlayerWeapons(playerid);
   
    return 1;
}
I added one macro, it's cleaner that way - it check if player is a member or leader of a fraction, and if he's on duty.
Reply
#8

if i leader or member of LSPD or FBI system takes from me money.

here must be return 1;
but if i set return 1; he wan't spawn on FBI hq or LSPD hq

Код:
if(ActiveMemberOnDuty(playerid, 1) || ActiveMemberOnDuty(playerid, 2) || ActiveMemberOnDuty(playerid, 3))
    {
        SCM(playerid, COLOR_WHITE, "Country pay insured for you.");
        return 1;
    }
Reply
#9

So don't use return 1?
Reply
#10

If i don't use return 1 system will not spawn member & leader in HQ
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)