Difference between revisions of "User:DracoBlue/DGTAsa"

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
()
 
 
Line 1: Line 1:
 
==Implementation==
 
==Implementation==
 
<syntaxhighlight lang="lua">function inheritsFrom( baseClass )
 
<syntaxhighlight lang="lua">function inheritsFrom( baseClass )
 
+
 
local new_class = {}
 
local new_class = {}
 
local class_mt = { __index = new_class }
 
local class_mt = { __index = new_class }
Line 47: Line 47:
 
end
 
end
  
 +
module("GTAsa")
 +
 +
---
 +
-- The GTAElement
 +
-- @class table
 +
-- @name GTAElement
 
GTAElement=inheritsFrom(nil)
 
GTAElement=inheritsFrom(nil)
 
GTAElement.ID=nil
 
GTAElement.ID=nil
 
function GTAElement:className() return "GTAElement" end
 
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)
 
function GTAElement:setData(key,value)
 
setElementData(self.ID,key,value)
 
setElementData(self.ID,key,value)
 
end
 
end
function GTAElement:getData(key)
+
 
return getElementData(self.ID,key)
+
---
end
+
-- Get current Position of the Element
 +
-- @return x, y, z
 
function GTAElement:Position()
 
function GTAElement:Position()
 
return getElementPosition(self.ID)
 
return getElementPosition(self.ID)
 
end
 
end
  
 +
 +
 +
---
 +
-- The GTAPlayer
 +
-- @name GTAPlayer
 
GTAPlayer=inheritsFrom(GTAElement)
 
GTAPlayer=inheritsFrom(GTAElement)
 
function GTAPlayer:className() return "GTAPlayer" end
 
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)
 
function GTAPlayer:giveWeapon(w_id,ammo)
 
giveWeapon(self.ID,w_id,ammo)
 
giveWeapon(self.ID,w_id,ammo)
 
end
 
end
 +
 +
---
 +
-- Get current ping of the player
 +
-- @return int value
 
function GTAPlayer:Ping()
 
function GTAPlayer:Ping()
 
return getPlayerPing(self.ID)
 
return getPlayerPing(self.ID)
 
end
 
end
 +
 +
---
 +
-- Get current name of the player
 +
-- @return string name
 
function GTAPlayer:Name()
 
function GTAPlayer:Name()
 
return getClientName(self.ID)
 
return getClientName(self.ID)
 
end
 
end
 +
 +
---
 +
-- Get current rotation of the player
 +
-- @return float value
 
function GTAPlayer:Rotation()
 
function GTAPlayer:Rotation()
 
return getPlayerRotation(self.ID)
 
return getPlayerRotation(self.ID)
 
end
 
end
 +
 +
---
 +
-- Get current amount of health points of player
 +
-- @return int Health of the player
 
function GTAPlayer:Health()
 
function GTAPlayer:Health()
 
return getPlayerHealth(self.ID)
 
return getPlayerHealth(self.ID)
 
end
 
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)
 
function GTAPlayer:setHealth(val)
 
return setPlayerHealth(self.ID,val)
 
return setPlayerHealth(self.ID,val)
 
end
 
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)
 
function GTAPlayer:die(attacker,weapon,bodypart)
 
return killPlayer(self.ID,attacker,weapon,bodypart)
 
return killPlayer(self.ID,attacker,weapon,bodypart)
 
end
 
end
 +
 +
---
 +
-- Check wether player is dead or not
 +
-- @return bool True if the player is dead
 
function GTAPlayer:isDead()
 
function GTAPlayer:isDead()
 
return isPlayerDead(self.ID)
 
return isPlayerDead(self.ID)
 
end
 
end
 +
 +
---
 +
-- Check wether player is alive or not
 +
-- @return bool True if the player is alive
 
function GTAPlayer:isAlive()
 
function GTAPlayer:isAlive()
 
return not isPlayerDead(self.ID)
 
return not isPlayerDead(self.ID)
 
end
 
end
 +
 +
---
 +
-- Check wether player is ducked or not
 +
-- @return bool True if the player is ducked
 
function GTAPlayer:isDucked()
 
function GTAPlayer:isDucked()
 
return isPlayerDucked(self.ID)
 
return isPlayerDucked(self.ID)

Latest revision as of 21:44, 1 June 2007

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)