Skocz do zawartości

  • Zaloguj korzystając z Facebooka Zaloguj korzystając z Twittera Zaloguj przez Steam Zaloguj poprzez Google      Logowanie »   
  • Rejestracja

Witamy w Nieoficjalnym polskim support'cie AMX Mod X

Witamy w Nieoficjalnym polskim support'cie AMX Mod X, jak w większości społeczności internetowych musisz się zarejestrować aby móc odpowiadać lub zakładać nowe tematy, ale nie bój się to jest prosty proces w którym wymagamy minimalnych informacji.

  • Rozpoczynaj nowe tematy i odpowiedaj na inne
  • Zapisz się do tematów i for, aby otrzymywać automatyczne uaktualnienia
  • Dodawaj wydarzenia do kalendarza społecznościowego
  • Stwórz swój własny profil i zdobywaj nowych znajomych
  • Zdobywaj nowe doświadczenia

Dołączona grafika Dołączona grafika

Guest Message by DevFuse
 

Zdjęcie
Modyfikacja

Zmiana czasu

Modyfikacja

  • Zamknięty Temat jest zamknięty
Brak odpowiedzi do tego tematu

#1 no name

    Wszechpomocny

  • Użytkownik

Reputacja: 56
Pomocny

  • Postów:387
  • GG:
  • Steam:steam
  • Imię:Wojciech
  • Lokalizacja:Kraków
Offline

Napisano 07.10.2009 14:00

Dało by rade przerobić ten plugin tak aby godzina była w czasie GMT+2 a nie GMT+0??

/* 
 * Automatic weather plugin
 *
 * CVARS:
 *  weather_minlight	<0-25> D: 24	| 24 Darkest 0 Brightest
 *  weather_maxlight	<0-25> D: 10	| 24 Darkest 0 Brightest
 *  weather_currhour	<0-23> D: 0	| Manually sets daytime 0 = off
 *  weather_region	<recioncode>	| e.g. 0050 for berlin (must be 4 digits)
 *
 *
 * CL_COMMANDS
 *
 * say /weatherinfo	- shows current conditions
 */

#include <amxmodx>
#include <sockets>
#include <fakemeta>
#include <nvault>

#pragma semicolon 1

#define PLUGIN	"Auto Weather"
#define AUTHOR	"TeddyDesTodes"
#define VERSION	"0.85"

//#define DEBUG	// uncomment this for debugmode
#define STEP_DELAY 0.5
#define fm_create_entity(%1)	engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, %1))
#define fm_set_lights(%1)	engfunc(EngFunc_LightStyle, 0, %1)

#define Radian2Degree(%1) (%1 * 180.0 / M_PI)

const OFFSET_AMBIENCE = (1<<0);

new g_cvar_minlight, g_cvar_maxlight, g_cvar_region, g_cvar_currhour;
new g_sckweather, g_temp, g_curr_temp, g_temp_min, g_weather, g_hum;
new g_env, g_fog, g_sunRise[2], g_sunSet[2],g_location[32];
new Float:g_fNextStep[33];
new g_vault;
new const g_szSnowStepSound[][] = {
	"player/pl_snow1.wav",
	"player/pl_snow2.wav",
	"player/pl_snow3.wav",
	"player/pl_snow4.wav",
	"player/pl_snow5.wav",
	"player/pl_snow6.wav"
};
new g_LightLevel[][]	= { "z","y","x","w","v","u","t","s","r","q","p","o","n","m","l","k","j","i","h","g","f","e","d","c","b","a" };
new g_env_name[][]	= { "","sunny","rain","snow" };
new g_weather_name[][]	= { "","good","cloudy","partially cloudy" };
new g_skysuf[6][3]	= { "up", "dn", "ft", "bk", "lf", "rt" };

//					morning noon normal afternoon night
					// sunny
new g_skynames[][] = { "sunny","3dm_bikini","52h05","sunny","52h03",
					// partlyclouded
					   "blue","52h05","de_dune_","sunset1","paris_night",
					// clouded
					   "sunbeams_","CCCP","CCCP","CCCP","52h03",
					// foggy
					   "CCCP","CCCP","CCCP","CCCP","CCCP"};
