onfirstspawn = OnCharacterEnterVehicle(
function(player, vehicle)
while IsCharacterHuman(player) and GetEntityClass(vehicle) == GetEntityClassPtr("rep_hover_barcspeeder") do
SetProperty(GetCharacterVehicle(player), "AddHealth", 200)
end
end
)
and when i use barcspeeder bf2 crash and not message of severity asociated to it :S please help
onfirstspawn = OnCharacterEnterVehicle(
function(player, vehicle)
while IsCharacterHuman(player) and GetEntityClass(vehicle) == GetEntityClassPtr("rep_hover_barcspeeder") do
SetProperty(GetCharacterVehicle(player), "AddHealth", 200)
end
end
)
onfirstspawn = OnCharacterEnterVehicle(
function(player, vehicle)
if IsCharacterHuman(player) and GetEntityClass(vehicle) == GetEntityClassPtr("rep_hover_barcspeeder") then
SetProperty(GetCharacterVehicle(player), "AddHealth", 200)
end
end
)
Remember, there is no such thing as a "While Do" it's always "If Then", and before you go making up code look up what it should be first.
myers73 wrote:he want it to only have addhealth when you are in it. Better to just also add a function for if the vehicle is empty to give it AddHealth -200
i dont know how make it without while and i dont know how using your way :S
bobfinkl wrote:Remember, there is no such thing as a "While Do" it's always "If Then", and before you go making up code look up what it should be first.
"While" is a conditional statement just like "if," and yes, it's perfectly valid. The original code posted above doesn't have a break condition to the while loop, and it's probably getting some kind of overflow error. I wouldn't use "while" to define perpetual states of being like the original post's code does - only use while to iterate through something with definable steps.
To fix the code, make two conditional statements, one for when a character is on the vehicle and one for when it is not.
Maveritchell wrote:To fix the code, make two conditional statements, one for when a character is on the vehicle and one for when it is not.
i tried with help of myers but i didnt can get it, any idea suggestion or little lines ?
The code would be a partial script that says
"while playerisinvehicle, do addhealth+200"
and a different script that says
"while playerisnotinvehicle, do addhealth-200"
or something like that.I think
I'm thinking maybe addhealth 0 when outside the vehicle? If you set it to -200, you'd lose health.
There's not much point in doing this anyway is there? as the vehicle would still lose health and die....vehicles have a differenent health bar i'm pretty sure. If you destroy a speeder, you die no matter how much health you have, same with hovercraft and space vehicles, unless the addhealth affects the vehicle instead?
Maveritchell wrote:To fix the code, make two conditional statements, one for when a character is on the vehicle and one for when it is not.
i tried with help of myers but i didnt can get it, any idea suggestion or little lines ?
The code would be a partial script that says
"while playerisinvehicle, do addhealth+200"
and a different script that says
"while playerisnotinvehicle, do addhealth-200"
or something like that.I think
No. No. Don't use a while loop for this. AddHealth is already a self-repeating property, there's no reason to apply it over and over and over. Unless you are using while to iterate through something (just like I said above) don't use it.
If you were dead-set on using a while loop (why, I don't know), you could write something like this:
vehicleaddhealth = OnCharacterEnterVehicle(
function(player, vehicle)
if IsCharacterHuman(player) and GetEntityClass(vehicle) == FindEntityClass("rep_hover_barcspeeder") then
SetProperty(GetEntityName(vehicle), "AddHealth", 200)
vehloop = GetCharacterVehicle(player)
while vehloop do
vehloop = GetCharacterVehicle(player)
if not GetCharacterVehicle(player) then
SetProperty(GetEntityName(vehicle), "AddHealth", 0)
end
end
end
end
)
It iterates through nothing, but whenever the player is no longer on a vehicle it breaks the loop and removes the addhealth. It still might give you a crash; I don't know if the while loop will handle that continual referencing that you're asking it to do.
I'm not exactly sure what you're trying to do. Do you want the vehicle to gain health/heal at a rate of 200 per second while a player is in it or do you want the vehicle's health to increase by 200 only once when a player enters the vehicle?
Also, is this the only type of vehicle you have on your map?
[RDH]Zerted wrote:I'm not exactly sure what you're trying to do. Do you want the vehicle to gain health/heal at a rate of 200 per second while a player is in it or do you want the vehicle's health to increase by 200 only once when a player enters the vehicle?
Also, is this the only type of vehicle you have on your map?
the first one, only i want vehicle have regen 200 per seconds when i (player ) am using it when i out i want this havent regen 200
MAV: you are a master really, i will test your code now many thanks really and is the first time i see vehloop code
vehRegen = OnCharacterEnterVehicle(
function(player, vehicle)
if IsCharacterHuman(player) and GetEntityClass(vehicle) == GetEntityClassPtr("rep_hover_barcspeeder") then
SetProperty(GetCharacterVehicle(player), "AddHealth", 200)
end
end
)
vehStopRegen = OnCharacterExitVehicle(
function(player, vehicle)
if IsCharacterHuman(player) and GetEntityClass(vehicle) == GetEntityClassPtr("rep_hover_barcspeeder") then
SetProperty(GetCharacterVehicle(player), "AddHealth", -200)
end
end
)
vehRegen = OnCharacterEnterVehicle(
function(player, vehicle)
if IsCharacterHuman(player) and GetEntityClass(vehicle) == GetEntityClassPtr("rep_hover_barcspeeder") then
SetProperty(GetCharacterVehicle(player), "AddHealth", 200)
end
end
)
vehStopRegen = OnCharacterExitVehicle(
function(player, vehicle)
if IsCharacterHuman(player) and GetEntityClass(vehicle) == GetEntityClassPtr("rep_hover_barcspeeder") then
SetProperty(GetCharacterVehicle(player), "AddHealth", -200)
end
end
)
trying now i cant discover which is the different between GetEntityClassPtr("rep_hover_barcspeeder") and FindEntityClass("rep_hover_barcspeeder")
EDIT: this work but again when i exit of vehicle this kept his regen :S
vehRegenBigAssFunction = OnCharacterSpawn(
function(player)
if IsCharacterHuman(player) then
vehRegen = OnCharacterEnterVehicle(
function(player, vehicle)
if GetEntityClass(vehicle) == GetEntityClassPtr("rep_hover_barcspeeder") then
theVeh = (GetCharacterVehicle(player)
SetProperty(theVeh, "AddHealth", 200)
end
end
)
vehStopRegen = OnCharacterExitVehicle(
function(player, vehicle)
if GetEntityClass(vehicle) == GetEntityClassPtr("rep_hover_barcspeeder") then
SetProperty(theVeh, "AddHealth", -200)
end
end
)
end
end
)
Deviss on Xfire wrote:
work but when i exit this kept regen :S
try this then
Hidden/Spoiler:
vehRegenBigAssFunction = OnCharacterSpawn(
function(player)
if IsCharacterHuman(player) then
vehRegen = OnCharacterEnterVehicle(
function(player, vehicle)
if GetEntityClass(vehicle) == GetEntityClassPtr("rep_hover_barcspeeder") then
theVeh = (GetCharacterVehicle(player)
SetProperty(theVeh, "AddHealth", 200)
end
end
)
vehStopRegen = OnCharacterExitVehicle(
function(player, vehicle)
if GetEntityClass(vehicle) == GetEntityClassPtr("rep_hover_barcspeeder") then
SetProperty(theVeh, "AddHealth", -200)
end
end
)
end
end
)
agian this still keep his regen after i exit of vehicle :S , i will try make one mix between your and mav one
EDIT: i tried this using mav one and i got no crash, but anyway keep regen after i exit vehicle
vehicleaddhealth = OnCharacterEnterVehicle(
function(player, vehicle)
if IsCharacterHuman(player) and GetEntityClass(vehicle) == GetEntityClassPtr("rep_hover_barcspeeder") then
SetProperty(GetEntityName(vehicle), "AddHealth", 200)
vehloop = GetCharacterVehicle(player)
if vehloop then
vehloop = GetCharacterVehicle(player)
if not GetCharacterVehicle(player) then
SetProperty(GetEntityName(vehicle), "AddHealth", 0)
end
end
end
end
)
There is no good way to determine when a player leaves a vehicle. I only have a minute so I can't do any code, but what you want to do is when you enter the vehicle, setup and start a repeating timer. Each time the timer goes off check to see if the player is still in the same vehicle. If so, do nothing. If not, then remove the AddHealth.
A different way if the player is always the same class would be to make that class have a high auto-repair rate for vehicles. I don't know if that fits into your map or not.
[RDH]Zerted wrote:There is no good way to determine when a player leaves a vehicle. I only have a minute so I can't do any code, but what you want to do is when you enter the vehicle, setup and start a repeating timer. Each time the timer goes off check to see if the player is still in the same vehicle. If so, do nothing. If not, then remove the AddHealth.
A different way if the player is always the same class would be to make that class have a high auto-repair rate for vehicles. I don't know if that fits into your map or not.
oh yeah i never think it, addhealth finish when i change of vehicle name, but how will be the code xD? (of course when you have time )
Deviss on Xfire wrote:
work but when i exit this kept regen :S
try this then
Hidden/Spoiler:
vehRegenBigAssFunction = OnCharacterSpawn(
function(player)
if IsCharacterHuman(player) then
vehRegen = OnCharacterEnterVehicle(
function(player, vehicle)
if GetEntityClass(vehicle) == GetEntityClassPtr("rep_hover_barcspeeder") then
theVeh = (GetCharacterVehicle(player)
SetProperty(theVeh, "AddHealth", 200)
end
end
)
vehStopRegen = OnCharacterExitVehicle(
function(player, vehicle)
if GetEntityClass(vehicle) == GetEntityClassPtr("rep_hover_barcspeeder") then
SetProperty(theVeh, "AddHealth", -200)
end
end
)
end
end
)
agian this still keep his regen after i exit of vehicle :S , i will try make one mix between your and mav one
EDIT: i tried this using mav one and i got no crash, but anyway keep regen after i exit vehicle
Hidden/Spoiler:
[code] vehicleaddhealth = OnCharacterEnterVehicle(
function(player, vehicle)
if IsCharacterHuman(player) and GetEntityClass(vehicle) == GetEntityClassPtr("rep_hover_barcspeeder") then
SetProperty(GetEntityName(vehicle), "AddHealth", 200)
vehloop = GetCharacterVehicle(player)
if vehloop then
vehloop = GetCharacterVehicle(player)
if not GetCharacterVehicle(player) then
SetProperty(GetEntityName(vehicle), "AddHealth", 0)
end
end
end
end
)[/code]
any idea :S?
If you used the code you just posted, you didn't use the code I posted. I wrote it so that it has to use the while loop. Here's the code again:
vehicleaddhealth = OnCharacterEnterVehicle(
function(player, vehicle)
if IsCharacterHuman(player) and GetEntityClass(vehicle) == FindEntityClass("rep_hover_barcspeeder") then
SetProperty(GetEntityName(vehicle), "AddHealth", 200)
vehloop = GetCharacterVehicle(player)
while vehloop do
vehloop = GetCharacterVehicle(player)
if not GetCharacterVehicle(player) then
SetProperty(GetEntityName(vehicle), "AddHealth", 0)
end
end
end
end
)
Deviss on Xfire wrote:
work but when i exit this kept regen :S
try this then
Hidden/Spoiler:
vehRegenBigAssFunction = OnCharacterSpawn(
function(player)
if IsCharacterHuman(player) then
vehRegen = OnCharacterEnterVehicle(
function(player, vehicle)
if GetEntityClass(vehicle) == GetEntityClassPtr("rep_hover_barcspeeder") then
theVeh = (GetCharacterVehicle(player)
SetProperty(theVeh, "AddHealth", 200)
end
end
)
vehStopRegen = OnCharacterExitVehicle(
function(player, vehicle)
if GetEntityClass(vehicle) == GetEntityClassPtr("rep_hover_barcspeeder") then
SetProperty(theVeh, "AddHealth", -200)
end
end
)
end
end
)
agian this still keep his regen after i exit of vehicle :S , i will try make one mix between your and mav one
EDIT: i tried this using mav one and i got no crash, but anyway keep regen after i exit vehicle
Hidden/Spoiler:
[code] vehicleaddhealth = OnCharacterEnterVehicle(
function(player, vehicle)
if IsCharacterHuman(player) and GetEntityClass(vehicle) == GetEntityClassPtr("rep_hover_barcspeeder") then
SetProperty(GetEntityName(vehicle), "AddHealth", 200)
vehloop = GetCharacterVehicle(player)
if vehloop then
vehloop = GetCharacterVehicle(player)
if not GetCharacterVehicle(player) then
SetProperty(GetEntityName(vehicle), "AddHealth", 0)
end
end
end
end
)[/code]
any idea :S?
If you used the code you just posted, you didn't use the code I posted. I wrote it so that it has to use the while loop. Here's the code again:
vehicleaddhealth = OnCharacterEnterVehicle(
function(player, vehicle)
if IsCharacterHuman(player) and GetEntityClass(vehicle) == FindEntityClass("rep_hover_barcspeeder") then
SetProperty(GetEntityName(vehicle), "AddHealth", 200)
vehloop = GetCharacterVehicle(player)
while vehloop do
vehloop = GetCharacterVehicle(player)
if not GetCharacterVehicle(player) then
SetProperty(GetEntityName(vehicle), "AddHealth", 0)
end
end
end
end
)
i know and i tested by make crash :S , maybe because WHILE? but supposly while must work without problems in lua, but always i use it cause crash :S , for this reason i need if zerted can save me, or yes or yes i need use IF for no crash xD