xan
10.08.2008, 20:33
Hi,
ich habe gestern angefangen LUA zu lernen und nun auch gleich ein zwei Fragen:
Zunächst, welchen Sinn hat das Semikolon (;)? Einige setzen es am ende jeder Funktion, andere lassen es komplett weg. Ich kann PHP und da ist es so, dass jede Funktion mit einem Semikolon abgeschlossen werden muss, ist das in LUA optional?
Wenn ich ein Script editiere, muss dann erst GMod neugestartet werden damit die Änderungen übernommen werden, oder gibt es einen Konsolenbefehl der dieses Erledigt?
PS: Mein erstes Script ;) (es funktioniert sogar)
function ParsePlayerText(ply, text)
//!health
if string.find( text, "!health") == 1 then //wenn "!health" an erster stelle
if ply:Alive() != true then //wenn Palyer nicht am leben
ply:ChatPrint( "You are dead.")
else
ply:SetHealth(ply:Health() + 100)
ply:ChatPrint( "Added 100 health.")
end
return ""
end
//!equip
if string.find( text, "!equip") == 1 then
if ply:Alive() != true then
ply:ChatPrint( "You are dead.")
else
ply:Give("weapon_crowbar")
ply:Give("weapon_physcannon")
ply:Give("weapon_physgun")
ply:Give("weapon_pistol")
ply:Give("weapon_357")
ply:Give("weapon_smg1")
ply:Give("weapon_ar2")
ply:Give("weapon_crossbow")
ply:Give("weapon_frag")
ply:Give("weapon_rpg")
ply:Give("gmod_camera")
ply:Give("gmod_tool")
ply:ChatPrint( "Added equipment.")
end
return ""
end
//!ammo
if string.find( text, "!ammo") == 1 then
if ply:Alive() != true then
ply:ChatPrint( "You are dead.")
else
ply:GiveAmmo(100,"pistol")
ply:GiveAmmo(100,"357")
ply:GiveAmmo(100,"smg1")
ply:GiveAmmo(100,"ar2")
ply:GiveAmmo(100,"ar2altfire")
ply:GiveAmmo(100,"crossbow")
ply:ChatPrint( "Added ammo.")
end
return ""
end
//!info
if string.find( text, "!info") == 1 then
ply:ChatPrint( "!health - Adds 100 health.")
ply:ChatPrint( "!equip - Adds all weapons")
ply:ChatPrint( "!ammo - Adds ammo")
return ""
end
return text
end
hook.Add("PlayerSay", "ParsePlayerText", ParsePlayerText)
MfG
xan
ich habe gestern angefangen LUA zu lernen und nun auch gleich ein zwei Fragen:
Zunächst, welchen Sinn hat das Semikolon (;)? Einige setzen es am ende jeder Funktion, andere lassen es komplett weg. Ich kann PHP und da ist es so, dass jede Funktion mit einem Semikolon abgeschlossen werden muss, ist das in LUA optional?
Wenn ich ein Script editiere, muss dann erst GMod neugestartet werden damit die Änderungen übernommen werden, oder gibt es einen Konsolenbefehl der dieses Erledigt?
PS: Mein erstes Script ;) (es funktioniert sogar)
function ParsePlayerText(ply, text)
//!health
if string.find( text, "!health") == 1 then //wenn "!health" an erster stelle
if ply:Alive() != true then //wenn Palyer nicht am leben
ply:ChatPrint( "You are dead.")
else
ply:SetHealth(ply:Health() + 100)
ply:ChatPrint( "Added 100 health.")
end
return ""
end
//!equip
if string.find( text, "!equip") == 1 then
if ply:Alive() != true then
ply:ChatPrint( "You are dead.")
else
ply:Give("weapon_crowbar")
ply:Give("weapon_physcannon")
ply:Give("weapon_physgun")
ply:Give("weapon_pistol")
ply:Give("weapon_357")
ply:Give("weapon_smg1")
ply:Give("weapon_ar2")
ply:Give("weapon_crossbow")
ply:Give("weapon_frag")
ply:Give("weapon_rpg")
ply:Give("gmod_camera")
ply:Give("gmod_tool")
ply:ChatPrint( "Added equipment.")
end
return ""
end
//!ammo
if string.find( text, "!ammo") == 1 then
if ply:Alive() != true then
ply:ChatPrint( "You are dead.")
else
ply:GiveAmmo(100,"pistol")
ply:GiveAmmo(100,"357")
ply:GiveAmmo(100,"smg1")
ply:GiveAmmo(100,"ar2")
ply:GiveAmmo(100,"ar2altfire")
ply:GiveAmmo(100,"crossbow")
ply:ChatPrint( "Added ammo.")
end
return ""
end
//!info
if string.find( text, "!info") == 1 then
ply:ChatPrint( "!health - Adds 100 health.")
ply:ChatPrint( "!equip - Adds all weapons")
ply:ChatPrint( "!ammo - Adds ammo")
return ""
end
return text
end
hook.Add("PlayerSay", "ParsePlayerText", ParsePlayerText)
MfG
xan