public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR);
	
	register_cvar("autoweather_version", VERSION, FCVAR_SERVER);
	g_cvar_minlight	= register_cvar("weather_minlight","24");
	g_cvar_maxlight	= register_cvar("weather_maxlight","7");
	g_cvar_currhour	= register_cvar("weather_currhour","0");
	g_cvar_region	= register_cvar("weather_region","4508");
	register_cvar("weather_hud","200");
	register_clcmd("say /pogoda", "showinfo");
	register_forward(FM_PlayerPreThink, "fwd_PlayerPreThink", 0);
	get_weather();
	daylight();
	set_task(15.0, "daylight", _,_,_, "b");
}
public plugin_end(){
	nvault_close(g_vault);
}
public plugin_precache(){
	g_vault = nvault_open("weather");
	makeweather();
}
public client_putinserver(id) {
	client_cmd(id,"cl_weather 1");
	set_task(15.0,"daylight");
}

public showinfo(id) {
	set_hudmessage (0, 100, 255, 0.03, 0.50, 0, 4.0, 7.0, 1.0, 1.0, -1);
	show_hudmessage(id, "Location: %s^nTemp: %dC^nCurr Condition: %s^nVisibility: %s^nHumidity: %d%s^nSunrise: %d:%d^nSunset: %d:%d",g_location,g_curr_temp,g_env_name[g_env],g_weather_name[g_weather],g_hum,"%",g_sunRise[0],g_sunRise[1],g_sunSet[0],g_sunSet[1]);
	client_print(id, print_console, "Location: %s | Temp: %dC | Curr Condition: %s | Visibility: %s | Humidity: %d^% | Sunrise: %d:%d | Sunset: %d:%d",g_location,g_curr_temp,g_env_name[g_env],g_weather_name[g_weather],g_hum,g_sunRise[0],g_sunRise[1],g_sunSet[0],g_sunSet[1]);
}

public get_weather() {
	#if defined DEBUG
		log_amx("Hohle Wetter!");
	#endif
	
	new error, constring[512], region[5];
	
	get_pcvar_string(g_cvar_region,region,4);
	g_sckweather = socket_open("feeds.bbc.co.uk", 80, SOCKET_TCP, error);
	
	format(constring,511,"GET /weather/feeds/rss/5day/world/%s.xml HTTP/1.0^nHost: feeds.bbc.co.uk^n^n", region);
	write_web(constring);
	
	#if defined DEBUG
		log_amx(constring);
	#endif
	
	read_web();
}

public write_web(text[512])
    socket_send(g_sckweather, text, 511);
