Jump to content
  • 0

pomoc Camp Fire - 1 objekt pro každého hráče


Thomas

Dotaz

Zdravím chtěl bych jsem se zeptat jak udělám u fs camp fire aby každý hráč si moch pouze jeden objekt vytvořit nikoliv aby všichni hráči mohly pouze max 19 např  a psalo mu to už jsi vytvořil jeden camp fire a pak po smazani moch vytvořit opět jeden pouze ? Předem Děkuji

 

Kod FS:

#include <a_samp>
#define MAX_SPIKESTRIPS 19

enum sInfo
{
	sCreated,
    Float:sX,
    Float:sY,
    Float:sZ,
    sObject,
};
new SpikeInfo[MAX_SPIKESTRIPS][sInfo];

public OnPlayerUpdate(playerid)
{
	if(!IsPlayerConnected(playerid)) return 0;

    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        for(new i = 0; i < sizeof(SpikeInfo); i++)
  	    {
  	        if(IsPlayerInRangeOfPoint(playerid, 3.0, SpikeInfo[i][sX], SpikeInfo[i][sY], SpikeInfo[i][sZ]))
            {
  	            if(SpikeInfo[i][sCreated] == 1)
  	            {
  	                new panels, doors, lights, tires;
  	                new carid = GetPlayerVehicleID(playerid);
		            GetVehicleDamageStatus(carid, panels, doors, lights, tires);
		            tires = encode_tires(1, 1, 1, 1);
		            UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
  	                return 0;
  	            }
  	        }
  	    }
  	}

	return 1;
}

stock CreateCamp(Float:x,Float:y,Float:z,Float:Angle)
{
    for(new i = 0; i < sizeof(SpikeInfo); i++)
  	{
  	    if(SpikeInfo[i][sCreated] == 0)
  	    {
            SpikeInfo[i][sCreated]=1;
            SpikeInfo[i][sX]=x;
            SpikeInfo[i][sY]=y;
            SpikeInfo[i][sZ]=z-0.7;
            SpikeInfo[i][sObject] = CreateObject(19632, x, y, z-0.9, 0, 0, Angle-90);
	        return 1;
  	    }
  	}
  	return 0;
}

stock DeleteClosestCamp(playerid)
{
    for(new i = 0; i < sizeof(SpikeInfo); i++)
  	{
  	    if(IsPlayerInRangeOfPoint(playerid, 2.0, SpikeInfo[i][sX], SpikeInfo[i][sY], SpikeInfo[i][sZ]))
        {
  	        if(SpikeInfo[i][sCreated] == 1)
            {
                SpikeInfo[i][sCreated]=0;
                SpikeInfo[i][sX]=0.0;
                SpikeInfo[i][sY]=0.0;
                SpikeInfo[i][sZ]=0.0;
                DestroyObject(SpikeInfo[i][sObject]);
                return 1;
  	        }
  	    }
  	}
    return 0;
}

encode_tires(tires1, tires2, tires3, tires4) {

	return tires1 | (tires2 << 1) | (tires3 << 2) | (tires4 << 3);

}
strtok(const string[], &index)
{
	new length = strlen(string);
	while ((index < length) && (string[index] <= ' '))
	{
		index++;
	}

	new offset = index;
	new result[20];
	while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
	{
		result[index - offset] = string[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
	new cmd[256];
	new idx;
	cmd = strtok(cmdtext, idx);

	if (strcmp(cmd,"/campfire",true) == 0)
	{
	    ApplyAnimation(playerid,"BOMBER","BOM_Plant",4.0,0,0,0,0,0);
    	ApplyAnimation(playerid,"BOMBER","BOM_Plant",4.0,0,0,0,0,0);
		new Float:plocx,Float:plocy,Float:plocz,Float:ploca;
        GetPlayerPos(playerid, plocx, plocy, plocz);
        GetPlayerFacingAngle(playerid,ploca);
        CreateCamp(plocx,plocy,plocz,ploca);
	    return 1;
	}
	else if (strcmp(cmd,"/removecampfire",true) == 0)
	{
		ApplyAnimation(playerid,"BOMBER","BOM_Plant",4.0,0,0,0,0,0);
    	ApplyAnimation(playerid,"BOMBER","BOM_Plant",4.0,0,0,0,0,0);
		DeleteClosestCamp(playerid);
	    return 1;
	}

	return 0;
}
Edited by Thomas
Link to comment
Share on other sites

3 odpovědí na tuto otázku

Recommended Posts

  • 0

Hore do módu si daj:

new bool:campfire[MAX_PLAYERS];

Pokial nemáš zadefinovane MAX_PLAYERS tak si daj hore do módu kde máš definicie:

#define MAX_PLAYERS 10  to 10 si zmen na počet slotov tvojho servera

Teraz ideme k tomu čo si chcel:

public OnPlayerCommandText(playerid, cmdtext[])
{
	new cmd[256];
	new idx;
	cmd = strtok(cmdtext, idx);

	if (strcmp(cmd,"/campfire",true) == 0)
	{
	ApplyAnimation(playerid,"BOMBER","BOM_Plant",4.0,0,0,0,0,0);
    	ApplyAnimation(playerid,"BOMBER","BOM_Plant",4.0,0,0,0,0,0);
	new Float:plocx,Float:plocy,Float:plocz,Float:ploca;
        GetPlayerPos(playerid, plocx, plocy, plocz);
        GetPlayerFacingAngle(playerid,ploca);
        CreateCamp(plocx,plocy,plocz,ploca);
        campfire[playerid] = true;
	    return 1;
	}
	else if (strcmp(cmd,"/removecampfire",true) == 0)
	{
                if(campfire[playerid] == true)return SendClientMessage(playerid,0xFFAAFF,"Už máš vytvorený jeden campfire!");
		ApplyAnimation(playerid,"BOMBER","BOM_Plant",4.0,0,0,0,0,0);
    	        ApplyAnimation(playerid,"BOMBER","BOM_Plant",4.0,0,0,0,0,0);
		DeleteClosestCamp(playerid);
                campfire[playerid] = false;
	    return 1;
	}

	return 0;
}
Link to comment
Share on other sites

  • 0

Děkuj funguje je to :) jinak ta podminka if(campfire[playerid] == true)return SendClientMessage(playerid,0xFFAAFF,"Už máš vytvorený jeden campfire!"); měla byt u /campfire ale to jsem jsi opravil a funguje to

Edited by Thomas
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...