Author Topic: Medikit / Player position  (Read 1255 times)

0 Members and 1 Guest are viewing this topic.

Offline kosik231

  • Major
  • *
  • Posts: 70
  • Where can I find Your soul?
Medikit / Player position
« on: June 21, 2010, 05:50:36 pm »
Hay!
I have HP system on my Zombie server and i want to make that when player is near medikit, medi disappear (killobject) and soldiers HP is refilled to full... i made that in AppOnIdle:
Code: [Select]
Dist := Distance(GetPlayerStat(ID,'X'),GetPlayerStat(ID,'Y'),GetObjectStat(s,'X'),GetObjectStat(s,'Y'));
if  (Getobjectstat(s,'style')=16) and (Dist <= 30) then begin
if SoldierHpLeft[ID] < soldier[ID].maxhealth then begin
SoldierHpLeft[ID] := soldier[ID].maxhealth;
KillObject(s);
end;
end;
but it doesnt work... hp isnt refilled and medikit doesnt disappear... can any1 help me? first tell me that its possible to do xD ask if you have any questions


//sry for my english ^^ //
For signatures, you are allowed only one image in your signature which may not be wider and taller than 300 and 125 pixels, and may not be over 20kB in file size. No BMPs are allowed.

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Medikit / Player position
« Reply #1 on: June 21, 2010, 08:58:36 pm »
That would require itteration between all 225 possible medkits and a distance() call for all that are. Very very inefficient. The way i handle this problem is i check to see the players actual health before every onplayerdamage() call, if it is equal to 150 (or 65 for realistic), i set my players in-script health to the in-script max. Works like a charm.


Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Medikit / Player position
« Reply #2 on: June 25, 2010, 02:33:24 am »
as hacktank was saying, you should make it more efficient:
cycle through players and check if HP is below max first
then cycle through objects and check if it is a healthbox
then check if distance is < 30

what is SoldierHpLeft[ID] and soldier[ID]?
where are your for-loops?
you can't directly edit variables - you have to call a function that can change it like this:  SetPlayerStat(ID, 'Health', Value)
Can't think of anything original to put here...

Offline kosik231

  • Major
  • *
  • Posts: 70
  • Where can I find Your soul?
Re: Medikit / Player position
« Reply #3 on: June 25, 2010, 03:26:06 am »
soldier.[id] is a table with all statisctics for each account registered in my server, my server is based on RPG mode. soldierhpleft[id] is soldier's current hp after taken damage because hp on my server is unlimited (18 - 30 more hp per lvl) for example my character have 1000 HP, its called soldier[id].maxhealth := 1000; and its saved in my account file, when some1 shoot me i got for example 800HP, that is soldierhpleft[id], i want to make that when i stand on medikit it returning my hpleft to max hp... but i dont know how to check player / medikit position and how to kill object... so i need help :) if you want you can see all that features in my server "Zombieland"
For signatures, you are allowed only one image in your signature which may not be wider and taller than 300 and 125 pixels, and may not be over 20kB in file size. No BMPs are allowed.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Medikit / Player position
« Reply #4 on: June 25, 2010, 10:26:46 am »
Another method without the need to iterate through all the objects is to have the player's real health (not scripted health) slightly abnormal (1 less than maximum for example) if his health is not full (so that he cannot pick up a medikit if his health is full). AppOnIdle, you can check if a player's health is not full, and if his real health is full, and if so, set his health to full. ("health" refers to the scripted health, while "real health" refers to Soldat's implementation of player health)

In my opinion, this would probably behave smoother.

Offline kosik231

  • Major
  • *
  • Posts: 70
  • Where can I find Your soul?
Re: Medikit / Player position
« Reply #5 on: June 25, 2010, 11:18:48 am »
hmm, i have a idea :D ill make that when players HP is lower than max hp ill do damage to his real HP, something like 1 point damage, but how to make scripts hp refill with normal hp refill in same time?
For signatures, you are allowed only one image in your signature which may not be wider and taller than 300 and 125 pixels, and may not be over 20kB in file size. No BMPs are allowed.

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: Medikit / Player position
« Reply #6 on: June 25, 2010, 12:12:07 pm »
It won't probably work at the same time, but you'll have to go with it than any other scripter here, too.
-> AppOnIdle() is your friend when it's relating to timed things

Offline kosik231

  • Major
  • *
  • Posts: 70
  • Where can I find Your soul?
Re: Medikit / Player position
« Reply #7 on: June 25, 2010, 12:35:47 pm »
btw this from first post is good? i have it in my apponidle... and i have to make loop for it?
For signatures, you are allowed only one image in your signature which may not be wider and taller than 300 and 125 pixels, and may not be over 20kB in file size. No BMPs are allowed.

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: Medikit / Player position
« Reply #8 on: June 26, 2010, 02:42:32 am »
just do what curt said, it'll be the least resource-consuming solution

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Medikit / Player position
« Reply #9 on: June 26, 2010, 09:57:13 am »
By the way, I am Curt, if you didn't already know.

In addition to what I wrote before, it may also be a cool effect to set the player's real health based on his scripted health, so enemies can see whether or not players are hurt or not. (A ceiling function would probably be necessary to avoid death when it should not happen, but thats not the only option).