/** Later maybe getting more accurate weatherinfo
public read_obs(){
	
} 
*/
public read_web() {
	new buf[1024];
	socket_recv(g_sckweather, buf, 1024);
	//log_amx(buf);
	if(!equal(buf,"")) {
		if(containi(buf,"Forecast for ")>= 0){
			new out[32];
			copyc(out,32,buf[containi(buf,"Forecast for ")+13],'<');
			
			#if defined DEBUG
				log_amx("Position: %s",out);
			#endif
			g_location = out;
			nvault_set(g_vault,"location",out);
		}
		if(containi(buf,"Max Temp:")>= 0 && g_temp == 0) {
			new out[32];
			copy(out,3,buf[strfind(buf,"Max Temp:")+10]);
			replace(out,5,"&","");
			replace(out,5,"#","");
			
			#if defined DEBUG
				log_amx("Maxtemp %s",out);
			#endif
			nvault_set(g_vault,"maxtemp",out);
			g_temp = str_to_num(out);
		}
		if(containi(buf,"Min Temp:")>= 0 && g_temp_min == 0) {
			new out[32];
			copy(out,3,buf[strfind(buf,"Min Temp:")+10]);
			replace(out,5,"&","");
			replace(out,5,"#","");
			
			#if defined DEBUG
				log_amx("Mintemp %s",out);
			#endif
			nvault_set(g_vault,"mintemp",out);
			g_temp_min = str_to_num(out);
		}
		if(containi(buf,"Humidity:")>= 0 && g_hum == 0) {
			new out[32];
			copy(out,3,buf[strfind(buf,"Humidity:")+10]);
			replace(out,5,"%","");
			
			#if defined DEBUG
				log_amx("Humidity %s",out);
			#endif
			nvault_set(g_vault,"humidity",out);
			g_hum = str_to_num(out);
		}
		if(containi(buf,"Visibility:")>= 0 && g_weather == 0) {
			new out[32];
			#if defined DEBUG
				copy(out,31,buf[strfind(buf,"Visibility:")+12]);
			
				log_amx(out);
			#endif
			
			if(containi(out,"good") != -1) {
				#if defined DEBUG
					log_amx("Weather: good");
				#endif
				g_weather = 1;
			} else if(containi(out,"poor") != -1) {
				#if defined DEBUG
					log_amx("Weather: poor");
				#endif
				g_weather = 2;
			} else if(containi(out,"moderate") != -1) {
				#if defined DEBUG
					log_amx("Weather: moderate");
				#endif
				g_weather = 3;
			} else {
				#if defined DEBUG
					log_amx("Unknown weather: %s",out);
				#endif
				g_weather = 1;
			}
			new num[1];
			num_to_str(g_weather,num,1);
			nvault_set(g_vault,"weather",num);
		}
		if(g_env == 0) {
			new first = 2000;
			if(containi(buf,"rain,") > -1 && containi(buf,"rain,") < first) {
				first = containi(buf,"rain,");
				g_env = 2;
			}
			if(containi(buf,"drizzle,") > -1 && containi(buf,"drizzle,") < first){
				first = containi(buf,"drizzle,");
				g_env = 2;
			}
			if(containi(buf,"showers,") > -1 && containi(buf,"showers,") < first){
				first = containi(buf,"showers,");
				g_env = 2;
			}
			if(containi(buf,"sunny,") > -1 && containi(buf,"sunny,") < first){
				first = containi(buf,"sunny,");
				g_env = 1;
			}
			if(containi(buf,"sunny intervals,") > -1 && containi(buf,"sunny intervals,") < first){
				first = containi(buf,"sunny intervals,");
				g_env = 1;
			}
			if(containi(buf,"snow,") > -1 && containi(buf,"snow,") < first){
				first = containi(buf,"snow,");
				g_env = 3;
			}
			if(g_env !=0){
				new num[1];
				num_to_str(g_env,num,1);
				nvault_set(g_vault,"env",num);
			}
		}
		if(containi(buf,"Sunrise: ")>= 0 && g_sunRise[0] == 0 && g_sunRise[1] == 0) {
			new out[32];
			copy(out,5,buf[strfind(buf,"Sunrise: ")+9]);
			replace(out,5,"&","");
			
			#if defined DEBUG
				log_amx("Sunrise: %s",out);
			#endif
			
			new h[3],m[3];
			split(out,h,2,m,2,":");
			g_sunRise[0] = str_to_num(h);
			g_sunRise[1] = str_to_num(m);
			new num[3];
			num_to_str(g_sunRise[0],num,3);
			nvault_set(g_vault,"sunriseh",num);
			num_to_str(g_sunRise[1],num,3);
			nvault_set(g_vault,"sunrisem",num);
		}
		if(containi(buf,"Sunset: ")>= 0 && g_sunSet[0] == 0 && g_sunSet[1] == 0) {
			new out[32];
			copy(out,5,buf[strfind(buf,"Sunset: ")+8]);
			replace(out,5,"&","");
			
			#if defined DEBUG
				log_amx("Sunset: %s",out);
			#endif
			
			new h[3],m[3];
			split(out,h,2,m,2,":");
			g_sunSet[0] = str_to_num(h);
			g_sunSet[1] = str_to_num(m);
			new num[3];
			num_to_str(g_sunSet[0],num,3);
			nvault_set(g_vault,"sunseth",num);
			num_to_str(g_sunSet[1],num,3);
			nvault_set(g_vault,"sunsetm",num);
		}
		set_task(0.5,"read_web");
	} else {
		socket_close(g_sckweather);
	}
}

