User:DracoBlue/DGTAsa

From Multi Theft Auto: Wiki
< User:DracoBlue
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Implementation

function inheritsFrom( baseClass )
 
	local new_class = {}
	local class_mt = { __index = new_class }
	
	function new_class:create()
		local newinst = {}
		setmetatable( newinst, class_mt )
		return newinst
	end
	
	if nil ~= baseClass then
		setmetatable( new_class, { __index = baseClass } )
	end
	
	-- Implementation of additional OO properties starts here --
	
	-- Return the class object of the instance
	function new_class:class()
		return new_class
	end
	
	-- Return the super class object of the instance
	function new_class:superClass()
		return baseClass
	end
	
	-- Return true if the caller is an instance of theClass
	function new_class:isa( theClass )
		local b_isa = false
	
		local cur_class = new_class
	
		while ( nil ~= cur_class ) and ( false == b_isa ) do
		if cur_class == theClass then
			b_isa = true
		else
			cur_class = cur_class:superClass()
		end
		end
	
		return b_isa
	end
	
	return new_class
end

module("GTAsa")

---
-- The GTAElement
-- @class table
-- @name GTAElement
GTAElement=inheritsFrom(nil)
GTAElement.ID=nil
function GTAElement:className() return "GTAElement" end

---
-- Get Element's `key`-Data
-- @param key string Key of data
-- @return Content
function GTAElement:getData(key)
	return getElementData(self.ID,key)
end

---
-- Set Element's `key`-Data
-- @param key string Key of data
-- @param value Value to set.
function GTAElement:setData(key,value)
	setElementData(self.ID,key,value)
end

---
-- Get current Position of the Element
-- @return x, y, z
function GTAElement:Position()
	return getElementPosition(self.ID)
end



---
-- The GTAPlayer
-- @name GTAPlayer
GTAPlayer=inheritsFrom(GTAElement)
function GTAPlayer:className() return "GTAPlayer" end

---
-- Give a specific amount of ammo of a weapon to the player
-- @param w_id int WeaponID
-- @param ammo int Amount of Ammo
function GTAPlayer:giveWeapon(w_id,ammo)
	giveWeapon(self.ID,w_id,ammo)
end

---
-- Get current ping of the player
-- @return int value
function GTAPlayer:Ping()
	return getPlayerPing(self.ID)
end

---
-- Get current name of the player
-- @return string name
function GTAPlayer:Name()
	return getClientName(self.ID)
end

---
-- Get current rotation of the player
-- @return float value
function GTAPlayer:Rotation()
	return getPlayerRotation(self.ID)
end

---
-- Get current amount of health points of player
-- @return int Health of the player
function GTAPlayer:Health()
	return getPlayerHealth(self.ID)
end

---
-- Set players current health points
-- @param val int New amount of health a player has
-- @return If it was possible
function GTAPlayer:setHealth(val)
	return setPlayerHealth(self.ID,val)
end

---
-- Let a player die by the hand of an attacker
-- @param attacker ID of the attacker
-- @param weapon The weapon the attacker used
-- @param bodypart The bodypart, which was hit
-- @return bool True if it was possible 
function GTAPlayer:die(attacker,weapon,bodypart)
	return killPlayer(self.ID,attacker,weapon,bodypart)
end

---
-- Check wether player is dead or not
-- @return bool True if the player is dead 
function GTAPlayer:isDead()
	return isPlayerDead(self.ID)
end

---
-- Check wether player is alive or not
-- @return bool True if the player is alive 
function GTAPlayer:isAlive()
	return not isPlayerDead(self.ID)
end

---
-- Check wether player is ducked or not
-- @return bool True if the player is ducked 
function GTAPlayer:isDucked()
	return isPlayerDucked(self.ID)
end

Usage

p = GTAPlayer:create()
p.ID=source;
p:setHealth(p:Health()-10)