Jump to content

Recommended Posts

Posted

I'm a lost ball in tall weeds. Josh, would I just need to add a collision function to the powerup entity? such as 

slowedSpeed = {}
slowedSpeed.name = "slowedSpeed"

function slowedSpeed:Start()
	--set the trigger properties
	self:SetCollisionType(COLLISION_TRIGGER)
end

function slowedSpeed:Collide(entity)
	if entity:GetCollisionType() == COLLISION_PLAYER then
		myPlayer.speed = 140 end
end

I have the myPlayer.speed = 10 at the top of my player script. Obviously this isn't right because its not working. Am I going about this the wrong way?

Posted (edited)
39 minutes ago, Sweetgebus said:

I'm a lost ball in tall weeds. Josh, would I just need to add a collision function to the powerup entity? such as 

slowedSpeed = {}
slowedSpeed.name = "slowedSpeed"

function slowedSpeed:Start()
	--set the trigger properties
	self:SetCollisionType(COLLISION_TRIGGER)
end

function slowedSpeed:Collide(entity)
	if entity:GetCollisionType() == COLLISION_PLAYER then
		myPlayer.speed = 140 end
end

I have the myPlayer.speed = 10 at the top of my player script. Obviously this isn't right because its not working. Am I going about this the wrong way?

ignore that, I'm an idiot. This is was an issue within my player script, I did infact have a global variable, myPlayer.speed = 10. The issue was that I was never using it. The above code does infact work.

 

Edited by Sweetgebus
Posted

I have the script working the way I was expecting to. I just want to post what I have so others can view it. I welcome any feed back, it helps me learn. Maybe there is a better way? or maybe this way will lead to issues later? Your feed back will help with this, and help me by preventing bad habits. 

Here is my powerup script. 

slowedSpeed = {}
slowedSpeed.name = "slowedSpeed"

function slowedSpeed:Start()
	self.window = ActiveWindow()
	
	--set the trigger properties
	self:SetCollisionType(COLLISION_TRIGGER)
end
function slowedSpeed:Collide(entity)

	if entity:GetCollisionType() == COLLISION_PLAYER then
		inventory.slot1 = 1 end
	end

function onEffect()
	slowtimer = CreateTimer(5000)
	ListenEvent(EVENT_TIMERTICK,slowtimer,effectTimer)
	myPlayer.speed = 5
end

function effectTimer()
	slowtimer:Stop()
	myPlayer.speed = 10
	inventory.slot1 = inventory.slot1 - 1
end

It creates the effect, but stores it for later use, I created a inventory table within my player script that holds the value.

inventory = {}
iventory.slot1 = 0

Below is how I went about using the powerup in my player script. I first check to make sure if I have a power up available. If so, when the player presses the T key, the powerup script is executed for the set duration.

	-- player effects
	if self.window:KeyHit(KEY_T) and inventory.slot1 >= 1 then
		Print("Buff Active")
		onEffect()
		end
 

Ignore the Prints, they are just there for debugging purposes. If there is at least 1 power up stored in inventory.slot 1, the onEffect() function from the powerup script is called.

Posted (edited)
2 minutes ago, Sweetgebus said:

I have the script working the way I was expecting to. I just want to post what I have so others can view it. I welcome any feed back, it helps me learn. Maybe there is a better way? or maybe this way will lead to issues later? Your feed back will help with this, and help me by preventing bad habits. 

Here is my powerup script. 

slowedSpeed = {}
slowedSpeed.name = "slowedSpeed"

function slowedSpeed:Start()
	self.window = ActiveWindow()
	
	--set the trigger properties
	self:SetCollisionType(COLLISION_TRIGGER)
end
function slowedSpeed:Collide(entity)

	if entity:GetCollisionType() == COLLISION_PLAYER then
		inventory.slot1 = 1 end
	end

function onEffect()
	slowtimer = CreateTimer(5000)
	ListenEvent(EVENT_TIMERTICK,slowtimer,effectTimer)
	myPlayer.speed = 5
end

function effectTimer()
	slowtimer:Stop()
	myPlayer.speed = 10
	inventory.slot1 = inventory.slot1 - 1
end

It creates the effect, but stores it for later use, I created a inventory table within my player script that holds the value.

inventory = {}
iventory.slot1 = 0

Below is how I went about using the powerup in my player script. I first check to make sure if I have a power up available. If so, when the player presses the T key, the powerup script is executed for the set duration.

	-- player effects
	if self.window:KeyHit(KEY_T) and inventory.slot1 >= 1 then
		Print("Buff Active")
		onEffect()
		end
 

Ignore the Prints, they are just there for debugging purposes. If there is at least 1 power up stored in inventory.slot 1, the onEffect() function from the powerup script is called.

 

P.S, I'm aware that I do not need self.window = ActiveWindow() in the powerup script. Just pretend it isn't there.

Edited by Sweetgebus

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...