public makeweather() {
	new humi = nvault_get(g_vault,"humidity");
	new e = nvault_get(g_vault,"env");
	if(humi >90)
		makeFog(humi);
	
	switch ( e ) {
		case 2: {
			fm_create_entity("env_rain");
			//TO-DO ambient sound...
			precache_sound("ambience/drizzle.wav");
			new entity = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "ambient_generic"));
			set_pev(entity, pev_health, 10.0);
			set_pev(entity, pev_message,"ambience/drizzle.wav");
			set_pev(entity, pev_spawnflags, OFFSET_AMBIENCE);
			dllfunc(DLLFunc_Spawn, entity);
		}
		case 3: {
			fm_create_entity("env_snow");
			for(new i = 0 ; i < sizeof g_szSnowStepSound ; i++)
				precache_sound(g_szSnowStepSound[i]);
		}
		case 4: {
			fm_create_entity("env_rain");
			fm_create_entity("env_snow");
		}
	} 
	
	set_sky(humi);
}

public set_sky(humi) {
	new daytime, sunset, sunrise,temp[3];	
	sunset = nvault_get(g_vault,"sunseth");
	sunrise = nvault_get(g_vault,"sunriseh");
	
	get_time("%H",temp,2);
	new currhour = str_to_num(temp);
	
	if(currhour >= sunrise-1 && currhour <= sunrise+1)
		daytime = 0;
	else if (daytime == ((sunset-sunrise)/2)+sunrise)
		daytime = 1;		
	else if (currhour >= sunset-1 && currhour <= sunset+1)
		daytime = 3;
	else if (daytime < sunrise-1 || daytime > sunset+1)
		daytime = 4;
	else
		daytime = 2;
	
	
	if(humi <= 90) {
		precache_sky(g_skynames[((nvault_get(g_vault,"weather")-1)*5)+daytime]);
	} else
		precache_sky(g_skynames[(3*5)+daytime]);
	
}

public precache_sky(const skyname[]) {
	new bool:pres = true;
	static file[35];
	
	for(new i = 0; i < 6; ++i) {
		formatex(file, 34, "gfx/env/%s%s.tga", skyname, g_skysuf[i]);
		if(file_exists(file)){
			precache_generic(file);
		} else {
			pres = false;
			break;
		}
	}
	
	if(pres)
		set_cvar_string("sv_skyname", skyname);
}

public daylight() {
	new sunset = g_sunSet[0] +1;
	new sunrise = g_sunRise[0] -1;
	new totalDayLight = sunset-sunrise;
	new time[3];
	get_time("%H",time,2);
	new currHour = str_to_num(time);
	
	if(get_pcvar_num(g_cvar_currhour) > 0)
		currHour = get_cvar_num("weather_currhour");
	
	new light,lightspan = get_pcvar_num(g_cvar_minlight)-get_pcvar_num(g_cvar_maxlight);
	new tempspan = g_temp-g_temp_min;
	new noon = (totalDayLight/2)+sunrise;
	if(currHour < noon){
		if(currHour < sunrise){
			light = get_pcvar_num(g_cvar_minlight);
			g_curr_temp = g_temp_min;
		}else{
			new prenoon = noon-sunrise;
			light = get_pcvar_num(g_cvar_minlight) - (currHour-sunrise)*(lightspan/prenoon);
			g_curr_temp = g_temp-(currHour-sunrise)*(tempspan/prenoon);
			//log_amx("%d %d %d %d",lightspan,prenoon,lightspan/prenoon,currHour);
		}
	}
	if(currHour == noon){
		light = get_pcvar_num(g_cvar_maxlight);
		g_curr_temp = g_temp;
	}
	if(currHour > noon){
		
		if(currHour > sunset){
			light = get_pcvar_num(g_cvar_minlight);
			g_curr_temp = g_temp_min;
		}else{
			//light = get_cvar_num("weather_maxlight")-(currHour)*((minlight-get_cvar_num("weather_maxlight"))/(g_sunSet[0]-noon)))
			new postnoon = noon-sunrise;
			
			light = (currHour-noon)*(lightspan/postnoon)+get_pcvar_num(g_cvar_maxlight);
			g_curr_temp = (currHour-sunrise)*(tempspan/postnoon)+g_temp_min;
			if(light > get_pcvar_num(g_cvar_minlight)){
				light = get_pcvar_num(g_cvar_minlight);
			}
		}
	}
	
	//log_amx("%d %d %d",minlight,light,get_cvar_num("weather_maxlight"));
	//log_amx("%d %d",get_pcvar_num(g_cvar_maxlight),get_pcvar_num(g_cvar_minlight));
	#if defined DEBUG
		log_amx("%s %s %s",g_LightLevel[get_pcvar_num(g_cvar_minlight)],g_LightLevel[light],g_LightLevel[get_pcvar_num(g_cvar_maxlight)]);
	#endif
	//log_amx("%d %s %s",light,g_LightLevel[get_pcvar_num(g_cvar_minlight)],g_LightLevel[get_pcvar_num(g_cvar_maxlight)]);
	fm_set_lights(g_LightLevel[light]);
	new fogcolor = (get_pcvar_num(g_cvar_minlight)-light)*10+20;
	new form[12];
	//set model illumination ?!
	set_cvar_num ( "sv_skycolor_r",fogcolor );
	set_cvar_num ( "sv_skycolor_g",fogcolor );
	set_cvar_num ( "sv_skycolor_b",fogcolor );
	//fog color
	format(form,12,"%d %d %d",fogcolor,fogcolor,fogcolor);
	fm_set_kvd(g_fog,"rendercolor",form);
	
}

