#include <a_samp> new Float:vhealth[MAX_PLAYERS];new Float:velX[MAX_PLAYERS], Float:velY[MAX_PLAYERS], Float:velZ[MAX_PLAYERS]; forward OnVehicleLoseHealth(playerid, vehid, health); forward DrunkClean(playerid);forward Refix(playerid);forward FallSet(playerid);forward Controllable(playerid); public OnFilterScriptInit(){ print(\"\\n--------------------------------------\"); print(\" Damage behaviour v2.0 by Fade \"); print(\"--------------------------------------\\n\"); return 1;} public OnPlayerStateChange(playerid, newstate, oldstate){ if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER) { GetVehicleHealth(GetPlayerVehicleID(playerid), vhealth[playerid]); } return 1;} public OnVehicleRespray(playerid, vehicleid, color1, color2){ GetVehicleHealth(vehicleid, vhealth[playerid]); return 1;} public OnVehicleLoseHealth(playerid, vehid, health){ if(health >= 150) { new Float:x, Float:y, Float:z, Float:a; GetVehiclePos(vehid, x, y, z); GetVehicleZAngle(vehid, a); SetPlayerPos(playerid, x, y, z+2); GetVehicleVelocity(vehid, x, y, z); SetPlayerVelocity(playerid, velX[playerid], velY[playerid], z+1); SetPlayerDrunkLevel(playerid, 10000); SetTimerEx(\"FallSet\", 500, 0, \"i\", playerid); } if(health >= 500) SetPlayerHealth(playerid, 0); return 1;} public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid){ new Float:hp; GetPlayerHealth(playerid, hp); if(20 <= amount <= 40) { SetPlayerDrunkLevel(playerid, 25000); SetTimerEx(\"DrunkClean\", 5000, 0, \"i\", playerid); } else if(40 <= amount <= hp) { ClearAnimations(playerid); TogglePlayerControllable(playerid, 0); ApplyAnimation(playerid, \"PARACHUTE\", \"FALL_skyDive_DIE\",4,0,0,0,1,0); SetPlayerDrunkLevel(playerid, 10000); SetTimerEx(\"Refix\", 5000, 0, \"i\", playerid); } return 1;} public Refix(playerid){ ApplyAnimation(playerid, \"ped\", \"getup_front\",4,0,0,0,0,0); SetTimerEx(\"Controllable\",1800,0,\"i\",playerid); SetTimerEx(\"DrunkClean\",3000,0,\"i\",playerid); return 1;} public Controllable(playerid) return TogglePlayerControllable(playerid, 1);public FallSet(playerid) return SetPVarInt(playerid, \"FallFromVeh\", 1); public DrunkClean(playerid){ SetPlayerDrunkLevel(playerid,0); return 1;} public OnPlayerUpdate(playerid){ new Float:hp; GetPlayerHealth(playerid, hp); if(hp >= 99) SetPlayerDrunkLevel(playerid, 0); else if(hp <= 10) SetPlayerDrunkLevel(playerid, 1000); new vehicleid = GetPlayerVehicleID(playerid); if(vehicleid) { GetVehicleHealth(vehicleid, hp); if(hp != vhealth[playerid]) { if(hp < vhealth[playerid]) OnVehicleLoseHealth(playerid, vehicleid, floatround(vhealth[playerid] - hp)); vhealth[playerid] = hp; } GetVehicleVelocity(vehicleid, velX[playerid], velY[playerid], velZ[playerid]); } if(GetPVarInt(playerid, \"FallFromVeh\") == 1) { new Float:vX, Float:vY, Float:vZ; GetPlayerVelocity(playerid ,vX, vY, vZ); if(vZ == 0) { ClearAnimations(playerid); GetPlayerHealth(playerid, hp); hp -= 30.0; SetPlayerHealth(playerid, hp); if(hp <= 0.0) { SetPlayerDrunkLevel(playerid, 0); } else { SetPlayerDrunkLevel(playerid, 10000); SetTimerEx(\"Refix\", 5000, 0, \"i\", playerid); TogglePlayerControllable(playerid, 0); ApplyAnimation(playerid, \"PARACHUTE\", \"FALL_skyDive_DIE\",4,0,0,0,1,0); } SetPVarInt(playerid, \"FallFromVeh\", 0); } } return 1;}
Grat.Egy pár megjegyzés:AZ OnPlayerUpdate alatti részt igen csak lehetne optimalizálni.Az OnPlayerStateChange alatti rész se teljesen korrekt.Az OnPlayerGetHealth meg nincs használva sehol sem.Még egy:Ennek a global változónak a használata meg felesleges. new Float:vhp;Ha gondolod átírhatom egy általam optimalizált verzióra.
#include <a_samp>new Float:vhealth[MAX_PLAYERS];new Float:velX[MAX_PLAYERS], Float:velY[MAX_PLAYERS], Float:velZ[MAX_PLAYERS];forward OnVehicleLoseHealth(playerid, vehid, health);forward DrunkClean(playerid);forward Refix(playerid);forward FallSet(playerid);forward Controllable(playerid);publicOnFilterScriptInit(){print(\"\\n--------------------------------------\");print(\" Damage behaviour v2.0 by Fade \");print(\"--------------------------------------\\n\");return 1;}publicOnPlayerStateChange(playerid, newstate, oldstate){if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER){GetVehicleHealth(GetPlayerVehicleID(playerid), vhealth[playerid]);}return 1;}publicOnVehicleRespray(playerid, vehicleid, color1, color2){GetVehicleHealth(vehicleid, vhealth[playerid]);return 1;}publicOnVehicleLoseHealth(playerid, vehid, health){if(health >= 150){new Float:x, Float:y, Float:z, Float:a;GetVehiclePos(vehid, x, y, z);GetVehicleZAngle(vehid, a);SetPlayerPos(playerid, x, y, z+2);GetVehicleVelocity(vehid, x, y, z);SetPlayerVelocity(playerid, velX[playerid], velY[playerid], z+1);SetPlayerDrunkLevel(playerid, 10000);SetTimerEx(\"FallSet\", 500, 0, \"i\", playerid);}if(health >= 500) SetPlayerHealth(playerid, 0);return 1;}publicOnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid){newFloat:hp;GetPlayerHealth(playerid, hp);if(20 <= amount <= 40){SetPlayerDrunkLevel(playerid, 25000);SetTimerEx(\"DrunkClean\", 5000, 0, \"i\", playerid);}else if(40 <= amount <= hp){ClearAnimations(playerid);TogglePlayerControllable(playerid, 0);ApplyAnimation(playerid, \"PARACHUTE\", \"FALL_skyDive_DIE\",4,0,0,0,1,0);SetPlayerDrunkLevel(playerid, 10000);SetTimerEx(\"Refix\", 5000, 0, \"i\", playerid);}return 1;}public Refix(playerid){ApplyAnimation(playerid, \"ped\", \"getup_front\",4,0,0,0,0,0);SetTimerEx(\"Controllable\",1800,0,\"i\",playerid);SetTimerEx(\"DrunkClean\",3000,0,\"i\",playerid);return 1;}public Controllable(playerid) return TogglePlayerControllable(playerid, 1);public FallSet(playerid) return SetPVarInt(playerid, \"FallFromVeh\", 1);publicDrunkClean(playerid){SetPlayerDrunkLevel(playerid,0);return 1;}public OnPlayerUpdate(playerid){newFloat:hp;GetPlayerHealth(playerid, hp);if(hp >= 99) SetPlayerDrunkLevel(playerid, 0);else if(hp <= 10) SetPlayerDrunkLevel(playerid, 1000);newvehicleid = GetPlayerVehicleID(playerid);if(vehicleid){GetVehicleHealth(vehicleid, hp);if(hp != vhealth[playerid]){ if(hp < vhealth[playerid]) OnVehicleLoseHealth(playerid, vehicleid, floatround(vhealth[playerid] - hp)); vhealth[playerid] = hp;}GetVehicleVelocity(vehicleid, velX[playerid], velY[playerid], velZ[playerid]);}if(GetPVarInt(playerid, \"FallFromVeh\") == 1){new Float:vX, Float:vY, Float:vZ;GetPlayerVelocity(playerid ,vX, vY, vZ);if(vZ == 0){ ClearAnimations(playerid); GetPlayerHealth(playerid, hp); hp -= 30.0; SetPlayerHealth(playerid, hp); if(hp <= 0.0) { SetPlayerDrunkLevel(playerid, 0); } else { SetPlayerDrunkLevel(playerid, 10000); SetTimerEx(\"Refix\", 5000, 0, \"i\", playerid); TogglePlayerControllable(playerid, 0); ApplyAnimation(playerid, \"PARACHUTE\", \"FALL_skyDive_DIE\",4,0,0,0,1,0); } SetPVarInt(playerid, \"FallFromVeh\", 0);}}return 1;}
Ezt a repûlést nem lehet egy kicsit lejjebb vinni? Vagyis kb 2 métre lökjön ell?? :hmmm:
Ok elvileg meg is lenne gondolkoztam OnVehicleDamageStatusUpdate alkalmazásán is de ahhoz tesztelni kellene. (Az egész a jármû élet csökkenésének megállapításának a ténye.)Na mindegy a kód optimalizálásán alkottam kicsit, kivettem pár nem használt és felesleges dolgot, és átírtam pár vizsgálatokat. (az OnPlayerUpdate alatt változott talán a legtöbbet)Lehetne még optimalizálni, de ahhoz több teszt és idõ legfõképp idõ kellene. Jha igen nem kell a nevemet feltüntetni nem az én szkriptem. Akkor a változat: #include <a_samp>new Float:vhealth[MAX_PLAYERS];new Float:velX[MAX_PLAYERS], Float:velY[MAX_PLAYERS], Float:velZ[MAX_PLAYERS];forward OnVehicleLoseHealth(playerid, vehid, health);forward DrunkClean(playerid);forward Refix(playerid);forward FallSet(playerid);forward Controllable(playerid);publicOnFilterScriptInit(){print(\"\\n--------------------------------------\");print(\" Damage behaviour v2.0 by Fade \");print(\"--------------------------------------\\n\");return 1;}publicOnPlayerStateChange(playerid, newstate, oldstate){if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER){GetVehicleHealth(GetPlayerVehicleID(playerid), vhealth[playerid]);}return 1;}publicOnVehicleRespray(playerid, vehicleid, color1, color2){GetVehicleHealth(vehicleid, vhealth[playerid]);return 1;}publicOnVehicleLoseHealth(playerid, vehid, health){if(health >= 150){new Float:x, Float:y, Float:z, Float:a;GetVehiclePos(vehid, x, y, z);GetVehicleZAngle(vehid, a);SetPlayerPos(playerid, x, y, z+2);GetVehicleVelocity(vehid, x, y, z);SetPlayerVelocity(playerid, velX[playerid], velY[playerid], z+1);SetPlayerDrunkLevel(playerid, 10000);SetTimerEx(\"FallSet\", 500, 0, \"i\", playerid);}if(health >= 500) SetPlayerHealth(playerid, 0);return 1;}publicOnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid){newFloat:hp;GetPlayerHealth(playerid, hp);if(20 <= amount <= 40){SetPlayerDrunkLevel(playerid, 25000);SetTimerEx(\"DrunkClean\", 5000, 0, \"i\", playerid);}else if(40 <= amount <= hp){ClearAnimations(playerid);TogglePlayerControllable(playerid, 0);ApplyAnimation(playerid, \"PARACHUTE\", \"FALL_skyDive_DIE\",4,0,0,0,1,0);SetPlayerDrunkLevel(playerid, 10000);SetTimerEx(\"Refix\", 5000, 0, \"i\", playerid);}return 1;}public Refix(playerid){ApplyAnimation(playerid, \"ped\", \"getup_front\",4,0,0,0,0,0);SetTimerEx(\"Controllable\",1800,0,\"i\",playerid);SetTimerEx(\"DrunkClean\",3000,0,\"i\",playerid);return 1;}public Controllable(playerid) return TogglePlayerControllable(playerid, 1);public FallSet(playerid) return SetPVarInt(playerid, \"FallFromVeh\", 1);publicDrunkClean(playerid){SetPlayerDrunkLevel(playerid,0);return 1;}public OnPlayerUpdate(playerid){newFloat:hp;GetPlayerHealth(playerid, hp);if(hp >= 99) SetPlayerDrunkLevel(playerid, 0);else if(hp <= 10) SetPlayerDrunkLevel(playerid, 1000);newvehicleid = GetPlayerVehicleID(playerid);if(vehicleid){GetVehicleHealth(vehicleid, hp);if(hp != vhealth[playerid]){ if(hp < vhealth[playerid]) OnVehicleLoseHealth(playerid, vehicleid, floatround(vhealth[playerid] - hp)); vhealth[playerid] = hp;}GetVehicleVelocity(vehicleid, velX[playerid], velY[playerid], velZ[playerid]);}if(GetPVarInt(playerid, \"FallFromVeh\") == 1){new Float:vX, Float:vY, Float:vZ;GetPlayerVelocity(playerid ,vX, vY, vZ);if(vZ == 0){ ClearAnimations(playerid); GetPlayerHealth(playerid, hp); hp -= 30.0; SetPlayerHealth(playerid, hp); if(hp <= 0.0) { SetPlayerDrunkLevel(playerid, 0); } else { SetPlayerDrunkLevel(playerid, 10000); SetTimerEx(\"Refix\", 5000, 0, \"i\", playerid); TogglePlayerControllable(playerid, 0); ApplyAnimation(playerid, \"PARACHUTE\", \"FALL_skyDive_DIE\",4,0,0,0,1,0); } SetPVarInt(playerid, \"FallFromVeh\", 0);}}return 1;} [/quote]Köszönöm. Azért megemlítettem a neved, hogy te optimalizáltad.