• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

chat gpt keeps blowing my mind

Status
Not open for further replies.
Level 21
Joined
Mar 29, 2020
Messages
1,237
can you write a fireball spell in jass code? (everything else here is the untouched response)


Certainly! Here is a simple example of a fireball spell written in JASS (the scripting language used in the popular video game Warcraft III):


JASS:
function SpellCast_Fireball takes nothing returns nothing
local unit caster = GetTriggerUnit()
local location target = GetSpellTargetLoc()
local real damage = 50.0
    local string spellName = "fireball"

// Check if the caster has enough mana to cast the spell
if GetUnitState(caster, UNIT_STATE_MANA) < GetUnitAbilityManaCost(caster, spellName) then
        return
    endif

// Create the fireball projectile
local projectile proj = AddProjectile(spellName, target, target)
SetProjectileMoveSpeed(proj, 1000)

// Damage units within the explosion radius
call GroupEnumUnitsInRange(GetSpellTargetLoc(), 250.0, null)
    loop
local unit target = GetEnumUnit()
        if target != null then
call DamageUnit(target, damage, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_MAGIC)
        endif
    endloop
endfunction

This code defines a function called SpellCast_Fireball that takes no arguments and returns no value. The function creates a fireball projectile that travels towards a target location, and damages any units within a 250-unit radius of the target location when it explodes.
I hope this helps! Let me know if you have any other questions.
 
Level 14
Joined
Dec 12, 2012
Messages
1,007
I find it quite amazing how many errors can be packed into such a small code snippet...

  • There is no native GetUnitAbilityManaCost, should be BlzGetUnitAbilityManaCost instead.
  • BlzGetUnitAbilityManaCost however takes three arguments, not two. It doesn't take any argument of type string.
  • GroupEnumUnitsInRange takes five arguments, not three.
  • GetSpellTargetLoc returns a location, which is incompatible to the first argument of GroupEnumUnitsInRange, which expects a group instead (however, no group is used here at all).
  • Calling GetEnumUnit in a loop like that will not work. Presumably that should be something like FirstOfGroup instead, in combination with GroupRemoveUnit. Also the exitwhen condition is missing, so that loop will just hit the OP limit and crash.
  • There is no native projectile, AddProjectile or SetProjectileMoveSpeed. If it relies on a projectile system, that should be at least referenced. I am not aware however of a projectile system with a function that is called like AddProjectile(spellName, target, target) (why two times target?)
  • There is no native DamageUnit, there is UnitDamageTarget (which takes however eight arguments instead of four). Even if a custom DamageUnit function would be used, that function should be referenced/defined. Also it is unclear how experience would be assigned correctly to the damage dealer, as this function takes only one unit as argument (the target), but not the damage dealer. So the caster would not get exp.
  • local unit target redeclares the identifier local location target, which is invalid.
  • As DSG already mentioned, local variables must be declared at the top of a function and functions must be called with call.

So, pretty much everything is wrong.

Appart from that it seems wrong that the projectile is created and does damage at the same time, expecially since it is "assigned" a finite movement speed. Logically, the projectile should deal damage once it arrives at the target, not at the instant it is casted. The code however can not achieve this. Also, it only checks if the caster has enough mana, but it does not adjust the mana of the caster accordingly (could be done with SetUnitState).

Don't know how Chat GPT generates its code but it seems it just randomly glues code snippets together without any regards for functionality or even valid syntax.
 
Last edited:
Status
Not open for further replies.
Top