public makeFog(amount) {
		//g_fog = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_fog"));
		g_fog = fm_create_entity("env_fog");
		new Float:density = (0.0002*(amount-90))+0.001;
		new dens[7];
		float_to_str(density,dens,6);
		fm_set_kvd(g_fog,"density",dens);
		fm_set_kvd(g_fog,"rendercolor","200 200 200");
}
public fwd_PlayerPreThink(id)
{
	if(!is_user_alive(id))
		return FMRES_IGNORED;
	
	static Float:fGmTime ; fGmTime = get_gametime();
	if(g_fNextStep[id] < fGmTime)
	{
		if(fm_get_user_speed(id) && (pev(id, pev_flags) & FL_ONGROUND) && is_user_outside(id))
		{
			set_pev(id, pev_flTimeStepSound, 999);
			if(g_env == 3){
				engfunc(EngFunc_EmitSound, id, CHAN_AUTO, g_szSnowStepSound[random_num(0, sizeof g_szSnowStepSound - 1)], 0.5, ATTN_NORM, 0, PITCH_NORM);
			}
			g_fNextStep[id] = fGmTime + STEP_DELAY;
		}
	}
	return FMRES_IGNORED;
}
// DispatchKeyValue
stock fm_set_kvd(entity, const key[], const value[], const classname[] = "") {
	if (classname[0])
		set_kvd(0, KV_ClassName, classname);
	else {
		new class[32];
		pev(entity, pev_classname, class, sizeof class - 1);
		set_kvd(0, KV_ClassName, class);
	}

	set_kvd(0, KV_KeyName, key);
	set_kvd(0, KV_Value, value);
	set_kvd(0, KV_fHandled, 0);

	return dllfunc(DLLFunc_KeyValue, entity, 0);
}
//some stocks
stock Float:is_user_outside(id)
{
	new Float:vOrigin[3], Float:fDist;
	pev(id, pev_origin, vOrigin);
	
	fDist = vOrigin[2];
	
	while(engfunc(EngFunc_PointContents, vOrigin) == CONTENTS_EMPTY)
		vOrigin[2] += 5.0;
	
	if(engfunc(EngFunc_PointContents, vOrigin) == CONTENTS_SKY)
		return (vOrigin[2] - fDist);
	
	return 0.0;
}

stock Float:fm_get_user_speed(id)
{
	if(!is_user_connected(id))
		return 0.0;
	
	static Float:fVelocity[3];
	pev(id, pev_velocity, fVelocity);
	
	fVelocity[2] = 0.0;
	
	return vector_length(fVelocity);
}

Załączone pliki


  • +
  • -
  • 0





Również z jednym lub większą ilością słów kluczowych: Modyfikacja

Użytkownicy przeglądający ten temat: 0

0 użytkowników, 0 gości, 0 anonimowych