All pastes #549500 Raw Edit

[Fackin']Luke

public text v1 · immutable
·published 2007-06-08 04:24 UTC
rendered paste body
#include <a_samp>

#define COLOR_YELLOW 0xFFFF00AA

new NearObject[MAX_PLAYERS];

enum ObjectInfo
{
    modelid,
    Float:X,
    Float:Y,
    Float:Z,
    Float:rX,
    Float:rY,
    Float:rZ
}

new Float:ObjectsWithLOD[1][ObjectInfo] =
{
    {3589,2431.76,-1674.83,15.2906,0.0,0.0,0.0}
};

new Float:LODObjects[1][ObjectInfo] =
{
    {3592,2431.76,-1674.83,15.2903,0.0,0.0,0.0}
};

forward DynamicLODObjectTimer();

main()
{
    print("\n-------------------------------------");
    print("    Dynamic LOD Objects Test Script    ");
    print("-------------------------------------\n");
}

public OnGameModeInit()
{
    SetGameModeText("Test Script");
    AddPlayerClass(105,2517.6182,-1661.7655,14.2038,98.6277,0,0,22,1000,0,0);
    SetTimer("DynamicLODObjectTimer",500,1);
    for(new i = 0; i < sizeof(ObjectsWithLOD); i++)
    {
    CreateObject(ObjectsWithLOD[i][modelid],ObjectsWithLOD[i][X],ObjectsWithLOD[i][Y],ObjectsWithLOD[i][Z],ObjectsWithLOD[i][rX],ObjectsWithLOD[i][rY],ObjectsWithLOD[i][rZ]);
    }
    //CreateObject(3592,2431.76,-1674.83,15.2903,0,0,0); //The LOD object for the house
    CreateObject(17514,2430.74,-1678.73,13.1484,180,180,0); //hedge walls
    CreateObject(1211,2426.95,-1665.25,12.9219,0.509539,0.0142679,359.783); //fire hydrant
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnPlayerConnect(playerid)
{
    NearObject[playerid] = 0;
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    return 1;
}

public OnPlayerSpawn(playerid)
{
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}

public OnPlayerPrivmsg(playerid, recieverid, text[])
{
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
	// Do something here
	return 1;
    }
    return 0;
}

public OnPlayerInfoChange(playerid)
{
    return 1;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public DynamicLODObjectTimer()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
	if(IsPlayerConnected(i))
	{
            for(new j = 0; j < sizeof(ObjectsWithLOD); j++)
	    {
	        for(new k = 0; k < sizeof(LODObjects); k++)
		{
		    //GetObjectPos(j,ObjectsWithLOD[j][X],ObjectsWithLOD[j][Y],ObjectsWithLOD[j][Z]); //is this line needed?
                    if(GetPlayerDistanceToPointEx(i,ObjectsWithLOD[j][X],ObjectsWithLOD[j][Y],ObjectsWithLOD[j][Z]) > 30.0)
                    {
		        if(NearObject[i] == 0)
	                {
			    DestroyObject(j);
		            SendClientMessage(i,COLOR_YELLOW,"1");
                            CreateObject(LODObjects[k][modelid],LODObjects[k][X],LODObjects[k][Y],LODObjects[k][Z],LODObjects[k][rX],LODObjects[k][rY],LODObjects[k][rY]);
			    SendClientMessage(i,COLOR_YELLOW,"2");
		            NearObject[i] = 1;
			}
			else if(NearObject[i] == 1)
			{
    			    DestroyObject(k);
			    SendClientMessage(i,COLOR_YELLOW,"3");
                            CreateObject(ObjectsWithLOD[j][modelid],ObjectsWithLOD[j][X],ObjectsWithLOD[j][Y],ObjectsWithLOD[j][Z],ObjectsWithLOD[j][rX],ObjectsWithLOD[j][rY],ObjectsWithLOD[j][rY]);
			    SendClientMessage(i,COLOR_YELLOW,"4");
			    NearObject[i] = 0;
			}
		    }
		}
	    }
	}
    }
}

GetPlayerDistanceToPointEx(playerid,Float:x,Float:y,Float:z)
{
	new Float:x1,Float:y1,Float:z1;
	new Float:tmpdis;
	GetPlayerPos(playerid,x1,y1,z1);
	tmpdis = floatsqroot(floatpower(floatabs(floatsub(x,x1)),2)+floatpower(floatabs(floatsub(y,y1)),2)+floatpower(floatabs(floatsub(z,z1)),2));
	return floatround(tmpdis);
}